internal override void OnApplicationQuit() { UnregisterEvent(); base.OnApplicationQuit(); // reset this score before save PlayerData.Instance.Player.ResetScore(); SaveLoadSystem.Save(); }
private void LoadData() { Log.Info(GameConst.SAVE_PATH); PlayerData.Instance = new PlayerData(); SaveLoadSystem.Load(); this.PostEvent(EventID.OnLoadDataCompleted); }
/// <summary> /// Request for authentication /// </summary> /// <param name="name"></param> public void GSAuthenticate(string name) { Debug.Log("GSAuthenticate()"); string userName = ""; string password = ""; userName = name; // make an authentication request AuthenticationRequest authReq = new AuthenticationRequest(); authReq.SetPassword(password) .SetUserName(userName) .Send((response) => { // if there is no errors if (!response.HasErrors) { Debug.LogWarning("Authen succeed"); string authToken = response.AuthToken; var errorBase = JsonUtility.FromJson <ErrorMsgBase>(response.ScriptData.JSON); if (errorBase.errorMsg.errorCode == (int)EErrorCode.Ok) { UIManager.Instance.ShowNotification($"Welcome, {name}"); this.PostEvent(EventID.OnAuthSucceed); PlayerData.Instance.Player.Name = name; SaveLoadSystem.Save(); IsAuthenticated = true; } } // if it has error else { Debug.LogWarningFormat("Authen failed: {0}", response.Errors.JSON); var errorBase = JsonUtility.FromJson <ErrorMsgBase>(response.Errors.JSON); if (errorBase != null) { Log.Info($"CustomError msg: {errorBase.Dump()}"); if (errorBase.errorMsg.errorCode == (int)EErrorCode.UserNameNotFound) { // show notification to user UIManager.Instance.ShowNotification("Your username not found!"); } } } }); }
/// <summary> /// Register with user name /// </summary> /// <param name="name"></param> public void GSRegisterUser(string name) { Debug.Log("GSRegisterUser()"); string displayName = name; string userName = name; string pass = ""; Debug.Log("UserName: "******"Pass: "******"Error in GSRegisterUser()"); Debug.Log("All response: " + response.JSONString); Debug.Log("Error: " + response.Errors.JSON); var errorBase = JsonUtility.FromJson <ErrorMsgBase>(response.Errors.JSON); if (errorBase != null && errorBase.errorMsg.errorCode == (int)EErrorCode.InvalidUserNameSupplied) { Debug.LogWarning($"CustomError msg: {errorBase.Dump()}"); UIManager.Instance.ShowNotification("Invalid UserName Supplied"); } else { UIManager.Instance.ShowNotification("User name already been taken"); } } else { Debug.Log("GSRegisterUser() succeed"); Debug.Log(response.JSONString); // notify that user succeed registeration this.PostEvent(EventID.OnRegisterSucceed); // then automate authenticate GSAuthenticate(name); SaveLoadSystem.Save(); } }); }