2. Plugins Are?
● Libraries of native code written in C, C++,
Objective-C….etc
● Allow your game code to call functions from
these libraries
3. Why do you need to develop a Plugin?
●
●
●
●
●
●
Unity3D can’t Do That
Reuse C/C++/Objective-C components
Difficult customize in Unity3D Assets Store
Cross-Device
Cross-Platform
Security Issues
4. Interface?
● Just like call Unmanaged DLL in .NET
● Sync
○ Call the functions and get return values
● Async
○ Use UnitySendMessage
● Name mangling Issue
○ Use extern "C" { }
○ or _ZN·9funtown·7ios·6init·E
5. Plugins for Different Device
● Compile time - iOS
#if UNITY_IOS
#else
#endif
● Compile time - Android
#if UNITY_ANDROID
#else
#endif
6. Plugins for Different Device
● Runtime - iOS
if (Application.platform == RuntimePlatform.OSXPlayer)
● Runtime - Android
if (Application.platform == RuntimePlatform.Android)
10. iOS Tips
● DO NOT call plugins Pre-Frame
● String passing should be encoded by UTF-8
● Wrappers your Message and let it easily
encodes and decodes cross language. Ex:
JSON,Query String
● Uses XCode Editor for building automation
12. Android Plugins
● C# Load Java Class
ftJava = new AndroidJavaClass("tw.com.funtown.unity.FT");
ftjava.CallStatic("Init", "");
● Java Class
public class FT
{
public static void init(String params) {
Log.d("FTUnitySDK", "init called with params: " + params);
}
}
13. Android Plugins
● Overwrite onActivityResult
public class FTUnityPlayerActivity extends UnityPlayerActivity
{
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
Log.d("FTUnityPlayerActivity", "onActivityResult: requestCode: " +
requestCode + ", resultCode:" + resultCode);
}
}
16. Android Tips
● DO NOT call plugins Pre-Frame
● Mono garbage collector by using(){..} or xx.
Dispose() in C#
● Put your *.jar *.so in
YOUR_PROJECT/Assets/Plugins
● Be careful of Android resource conflict
problem