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 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 }