public void ShowLeaderboard(ButtonEventArgs args) { #if UNITY_IOS #if GAMECENTER if (GameCenterBinding.isPlayerAuthenticated()) { GameCenterBinding.showLeaderboardWithTimeScope(GameCenterLeaderboardTimeScope.AllTime); } else { StartLeaderboard(); } #else Core.Utility.Popup.PopupMessages.Me.NativeFuncionNonAvailableMessage(); #endif #endif #if UNITY_ANDROID #if GPGSERVIES if (!PlayGameServices.isSignedIn()) { StartLeaderboard(false); } else { PlayGameServices.showLeaderboards(); } #else Core.Utility.Popup.PopupMessages.Me.NativeFuncionNonAvailableMessage(); #endif #endif }
public void StartLeaderboard(bool autoStart = false) { if (!Network.IsInternetConnection() && !autoStart) { Core.Utility.Popup.PopupMessages.Me.InternetConnectionMessgae(); return; } #if UNITY_IOS && GAMECENTER if (!GameCenterBinding.isPlayerAuthenticated()) { GameCenterBinding.authenticateLocalPlayer(); } #endif #if UNITY_ANDROID #if GPGSERVIES && !AMAZONSTORE GPGManager.authenticationFailedEvent += (string error) => { MyDebug.Log("Prime[31] Google Play service authenticate fail with error:\n" + error); }; GPGManager.authenticationSucceededEvent += (string data) => { MyDebug.Log("Prime[31] Google Play service authenticate compelete with data:\n" + data); }; if (!PlayGameServices.isSignedIn()) { #if MYDEBUG PlayGameServices.enableDebugLog(true); #endif PlayGameServices.authenticate(); } #endif #endif }
public static bool IsSingedIn() { #if UNITY_IOS return(GameCenterBinding.isPlayerAuthenticated()); #elif UNITY_ANDROID return(PlayGameServices.isSignedIn()); #endif return(false); }
public void Login() { #if UNITY_ANDROID if (!PlayGameServices.isSignedIn()) { ZedLogger.Log("trying to authenticate local player"); PlayGameServices.authenticate(); } #endif }
protected override void Setup(APIWrapperSettings settings) { #if UNITY_ANDROID if (!PlayGameServices.isSignedIn() && !PlayerDataManager.Instance.GameCenterLoginRequested) { ZedLogger.Log("trying to authenticate local player (silently)"); PlayGameServices.attemptSilentAuthentication(); } #endif }
public void StartGoogleCloudLogin() { Debug.Log("StartGoogleCloudLogin() called"); if (!PlayGameServices.isSignedIn() && !googleCloudTryingToLogin) { Debug.Log("StartGoogleCloudLogin() authenticate called"); PlayGameServices.authenticate(); googleCloudTryingToLogin = true; } }
public void DeleteUserFromCloud() { Debug.Log("[UserManagerCloud] DeleteUserFromCloud..."); #if UNITY_IPHONE || UNITY_EDITOR StartCoroutine(DeleteFromCloud()); #elif UNITY_ADNROID if (PlayGameServices.isSignedIn()) { PlayGameServices.deleteCloudDataForKey(0, false); } #endif }
public void PublishScore(int score) { #if UNITY_ANDROID if (PlayGameServices.isSignedIn()) { Debug.Log("Publish score. Signed In."); PlayGameServices.submitScore(_leaderboardId, score); } else { Debug.Log("Publish score not possible. Not Signed In."); } #else Debug.Log("Error. AndroidLeaderboard.Show call for not android platform."); #endif }
public void Show() { #if UNITY_ANDROID Debug.Log("Try to show leaderboard."); if (PlayGameServices.isSignedIn()) { Debug.Log("SignedIn. ShowLeaderboard."); PlayGameServices.showLeaderboard(_leaderboardId); } else { Debug.Log("Not SidngedIn. Authenticate."); PlayGameServices.authenticate(); } #else Debug.Log("Error. AndroidLeaderboard.Show call for not android platform."); #endif }
public void ShowAchievemetns(ButtonEventArgs args) { #if UNITY_IOS #if GAMECENTER #else Core.Utility.Popup.PopupMessages.Me.NativeFuncionNonAvailableMessage(); #endif #endif #if UNITY_ANDROID #if GPGSERVIES if (!PlayGameServices.isSignedIn()) { StartLeaderboard(); } else { PlayGameServices.showAchievements(); } #else Core.Utility.Popup.PopupMessages.Me.NativeFuncionNonAvailableMessage(); #endif #endif }
private IEnumerator DownloadFromCloudByCheckingConflicts(System.Action <UserCloudDownloadDelegateEventArgs> onResul = null) { #if UNITY_IPHONE || UNITY_EDITOR JCloudDocumentOperation operation; // Let's check file for conflict first operation = JCloudDocument.FileHasConflictVersions(FILE_NAME_CLOUD); while (operation.finished == false) { yield return(null); // Wait for 1 frame } // Look for error -- if any, handle & stop coroutine here -- ignore cloud unvailable as it simply means conflicts are not handled if (operation.error.HasValue && operation.error.Value != JCloudDocumentError.CloudUnavailable) { HandleDocumentError(operation.error.Value, onResul); yield break; } // Did looking for conflict trigger a result? if (((bool?)operation.result).HasValue && (bool)operation.result == true) { // We have conflicts -- sort them out operation = JCloudDocument.FileFetchAllVersions(FILE_NAME_CLOUD); while (operation.finished == false) { yield return(null); } // Look for error -- if any, handle & stop coroutine here if (operation.error.HasValue) { HandleDocumentError(operation.error.Value, onResul); yield break; } // Get conflict versions JCloudDocumentVersions versions = (JCloudDocumentVersions)operation.result; // We will now attempt to pick the "best" version (e.g. most progress) -- you could offer UI UserCloud temporalUser; int lastLevelTemporalUser = -1; byte[] bestVersionIdentifier = null; foreach (JCloudDocumentVersionMetadata metadata in versions.versionsMetadata) { // Read version bytes operation = JCloudDocument.FileReadVersionBytes(FILE_NAME_CLOUD, metadata.uniqueIdentifier); while (operation.finished == false) { yield return(null); } // Look for error -- if any, handle & stop coroutine here if (operation.error.HasValue) { HandleDocumentError(operation.error.Value, onResul); yield break; } // Pick best version temporalUser = UserCloud.Deserialize((byte[])operation.result); if (temporalUser == null) { continue; } if (temporalUser.LastFinishedLvl > lastLevelTemporalUser) { lastLevelTemporalUser = temporalUser.LastFinishedLvl; bestVersionIdentifier = metadata.uniqueIdentifier; } } // At that point we should have the best version if (bestVersionIdentifier != null) { // Pick it as current version operation = JCloudDocument.FilePickVersion(FILE_NAME_CLOUD, bestVersionIdentifier, versions.versionsHash); while (operation.finished == false) { yield return(null); } // Look for error -- if any, handle & stop coroutine here if (operation.error.HasValue) { HandleDocumentError(operation.error.Value, onResul); yield break; } } } // At that point conflicts have been cleared -- wait for file reading operation = JCloudDocument.FileReadAllBytes(FILE_NAME_CLOUD); while (operation.finished == false) { yield return(null); // Wait for 1 frame } // Look for error -- if any, handle & stop coroutine here if (operation.error.HasValue) { HandleDocumentError(operation.error.Value, onResul); yield break; } byte[] bytes = operation.result as byte[]; if (bytes != null) { //Save iCloud info in Memory. Then, merge information with local user data Debug.Log("- LoadUserFromCloud OK"); CurrentCloudUser = UserCloud.Deserialize(bytes); this.MergeUsers(onResul); } #endif #if UNITY_ANDROID && !disableGoogleCloud byte[] googleCloudDataBytes = null; if (CanUseGoogleCloud()) { while (!PlayGameServices.isSignedIn() && googleCloudTryingToLogin) { yield return(null); // Wait for n frames until googleCloudTryingToLogin was setted to FALSE } if (!PlayGameServices.isSignedIn() && !googleCloudTryingToLogin) { HandleDocumentError(JCloudDocumentError.CloudUnavailable, onResul); yield break; } Debug.Log("[UserManagerCloud] DownloadFromCloudByCheckingConflicts(): Downloading user data from cloud..."); PlayGameServices.loadCloudDataForKey(0, false); // Wait a maximum of 6 seconds to retrieve google cloud data float timeLeftToWait = 6f; float lastTime = Time.realtimeSinceStartup; while (googleCloudData == null && timeLeftToWait > 0f) { timeLeftToWait -= Time.realtimeSinceStartup - lastTime; lastTime = Time.realtimeSinceStartup; yield return(null); // Wait for n frames until googleCloudData was setted in loadCloudDataForKeyFailedEvent or loadCloudDataForKeySucceededEvent } if (googleCloudData == "ERROR" || googleCloudData == null) { Debug.Log("ANDROID CLOUD SERVICES RETURNED ERROR DOWNLOADING"); HandleDocumentError(JCloudDocumentError.DocumentNotFound, onResul); yield break; } Debug.Log("[UserManagerCloud] There is google cloud data : " + googleCloudData.Length); try { googleCloudDataBytes = System.Convert.FromBase64String(googleCloudData); Debug.Log("[UserManagerCloud] Cloud data size: " + googleCloudDataBytes.Length); } catch (Exception) { Debug.LogWarning("[UserManagerCloud] Failed to decode android cloud data: " + googleCloudData); } } CurrentCloudUser = UserCloud.Deserialize(googleCloudDataBytes); MergeUsers(onResul); //Free memory googleCloudData = null; #endif yield break; }
private IEnumerator SaveInCloud(System.Action <UserCloudUploadedDelegateEventArgs> onResultSave = null) { Debug.Log("Saving in the Cloud"); UserCloudUploadedDelegateEventArgs args = new UserCloudUploadedDelegateEventArgs(); bool isPossibleSaveInCloud = true; byte[] bytes = null; string errorReadingLocalData = string.Empty; try { bytes = System.IO.File.ReadAllBytes(UserCloud.GetPath(FILE_NAME_LOCAL)); Debug.Log("[UserManagerCloud] Loaded local file user data: " + UserCloud.GetPath(FILE_NAME_LOCAL)); } catch (Exception ex) { Debug.LogWarning("[SaveInCloud] Error reading local user data file..."); isPossibleSaveInCloud = false; errorReadingLocalData = ex.Message; } if (isPossibleSaveInCloud == false) { Debug.LogWarning("Exception reading local user before save it: " + errorReadingLocalData); args.Error = errorReadingLocalData; args.Message = "There was an error saving to iCloud"; args.Result = false; args.SaveIn = ResultSave.NotSaved; RaiseUserHasBeenUploaded(args, onResultSave); yield break; } #if UNITY_IPHONE || UNITY_EDITOR JCloudDocumentOperation op = JCloudDocument.FileWriteAllBytes(FILE_NAME_CLOUD, bytes); while (op.finished == false) { Debug.Log("[SaveInCloud] Writting user data to cloud: " + op.progress); yield return(null); } if (op.error.HasValue) { string res = ""; switch (op.error.Value) { 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 res = "An error ocurred while saving text file. please retry."; Debug.LogWarning("[SaveInCloud] " + res); break; case JCloudDocumentError.DocumentNotFound: res = "There is no file present on this device. Create a new text file."; Debug.LogWarning("[SaveInCloud] " + res); break; case JCloudDocumentError.DownloadTimeout: // Offer the user to retry res = "Could not download user cloud file. Please retry."; Debug.LogWarning("[SaveInCloud] " + res); break; default: // We should never get there break; } Debug.LogWarning("[SaveInCloud] " + op.error.Value); args.Error = res; args.Message = "There was an error saving to iCloud"; args.Result = false; args.ErrorType = op.error.Value; args.SaveIn = ResultSave.NotSaved; RaiseUserHasBeenUploaded(args, onResultSave); } else { // OK Debug.Log("[SaveInCloud] Saved user file in cloud " + bytes.Length + " bytes"); args.Error = string.Empty; args.Message = "Saved in iCloud"; args.Result = true; args.SaveIn = ResultSave.Cloud; Debug.Log("[SaveInCloud] - SaveUser. Level: " + CurrentUser.LastFinishedLvl); RaiseUserHasBeenUploaded(args, onResultSave); } yield break; // byte[] bytes = System.IO.File.ReadAllBytes(UserCloud.GetPath(FILE_NAME_LOCAL)); // JCloudDocument.FileWriteAllBytes(FILE_NAME_CLOUD, bytes); // //// UserCloudUploadedDelegateEventArgs args = new UserCloudUploadedDelegateEventArgs(); //// //// if (onResultSave != null) //// onResultSave(ResultSave.Cloud); // // Debug.Log("Save File in Cloud " + bytes.Length); // yield break; #elif UNITY_ANDROID && !disableGoogleCloud if (CanUseGoogleCloud()) { while (!PlayGameServices.isSignedIn() && googleCloudTryingToLogin) { yield return(null); } if (PlayGameServices.isSignedIn() && !googleCloudTryingToLogin) { string strUserData = null; try { strUserData = System.Convert.ToBase64String(bytes); Debug.Log("[UserManagerCloud] Saving to Google Cloud services: " + bytes.Length + " bytes"); } catch (Exception) { Debug.LogWarning("[UserManagerCloud] Failed to encode user raw bytes to string. Size: " + bytes.Length + " bytes"); } if (strUserData != null) { PlayGameServices.setStateData(strUserData, 0); } } } yield break; #endif }
void OnGUI() { GUI.skin.label.alignment = TextAnchor.MiddleCenter; beginColumn(); GUILayout.Label("Authentication and Settings"); if (GUILayout.Button("Set Toasts on Bottom")) { PlayGameServices.setAchievementToastSettings(GPGToastPlacement.Bottom, 50); } if (GUILayout.Button("Authenticate")) { PlayGameServices.authenticate(); } if (GUILayout.Button("Sign Out")) { PlayGameServices.signOut(); } if (GUILayout.Button("Is Signed In")) { // Please note that the isSignedIn method is a total hack that was added to work around a current bug where Google // does not properly notify an app that the user signed out Debug.Log("is signed in? " + PlayGameServices.isSignedIn()); } if (GUILayout.Button("Get Player Info")) { var playerInfo = PlayGameServices.getLocalPlayerInfo(); Debug.Log(playerInfo); // if we are on Android and have an avatar image available, lets download the profile pic if (Application.platform == RuntimePlatform.Android && playerInfo.avatarUrl != null) { PlayGameServices.loadProfileImageForUri(playerInfo.avatarUrl); } } GUILayout.Label("Achievements"); if (GUILayout.Button("Show Achievements")) { PlayGameServices.showAchievements(); } if (GUILayout.Button("Increment Achievement")) { PlayGameServices.incrementAchievement("CgkI_-mLmdQEEAIQAQ", 2); } if (GUILayout.Button("Unlock Achievment")) { PlayGameServices.unlockAchievement("CgkI_-mLmdQEEAIQAw"); } endColumn(true); // toggle to show two different sets of buttons if (toggleButtonState("Show Cloud Save Buttons")) { secondColumnButtions(); } else { cloudSaveButtons(); } toggleButton("Show Cloud Save Buttons", "Toggle Buttons"); endColumn(false); }