Permalink
Browse files

Unity c# 多做一层初始化操作

  • Loading branch information...
U-UZ\litl U-UZ\litl
U-UZ\litl authored and U-UZ\litl committed Jun 15, 2017
1 parent 2a7529f commit 59c77271abcc65fc466dace9b9d371d6d74c873d
Showing with 14 additions and 1 deletion.
  1. +1 −1 README.md
  2. +13 −0 Unity3D-MobLink/Assets/Plugins/MobLink/Android/AndroidMobLinkImpl.cs
View
@@ -31,7 +31,7 @@
#### Android配置及注意事项(iOS开发者可忽略)
请参考原生文档[http://wiki.mob.com/sdk-moblink-android-2-0-0/](http://wiki.mob.com/sdk-moblink-android-2-0-0/)) 进行配置
在这里只需要配置AndroidManifest部分, 请参考原生文档[http://wiki.mob.com/sdk-moblink-android-2-0-0/](http://wiki.mob.com/sdk-moblink-android-2-0-0/)) 中的"配置AndroidManiFest.xml文件"进行配置
## 调用接口及获取回调
@@ -13,8 +13,11 @@ public class AndroidMobLinkImpl : MobLinkImpl {
public const string MOB_GETMOBID_CALLBACK_FAIL_METHOD = "_MobIdCallback";
public const string MOB_RESTORE_CALLBACK_METHOD = "_RestoreCallBack";
private bool isInited = false;
public override void setRestoreSceneListener ()
{
initMobSdk ();
AndroidJavaClass javaMoblink = getAndroidMoblink();;
AndroidJavaObject l = new AndroidJavaObject ("com.mob.moblink.unity.RestoreSceneListener", MOB_GAMEOBJECT_NAME, MOB_RESTORE_CALLBACK_METHOD);
javaMoblink.CallStatic ("setRestoreSceneListener", l);
@@ -26,6 +29,7 @@ public override void setRestoreSceneListener ()
}
private void GetMobId (string path, string source, Hashtable param) {
initMobSdk ();
object map = hashtable2JavaMap(param);
object l = new AndroidJavaObject ("com.mob.moblink.unity.ActionListener", MOB_GAMEOBJECT_NAME, MOB_GETMOBID_CALLBACK_SUCCESS_METHOD, MOB_GETMOBID_CALLBACK_FAIL_METHOD);
@@ -41,6 +45,15 @@ public override void setRestoreSceneListener ()
javaMoblink.CallStatic ("updateIntent", activity, intent);
}
private void initMobSdk() {
if (!isInited) {
AndroidJavaObject jo = getAndroidContext ();
AndroidJavaClass jc = new AndroidJavaClass ("com.mob.MobSDK");
jc.CallStatic ("init", jo);
}
isInited = true;
}
private static AndroidJavaClass getAndroidMoblink()
{
return new AndroidJavaClass ("com.mob.moblink.MobLink");

0 comments on commit 59c7727

Please sign in to comment.