private void cloudSaveButtons() { GUILayout.Label("Cloud Data"); if (GUILayout.Button("Load Cloud Data")) { PlayGameServices.loadCloudDataForKey(0); } if (GUILayout.Button("Set Cloud Data")) { PlayGameServices.setStateData("I'm some data. I could be JSON or XML.", 0); } if (GUILayout.Button("Update Cloud Data")) { PlayGameServices.updateCloudDataForKey(0); } if (GUILayout.Button("Get Cloud Data")) { var data = PlayGameServices.stateDataForKey(0); Debug.Log(data); } if (GUILayout.Button("Delete Cloud Data")) { PlayGameServices.deleteCloudDataForKey(0); } if (GUILayout.Button("Clear Cloud Data")) { PlayGameServices.clearCloudDataForKey(0); } if (GUILayout.Button("Show Share Dialog")) { PlayGameServices.showShareDialog("I LOVE this game!", "http://prime31.com"); } }
private void cloudSaveButtons() { GUILayout.Label("Cloud Data"); if (GUILayout.Button("Load Cloud Data")) { PlayGameServices.loadCloudDataForKey(0); } if (GUILayout.Button("Set Cloud Data")) { PlayGameServices.setStateData("I'm some data. I could be JSON or XML.", 0); } if (GUILayout.Button("Update Cloud Data")) { PlayGameServices.updateCloudDataForKey(0); } if (GUILayout.Button("Get Cloud Data")) { var data = PlayGameServices.stateDataForKey(0); Debug.Log(data); } if (GUILayout.Button("Delete Cloud Data")) { PlayGameServices.deleteCloudDataForKey(0); } if (GUILayout.Button("Clear Cloud Data")) { PlayGameServices.clearCloudDataForKey(0); } }
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; }