public void Awake() { // instance is also set in initialize. // this ensures that it doesn't break if the component was added to the scene manually. instance = this; DontDestroyOnLoad(gameObject); // object name must match UnitySendMessage call in PermissionPlease.java if (name != PERMISSION_PLEASE_NAME) { name = PERMISSION_PLEASE_NAME; } }
private static void initialize() { // runs once when you call GrantPermission if (instance == null) { GameObject go = new GameObject(); // instance will also be set in awake, but having it here as well seems extra safe instance = go.AddComponent <PermissionPlease>(); // object name must match UnitySendMessage call in PermissionPlease.java go.name = PERMISSION_PLEASE_NAME; } // get the jni stuff. we need the activty class and the PermissionPlease class. PermissionPleaseClass = new AndroidJavaClass("net.jimmar.unityplugins.PermissionPlease"); AndroidJavaClass u3d = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); activity = u3d.GetStatic <AndroidJavaObject>("currentActivity"); initialized = true; }