public void OnEndDrag(PointerEventData eventData) { if (ErrorHandler.Error.activeSelf || ErrorHandler.Excellent.activeSelf) { return; } if (origParent != parentToReturn) { clone.transform.SetParent(parentToReturn); Destroy(clone.GetComponent <Dragable>()); } else { Destroy(clone.gameObject); } clone.GetComponent <CanvasGroup>().blocksRaycasts = true; clone.GetComponent <LayoutElement>().ignoreLayout = false; LevelStructure level = new LevelStructure(); if (origParent != parentToReturn && ApplicationModel.orderedAnimalsCount == level.AnimalsToOrderCount) { if (!CheckAnimalOrder()) { ErrorHandler.Error.SetActive(true); } else { ApplicationModel.CurrentLevel++; ApplicationModel.CurrentBoneNumber++; if (FirebaseAuthHelper.Auth.CurrentUser != null) { ApplicationModel.SaveLocalUserData(FirebaseAuthHelper.Auth.CurrentUser.UserId); FirebaseDatabaseHandler.SaveCloudUserData(FirebaseAuthHelper.Auth.CurrentUser.UserId); } else { ApplicationModel.SaveLocalUserData("notRegisteredUser"); } ErrorHandler.Excellent.SetActive(true); } ApplicationModel.orderedAnimalsCount = 0; } }
public static void SaveCloudUserData(string userId) { if (Application.internetReachability != NetworkReachability.NotReachable) { UserDataJson newCloudUserData = new UserDataJson(); newCloudUserData.InitFromApplicationModel(); FirebaseDatabaseHandler.WriteUser(newCloudUserData, userId).ContinueWith(task => { if (task.Result) { Debug.Log(String.Format("Write UserId: {0} to cloud succeed.", userId)); } else { Debug.LogError(String.Format("Write UserId: {0} to cloud failed.", userId)); } }); } }
private static void Auth_StateChanged(object sender, EventArgs e) { FirebaseAuth senderAuth = sender as FirebaseAuth; FirebaseUser user = null; if (senderAuth != null) { FirebaseAuthHelper.userByAuth.TryGetValue(senderAuth.App.Name, out user); } if (senderAuth == FirebaseAuthHelper.Auth && senderAuth.CurrentUser != user) { bool signedIn = user != senderAuth.CurrentUser && senderAuth.CurrentUser != null; if (!signedIn && user != null) { Debug.Log("Signed out " + user.UserId); ApplicationModel.CurrentLevel = 1; ApplicationModel.CurrentBoneNumber = 0; } user = senderAuth.CurrentUser; FirebaseAuthHelper.userByAuth[senderAuth.App.Name] = user; if (signedIn) { LoggedIn(); Debug.Log("Signed in " + user.UserId); FirebaseDatabaseHandler.GetUserByUserId(user.UserId).ContinueWith(task => { var localUserData = ApplicationModel.LoadLocalUserData(Auth.CurrentUser.UserId); FirebaseDatabaseHandler.SyncUserData(localUserData, task.Result); }); } } }
public static void SyncUserData(UserDataBinary localUserData, UserDataJson cloudUserData) { if (localUserData == null && cloudUserData == null) { ApplicationModel.CurrentLevel = 1; ApplicationModel.CurrentBoneNumber = 0; Debug.Log("No user data found."); return; } else if (localUserData == null || (localUserData != null && cloudUserData != null && localUserData.ModifiedDatetimeBinary <= cloudUserData.ModifiedDatetimeBinary)) { ApplicationModel.CurrentLevel = cloudUserData.Level; ApplicationModel.CurrentBoneNumber = cloudUserData.BoneNumber; ApplicationModel.SaveLocalUserData(FirebaseAuthHelper.Auth.CurrentUser.UserId); Debug.Log(String.Format("User data loaded from the cloud: {0}", FirebaseAuthHelper.Auth.CurrentUser.UserId)); } else if (cloudUserData == null || (localUserData != null && cloudUserData != null && localUserData.ModifiedDatetimeBinary >= cloudUserData.ModifiedDatetimeBinary)) { ApplicationModel.CurrentLevel = localUserData.Level; ApplicationModel.CurrentBoneNumber = localUserData.BoneNumber; Debug.Log(String.Format("User data loaded from the local file: {0}", localUserData.UserID)); UserDataJson newCloudUserData = new UserDataJson(); newCloudUserData.InitFromApplicationModel(); FirebaseDatabaseHandler.WriteUser(newCloudUserData, FirebaseAuthHelper.Auth.CurrentUser.UserId).ContinueWith(task => { if (task.Result) { Debug.Log(String.Format("Write UserId: {0} to cloud succeed.", FirebaseAuthHelper.Auth.CurrentUser.UserId)); } else { Debug.LogError(String.Format("Write UserId: {0} to cloud failed.", FirebaseAuthHelper.Auth.CurrentUser.UserId)); } }); } }