Building APK file in Unity (version 1.4.3 or later)
The goal of this chapter is to build an apk file in Unity IDE.
- Import Mobage Unity SDK assets to your Unity IDE.
There is no need to build and import Unity Plugin in Eclipse anymore from Mobage Unity SDK 1.4.3.
- Implement your Unity program.
you are expected to have completed the download, installation and license registration of Unity.
First, launch Unity and create a new Unity Project. While opening the newly created
project, choose "Assets">"Import Package">"Custom Package..."
In the dialog that appears, specify a path to MobageUnitySDK.unitypackage.
Check all the options, and press the "Import" button at the right bottom to complete the import.
|Please be aware that you will fail to import if you have "MobageUnitySDK.unitypackage" on a multi bite pass in Windows environment.|
After importing the package, you can see the imported files in Project View.
Open a template asset to double click Plugins/HelloMobage.unity (Unity icon file) in the Project view. Then you can see the MobageCallback object in Hierarchy View.
(The following image shows the outline of the Project View with Wide layout.)
|There is no need to configure MobageCallback object on Mobage Unity SDK 1.4.2 or later, since it will configure automatically.|
Following procedure is only needed if you want to configure manually.
Configure the MobageCallback object by following the process below.
- Drag GUIs/MobageGUI and drop into "Missing(GUISkin)" that is at the right of "Custom Skin" in the top "Mono Behaviour" in the Inspector View.
- Drag Plugins/HelloMobage.cs (C# icon) into "Missing (Mono Script)" at the right of "Scripts", that is in the top "Mono Behavior".
- Drag Plugins/MobageCallback.cs (C# icon) into "Missing (Mono Script)" at the right of "Scripts" that is in the second "Mono Behaviour".
- Configure the BalanceButton.
- Drop Plugins/BalancButton.cs into "Missing(Mono Script)" in "MonoBehavior".
- Drop GUIs/BalanceButton to "Missing (GUISkin)" at the right of "Custom Skin" in "MonoBehavior", where you have already set the above BalanceButton.cs.
- Build an apk file.
If you click on the other elements before drag&drop, the Inspector View will be switched to another one. Before selecting MobageCallback in the Hierarchy View, open GUIs and Plugins in the Project View.
The sample settings to show a button are now complete. When you press the replay icon at the top of the Unity IDE, the game preview screen is shown as below.
|In Mobage Unity SDK preview version, you cannot call Mobage Social API in Unity IDE. Please check the API behavior in Android device.|
You have an option to test the API behavior from Mobage Unity SDK 1.2, which will provide simulated responses without any communication.
To perform login process, you are required to set a login listener that receives events from Mobage Unity SDK.
To receive the login events, set a login listener by the following code. (Note that this code has already been implemented in HelloMobage.cs.)
The following is a sample code to call MobagePeople.getCurrentUser().
|HelloMobage.cs has already implemented a method getCurrentUser().|
Now we will modify the Plugins/Android/AndroidManifest.xml in Project View.
The file hierarchy will look like the below image.
Your AndroidManifest.xml will look as below.
|The screenOrientation of MobageDashboardActivity can be set to landscape from Mobage Native SDK 1.4.5 .|
Please replace the following items with your settings.
- If you're planning to use F.O.X for Mobage, just follow the standard import procedure of the SDK.
- If you're planning to remove F.O.X for Mobage or implement F.O.X by yourself, remove "/Assets/Plugins/Android/AppAdForce.jar" from Unity Project.
|You are able to call MobagePlatform.Initialize() in your C# code (same as iOS) from Mobage Unity SDK 1.4.2|
When you start your application (like inside Awake() method), you will need to implement the following initialization.
The arguments of the method are: region type, environment type, consumerKey, consumerSecret and application ID.
|Notice that this is already implemented inside your HelloMobage.cs, so you only need to enter your consumerKey, consumerSecret and application ID. |
You will need to register your application through Mobage Developers site to obtain your consumerKey, consumerSecret and application ID
When selecting "File"->"Build Settings" in the Unity IDE (the lower left image), the Build Settings Window will open (the below image).
Select "Android" in "Platform" that is at the bottom-left of the Build Settings Window (the below image). Push "Switch Platform" to configure Android platform settings.
When pushing "Player Settings...", UnityPlayer configuration pane will be shown in Unity IDE. Configure the following required settings.
When pressing the "Play Settings..." button, the setting items are shown in the Inspector view in the IDE window.Change "Other Settings" ->"Identification"->"Bundle Identifier" from the default value to jp.mbga.a1200XXXX (which 1200XXXX is your appID).
|If you do not change the Bundle identifier, you will not be able to build.|
|Please keep "Player Settings" -> "Stripping Level" as "Disabled" which is default settings. Changing this value can cause instability to the Unity SDK.|
When pressing the "Build" button at the bottom-right of the screen, a building process will start.
A dialog to set a path to Android SDK will be shown.
And then, a dialog to specify an apk file name will be shown (the below image).
Specify the apk file name and push the "Save" button. The apk file will be saved.
This apk file is the final output of the building process.
If you want to run your application, push "Build and Run" button at the bottom-right of "Build Settings" window.
You will need to comment out the initialization method using "#if UNITY_IPHONE #endif" so it will only be called on iOS.
Edit addPlatformListener inside Plugins/MobageManager.cs as below.
Comment out "Mobage.addLoginListener()" using "#if UNITY_IPHONE #endif" so it will only be called on iOS.
You can now proceed the same steps on building and importing your Unity plugin (See Building Unity Plugin in Eclipse).
- Initial Release. Description on using Mobage Unity SDK after 1.4.2.