private void RaiseUserHasBeenDownloaded(UserCloudDownloadDelegateEventArgs e, System.Action <UserCloudDownloadDelegateEventArgs> onResult) { if (onResult != null) { onResult(e); } if (UserHasBeenDownloadedFromCloud != null) { UserHasBeenDownloadedFromCloud(this, e); } }
// Single method for error handling private void HandleDocumentError(JCloudDocumentError documentError, System.Action <UserCloudDownloadDelegateEventArgs> onResul) { string error = ""; switch (documentError) { case JCloudDocumentError.InvalidPlatform: // Web player -- no file access. Do not use JCloudDocument. error = "No file access allowed on this platform."; break; case JCloudDocumentError.PluginError: case JCloudDocumentError.NativeError: case JCloudDocumentError.InvalidArguments: // Look out for this one as it means you passed invalid path // Offer the user to retry error = "An error ocurred while loading game data. Please retry."; break; case JCloudDocumentError.DocumentNotFound: error = "There is no saved game present on this device. Start a new game."; break; case JCloudDocumentError.DownloadTimeout: // Offer the user to retry error = "Could not download the save game data. Please retry."; break; case JCloudDocumentError.InvalidVersionIdentifier: case JCloudDocumentError.InvalidVersionsHash: // Offer the user to retry error = "An error occured while handling conflict versions of your save game data. Please retry."; break; default: // We should never get there break; } UserCloudDownloadDelegateEventArgs args = new UserCloudDownloadDelegateEventArgs(); Debug.Log(error); args.Error = error; args.Message = "There was an error downloading from iCloud by checking conflicts"; args.Result = false; args.ErrorType = documentError; RaiseUserHasBeenDownloaded(args, onResul); }
/// <summary> /// Merges the users and save the info in Local File and Cloud File. Previously, User from Cloud must be initialized /// </summary> /// <param name='onResult'> /// On result. /// </param> /// <param name='args'> /// Arguments. /// </param> private void MergeUsers(System.Action <UserCloudDownloadDelegateEventArgs> onResult = null) { bool isDirty = false; Debug.Log("- MergeUser 1"); UserCloudDownloadDelegateEventArgs args = new UserCloudDownloadDelegateEventArgs(); if (CurrentCloudUser == null) { Debug.Log("- MergeUser 2"); args.Result = false; args.Message = "MergeUser: User from cloud must be initialized before the Merge"; args.Error = "User from Cloud was not initialized"; this.SaveUserInCloud(); RaiseUserHasBeenDownloaded(args, onResult); return; } //Updating Levels int levelsInCloudUser = CurrentCloudUser.LastFinishedLvl; int levelsInLocalUser = CurrentUser.LastFinishedLvl; Debug.Log("- MergeUser - UserLocal had Level: " + levelsInLocalUser); Debug.Log("- MergeUser - UserCloud had Level: " + levelsInCloudUser); if (levelsInCloudUser > levelsInLocalUser) { CurrentUser.LastFinishedLvl = levelsInCloudUser; isDirty = true; } for (int i = 1; i <= CurrentUser.LastFinishedLvl; i++) { int scoreForLocalUser; int scoreForCloudUser; int starsForLocalUser; int starsForCloudUser; this.GetScoreAndStarsForLevel(CurrentCloudUser, i, out scoreForCloudUser, out starsForCloudUser); this.GetScoreAndStarsForLevel(CurrentUser, i, out scoreForLocalUser, out starsForLocalUser); int winnerScore = scoreForCloudUser > scoreForLocalUser ? scoreForCloudUser : scoreForLocalUser; int winnerStars = starsForCloudUser > starsForLocalUser ? starsForCloudUser : starsForLocalUser; if (winnerScore != scoreForLocalUser || winnerStars != starsForLocalUser) { this.ContinueWithSetScoreForLevel(CurrentUser, i, winnerScore, winnerStars, null, false, i == CurrentUser.LastFinishedLvl); } if (scoreForCloudUser < scoreForLocalUser || starsForCloudUser < starsForLocalUser) { isDirty = true; } } Debug.Log("- MergeUser 4"); //Updating Coins if (CurrentCloudUser.UserGoldCoins > CurrentUser.UserGoldCoins) { CurrentUser.UserGoldCoins = CurrentCloudUser.UserGoldCoins; } else if (CurrentCloudUser.UserGoldCoins < CurrentUser.UserGoldCoins) { isDirty = true; } if (CurrentCloudUser.UserSilverCoins > CurrentUser.UserSilverCoins) { CurrentUser.UserSilverCoins = CurrentCloudUser.UserSilverCoins; } else if (CurrentCloudUser.UserSilverCoins < CurrentUser.UserSilverCoins) { isDirty = true; } //Updating Lives // if (CurrentCloudUser.NumsLiveLeft > CurrentUser.NumsLiveLeft) // { // isDirty = true; // CurrentUser.NumsLiveLeft = CurrentCloudUser.NumsLiveLeft; // } //Once finished Merging, both instance must be the same CurrentCloudUser = CurrentUser; //Raise the event args.Error = string.Empty; args.Message = "MergeUser: User has been downloaded"; args.Result = true; RaiseUserHasBeenDownloaded(args, onResult); if (onResult != null) { onResult(args); } // IsUserInit = true; Debug.Log(" - MergeUser. Level: " + CurrentUser.LastFinishedLvl); bool isPossibleToSaveInCloud = this.SaveDataToDisk(); if (isDirty && isPossibleToSaveInCloud) { this.SaveUserInCloud(); } }
// void FacebookStatusChanged(object sender, UserLoginEventDelegateEventArgs e) // { // UpdateAvatar(); // } void DownloadedFromCloud(object sender, UserCloudDownloadDelegateEventArgs e) { CompanionsManager.Instance.RefreshLevelButtons(); UpdateAvatar(); }