Unity Introduction

Knowing how to integrate Unity SDK by reading this document. It's important for you to read through and understand the document before starting development.

Development Environment

1.下載 SGSDK Unity Package File


2.Import Custom Package

Import SGSDK.unitypackage to project.


SGSDK Package Content

1.Android

  • Plugins/Android/SGSDK.aar is native android sdk
  • Plugins/Android/android-support-v4.jar is dependency sdk of android. Keeping the newest one avoid making apk error.
  • Plugins/Android/AndroidManifest.xml is AndroidManifest.xml of sdk. Have to merge with project.
  •  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
    	<application>
    
    		<!-- SGSDK setting -->
    		<!-- Launch SGUnityContext override from com.unity3d.player.UnityPlayerActivity -->
    		<activity android:name="com.sgstudios.sdk.SGUnityActivity" android:launchMode="singleTask">
    			<intent-filter>
    				<action android:name="android.intent.action.MAIN" />
    				<category android:name="android.intent.category.LAUNCHER" />
    			</intent-filter>
    			<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
    		</activity>
    
    		<!-- Enter channel key from https://apidocs.smartgamesltd.com/channel -->
    		<meta-data android:name="SDKChannel" android:value="lemian" />
    		<!-- Google payment PublicKey -->
    		<meta-data android:name="Base64PublicKey" android:value="MyPublicKey" />
    		<uses-sdk android:minSdkVersion="19" />
    
    	</application>
    </manifest>
    

2.iOS

  • Plugins/iOS/SGSDK.framework native iOS sdk
  • Plugins/iOS/SwiftObject.mm SwiftObject.swift is intermediary file of iOS and Unity.
  • Below are files of build iOS project necessary.
  • Plugins/SGSDK/Editor/PostProcessor.cs
  • Plugins/SGSDK/UnitySwift-Bridging-Header.h
  • Plugins/SGSDK/Xcode/

3.Unity SDK

  • Plugins/SGSDK/Scripts Unity SGSDK

Using Unity SGSDK

1.Using SGSDK

  • Using singleton object SGSDK.Instance function to integrate SG member, payment and analytic system.
  • Recommended call SDK SetListener and Init at game initialization.
  •  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    private const string mGameKey = "MyGameKey";
    private const string mAppSecret = "MyAppSecret";
    
    void Start () {
    	SGSDK.Instance.SetListener (onSDKCallback);
    	SGSDK.Instance.Init (mGameKey, mAppSecret);
    }
    
    private void onSDKCallback(int code, string msg, string rawData) {
    	mMessage += code.ToString() + "\n";
    
    	if (!string.IsNullOrEmpty(msg))
    		mMessage += msg + "\n";
    
    	if (!string.IsNullOrEmpty(rawData))
    		mMessage += rawData + "\n";
    
    	//code define https://apidocs.smartgamesltd.com/webapi-init#section5
    	switch (code) {
    	case 201: // login success
    		//enter game play
    
    		break;
    	}
    }
    

2.SGSDK Customize Setting

  • SGSDK.Instance.ChangeLanguage(string lang); //Only support "zh-tw", "zh-hk", "zh-cn", "en"
  • SGSDK.Instance.AutoShowWidget(bool flag); //Default is true, setting to false widget is no longer show after login. User can customize your own UI for account UI.
  • SGSDK.Instance.IsChinaVersion = true; //Default is false, setting to true SDK will hide all Facebook feature. Country code of phone number is only show +86

3.Hints

  • SGSDK only can test in device.

4.SGSDK sample

  • Please refer to SGSDKSample/SGDemo

Install Facebook iOS SDK

1.Download Facebook iOS SDK


2.Unzip

Unzip the archive to ~/Documents/FacebookSDK