Unity 3 DはNative Pluginsを使用しています.
9933 ワード
本論文のソースリンク:http://blog.csdn.net/qq393830887/article/details/53162179
バージョン情報
注意
参考文献
https://docs.unity3d.com/Manual/PluginInspector.html http://docs.testin.cn/docs/sdk
コード部分
C钻中間層
using UnityEngine;
public class BugoutBridge
{
public static void Init(string appKey, string channelId, string userInfo, bool debugModel, bool errorActivity,
bool collectNDKCrash, bool openCrash, bool openEx, bool reportOnlyWifi, bool reportOnBack, bool qAMaster,
bool closeOption, bool logcat)
{
switch (Application.platform)
{
case RuntimePlatform.Android:
{
AndroidBugoutBridge.Init(appKey, channelId, userInfo, debugModel, errorActivity, collectNDKCrash, openCrash, openEx, reportOnlyWifi, reportOnBack, qAMaster, closeOption, logcat);
return;
}
}
}
public static bool GetShakeStatus()
{
switch (Application.platform)
{
case RuntimePlatform.Android:
{
return AndroidBugoutBridge.GetShakeStatus();
}
}
return false;
}
}
C铉呼び出しJava中間層
using System;
using UnityEngine;
public class AndroidBugoutBridge
{
#if UNITY_EDITOR || UNITY_ANDROID
private const string UnityClassPath = "com.unity3d.player.UnityPlayer";
private const string JavaClasPath = "com.Android.BugoutBridge";
private static AndroidJavaClass _mainJavaClass;
private static AndroidJavaClass MainJavaClass
{
get { return _mainJavaClass; }
}
private static AndroidJavaObject UnityJavaObject
{
get { return GetStatic(GetJavaClass(UnityClassPath), "currentActivity"); }
}
private static AndroidJavaClass GetJavaClass(string javaClassPath)
{
try
{
return new AndroidJavaClass(javaClassPath);
}
catch (Exception e)
{
Debug.LogException(e);
}
return null;
}
private static void CallApi(AndroidJavaClass jc, string apiName, params object[] args)
{
if (jc == null)
{
return;
}
try
{
jc.CallStatic(apiName, args);
}
catch (Exception e)
{
Debug.LogException(e);
}
}
private static T CallApi(AndroidJavaClass jc, string apiName, params object[] args)
{
if (jc == null)
{
return default(T);
}
try
{
return jc.CallStatic(apiName, args);
}
catch (Exception e)
{
Debug.LogException(e);
}
return default(T);
}
private static T GetStatic(AndroidJavaClass jc, string javaInterface)
{
if (jc == null)
{
return default(T);
}
try
{
return jc.GetStatic(javaInterface);
}
catch (Exception e)
{
Debug.LogException(e);
}
return default(T);
}
#endif
public static void Init(string appKey, string channelId, string userInfo, bool debugModel, bool errorActivity,
bool collectNDKCrash, bool openCrash, bool openEx, bool reportOnlyWifi, bool reportOnBack, bool qAMaster,
bool closeOption, bool logcat)
{
#if UNITY_EDITOR || UNITY_ANDROID
_mainJavaClass = GetJavaClass(JavaClasPath);
CallApi(MainJavaClass, "Init", UnityJavaObject, appKey, channelId, userInfo, debugModel, errorActivity, collectNDKCrash, openCrash, openEx, reportOnlyWifi, reportOnBack, qAMaster, closeOption, logcat);
#endif
}
public static bool GetShakeStatus()
{
#if UNITY_EDITOR || UNITY_ANDROID
return CallApi<bool>(MainJavaClass, "GetShakeStatus", UnityJavaObject);
#endif
return false;
}
}