void Awake() { SwarmLoginManager.addLoginListener(delegate(int status) { if (status == SwarmLoginManager.USER_LOGGED_IN) { loggedIn = true; load(); checkPaidVersion(); } else if (status == SwarmLoginManager.LOGIN_STARTED) { // The player has started logging in } else if (status == SwarmLoginManager.LOGIN_CANCELED) { // The player has cancelled the login } else if (status == SwarmLoginManager.USER_LOGGED_OUT) { loggedIn = false; } }); Swarm.init(SwarmConsts.App.APP_ID, SwarmConsts.App.APP_AUTH); //Debug GUI guiStyle1.fontSize = 18; guiStyle1.normal.textColor = Color.white; }
/** * Adds a login listener to report the status of a login. * * @param action The action to be performed (delegate to be called) when the callback is complete (the user data is returned). * * SwarmLoginListener enables the developer to listen for various events during the login process. * loginCancelled is called if the user intentionally cancels the login. * loginStarted is called when the login process has started (when a login dialog is displayed to the user). * userLoggedIn is called when the user has successfully logged in. * userLoggedOut is called when the user logs out for any reason. */ public static void addLoginListener(System.Action <int> action) { #if UNITY_ANDROID #if !UNITY_EDITOR string objName = "SwarmLoginManagerAddListener." + DateTime.Now.Ticks; GameObject gameObj = new GameObject(objName); DontDestroyOnLoad(gameObj); SwarmLoginManager component = gameObj.AddComponent <SwarmLoginManager>(); component.callbackAction = action; AndroidJavaObject callback = new AndroidJavaObject("java.lang.String", objName); jvalue[] args = new jvalue[1]; args[0].l = callback.GetRawObject(); AndroidJNI.CallStaticVoidMethod(swarmUnityInterface, addLoginListenerMethod, args); #endif #endif }