/// <summary> /// Creates the new save. Save returned in callback is closed!. Open it before use. /// </summary> /// <param name="save">Save.</param> /// <param name="saveCreatedCallback">Invoked when save has been created.</param> private static void CreateNewSave(ISavedGameMetadata save, Action<ISavedGameMetadata> saveCreatedCallback) { ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder (); builder = builder .WithUpdatedPlayedTime(save.TotalTimePlayed.Add(new TimeSpan(0, 0, (int) Time.realtimeSinceStartup))) .WithUpdatedDescription("Saved at " + DateTime.Now); SavedGameMetadataUpdate updatedMetadata = builder.Build(); SaveDataBundle newBundle = new SaveDataBundle(new StoredPlayerData()); savedGameClient.CommitUpdate( save, updatedMetadata, SaveDataBundle.ToByteArray(newBundle), (SavedGameRequestStatus status,ISavedGameMetadata game) => { if (status == SavedGameRequestStatus.Success) { m_saveBundleMetadata = game; if (saveCreatedCallback != null) saveCreatedCallback(game); } Debug.Log("Creating new save finished with status :" + status.ToString()); } ); }
public void OnSavedGameWritten(SavedGameRequestStatus status, ISavedGameMetadata game) { if (status == SavedGameRequestStatus.Success) { // handle reading or writing of saved game. } else { // handle error } }
/* * Cloud loads the selected saved game. * */ public void OnSavedGameSelected(SelectUIStatus status, ISavedGameMetadata game) { if (status == SelectUIStatus.SavedGameSelected) { GameControl.control.DoLoadFromCloud(); } else { } }
//========= Google's specific functions public void OnSavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game) { if (status == SavedGameRequestStatus.Success) { MonoBehaviour.print("has opened saved game (cloud save)"); GameObject.FindGameObjectWithTag("GameManager").GetComponent<GameManager>().callback_OnSavedGameOpened(game); } else { MonoBehaviour.print("could not open saved game (cloud save)"); } }
public void OnSavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game) { if (status == SavedGameRequestStatus.Success) { if (saving){ //Falta generar el byte de los datos SaveGameData(game,new byte[]{}); } else{ LoadGameData(game); } // handle reading or writing of saved game. } else { // handle error } }
/* * Does the cloud save. * Converts PlayerData into a byte array. Updates play time and saved file description. Then commits. * */ public void CloudSave(SavedGameRequestStatus status, ISavedGameMetadata game) { Save(); byte[] data = ToBytes(this.playerData); //Calculate play time and total playtime. TimeSpan delta = DateTime.Now.Subtract(loadedTime); playingTime += delta; this.timePlayed = playingTime; ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder(); builder = builder.WithUpdatedPlayedTime(this.timePlayed).WithUpdatedDescription("Current Level: " + playerData.currentGameLevel + " Current Player Level: " + playerData.playerLevel); SavedGameMetadataUpdate updatedMetadata = builder.Build(); savedGameClient.CommitUpdate(game, updatedMetadata, data, OnSaveWritten); }
public void ReadBinaryData(ISavedGameMetadata metadata, Action <SavedGameRequestStatus, byte[]> completedCallback) { Misc.CheckNotNull(metadata); Misc.CheckNotNull(completedCallback); completedCallback = ToOnGameThread(completedCallback); NativeSnapshotMetadata convertedMetadata = metadata as NativeSnapshotMetadata; if (convertedMetadata == null) { Logger.e("Encountered metadata that was not generated by this ISavedGameClient"); completedCallback(SavedGameRequestStatus.BadInputError, null); return; } if (!convertedMetadata.IsOpen) { Logger.e("This method requires an open ISavedGameMetadata."); completedCallback(SavedGameRequestStatus.BadInputError, null); return; } mSnapshotManager.Read(convertedMetadata, response => { if (!response.RequestSucceeded()) { completedCallback(AsRequestStatus(response.ResponseStatus()), null); } else { completedCallback(SavedGameRequestStatus.Success, response.Data()); } } ); }
private static void OnSavedGameOpened( SavedGameRequestStatus status, ISavedGameMetadata metadata, bool saving, CloudData data, Action <CloudData> callback = null) { if (status == SavedGameRequestStatus.Success) { if (saving) { PlayGamesPlatform.Instance.SavedGame.CommitUpdate( metadata, new SavedGameMetadataUpdate.Builder().Build(), Encoding.ASCII.GetBytes(JsonUtility.ToJson(data)), OnSavedGameWritten ); } else { PlayGamesPlatform.Instance.SavedGame.ReadBinaryData( metadata, (readStatus, readData) => OnSavedGameRead(readStatus, readData, callback) ); } } }
public void SaveGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game) { if (status == SavedGameRequestStatus.Success) { if (isSaving) // Writting data { byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(GetSaveString()); TimeSpan playedTime = TimeSpan.FromSeconds(totalplayTime); SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder() .WithUpdatedPlayedTime(playedTime) .WithUpdatedDescription("Saved Game At " + DateTime.Now); SavedGameMetadataUpdate update = builder.Build(); ((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(game, update, data, SaveGameWritten); } else //Reading Data { ((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(game, SaveGameLoaded); } } else { PopupManager.ins.ShowPopUp("Save State", "Error opening game:" + status); } }
static void SaveGame(ISavedGameMetadata game, byte[] savedData, TimeSpan totalPlaytime) { #if UNITY_ANDROID && !UNITY_EDITOR ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder(); builder = builder .WithUpdatedPlayedTime(totalPlaytime) .WithUpdatedDescription("Saved game at " + DateTime.Now); /* * if (savedImage != null) * { * // This assumes that savedImage is an instance of Texture2D * // and that you have already called a function equivalent to * // getScreenshot() to set savedImage * // NOTE: see sample definition of getScreenshot() method below * * byte[] pngData = savedImage.EncodeToPNG(); * builder = builder.WithUpdatedPngCoverImage(pngData); * }*/ SavedGameMetadataUpdate updatedMetadata = builder.Build(); savedGameClient.CommitUpdate(game, updatedMetadata, savedData, OnSavedGameWritten); #endif }
public void ChooseMetadata(ISavedGameMetadata chosenMetadata) { NativeSnapshotMetadata metadata = chosenMetadata as NativeSnapshotMetadata; if (metadata != this.mOriginal && metadata != this.mUnmerged) { Logger.e("Caller attempted to choose a version of the metadata that was not part of the conflict"); this.mCompleteCallback(SavedGameRequestStatus.BadInputError, (ISavedGameMetadata)null); } else { this.mManager.Resolve(metadata, new NativeSnapshotMetadataChange.Builder().Build(), this.mConflictId, (Action <GooglePlayGames.Native.PInvoke.SnapshotManager.CommitResponse>)(response => { if (!response.RequestSucceeded()) { this.mCompleteCallback(NativeSavedGameClient.AsRequestStatus(response.ResponseStatus()), (ISavedGameMetadata)null); } else { this.mRetryFileOpen(); } })); } }
public void SavedGameOpened(SavedGameRequestStatus _status, ISavedGameMetadata _game) { if (_status == SavedGameRequestStatus.Success) { if (isSaving) { #if UNITY_ANDROID // 스트링 데이터를 바이트로 바꿔서 메타 정보와 함꼐 저장한다 slot0.State = "Opened, now writing"; byte[] data = slot0.ToBytes(); TimeSpan playedTime = slot0.TotalPlayingTime; SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder() .WithUpdatedPlayedTime(playedTime) .WithUpdatedDescription("Saved Game at " + DateTime.Now); SavedGameMetadataUpdate updatedMetadata = builder.Build(); ((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate( _game, updatedMetadata, data, SavedGameWritten); #endif } else { #if UNITY_ANDROID // 우선 파일을 읽어온다 slot0.State = "Opened, reading..."; ((PlayGamesPlatform)Social.Active).SavedGame .ReadBinaryData(_game, SavedGameLoaded); #endif } } else { Debug.LogWarning("Error opening game: " + _status); } }
//save is opened, either save or load it. private void SavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game) { #if UNITY_ANDROID Debug.Log("SavedGameOpened"); //check success if (status == SavedGameRequestStatus.Success) { //saving if (m_saving) { //read bytes from save byte[] data = ToBytes(); //create builder. here you can add play time, time created etc for UI. SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder(); SavedGameMetadataUpdate updatedMetadata = builder.Build(); //saving to cloud ((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(game, updatedMetadata, data, SavedGameWritten); Debug.Log("Commited Update: " + status); //loading } else { Debug.Log("SavedGame.ReadBinaryData"); ((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(game, SavedGameLoaded); SaveToCloud(); } //error } else { Debug.LogWarning("Error opening game: " + status); } #endif }
public void ChooseMetadata(ISavedGameMetadata chosenMetadata) { AndroidSnapshotMetadata convertedMetadata = chosenMetadata as AndroidSnapshotMetadata; if (convertedMetadata != mOriginal && convertedMetadata != mUnmerged) { OurUtils.Logger.e("Caller attempted to choose a version of the metadata that was not part " + "of the conflict"); mCompleteCallback(SavedGameRequestStatus.BadInputError, null); return; } using (var task = mSnapshotsClient.Call <AndroidJavaObject>( "resolveConflict", mConflict.Call <string>("getConflictId"), convertedMetadata.JavaSnapshot)) { AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>( task, dataOrConflict => mRetryFileOpen()); AndroidTaskUtils.AddOnFailureListener( task, exception => mCompleteCallback(SavedGameRequestStatus.InternalError, null)); } }
// Save the game public void SaveGame() { //SaveDataManager.instance.ResolveDataConflict (); SaveDataManager.instance.ApplyPlayerPrefs(); // print ("1"); // Check if signed in if (PlayGamesPlatform.Instance.localUser.authenticated) { // print ("2"); // Save game callback Action <SavedGameRequestStatus, ISavedGameMetadata> writeCallback = (SavedGameRequestStatus status, ISavedGameMetadata game) => { }; // Read binary callback Action <SavedGameRequestStatus, byte []> readBinaryCallback = (SavedGameRequestStatus status, byte [] data) => { }; // Read game callback Action <SavedGameRequestStatus, ISavedGameMetadata> readCallback = (SavedGameRequestStatus status, ISavedGameMetadata game) => { // Check if read was successful if (status == SavedGameRequestStatus.Success) { // print ("3"); currentGame = game; PlayGamesPlatform.Instance.SavedGame.ReadBinaryData(game, readBinaryCallback); } }; // Create new save data // SaveData saveData = new SaveData { // // // These values are hard coded for the purpose of this tutorial. // // Normally, you would replace these values with whatever you want to save. // playerName = "Borris", // playerHealth = 72.5f, // playerScore = 99245 // }; // Replace "MySaveGame" with whatever you would like to save file to be called //for TEST // try{ReadSaveGame ("MySaveGameTest2", readCallback);} //for R E A L S A V E // try{ReadSaveGame ("SaveGameProgress", readCallback);} // catch(Exception e){ //// t2.text = e.Message; // print ("5"); // print (e.Message); // } // try{ // WriteSaveGame (currentGame, SaveDataManager.ToBytes (SaveDataManager.instance.internalPlayerSavedData), writeCallback); // } catch(Exception e){ // print ("55"); // print (e.Message); // } ReadSaveGame("SaveGameProgress", readCallback); WriteSaveGame(currentGame, SaveDataManager.ToBytes(SaveDataManager.instance.internalPlayerSavedData), writeCallback); } //else // t2.text = "sign in first"; }
internal void DoShowSavedGameUI() { SetStandBy("Showing saved game UI"); PlayGamesPlatform.Instance.SavedGame.ShowSelectSavedGameUI( "Saved Game UI", 10, false, false, (status, savedGame) => { mStatus = "UI Status: " + status; if (savedGame != null) { mStatus += "Retrieved saved game with description: " + savedGame.Description; mCurrentSavedGame = savedGame; } EndStandBy(); }); }
private void ResolveConflict(IConflictResolver resolver, ISavedGameMetadata original, byte[] originalData, ISavedGameMetadata unmerged, byte[] unmergedData) { if (originalData == null) { resolver.ChooseMetadata(unmerged); } else if (unmergedData == null) { resolver.ChooseMetadata(original); } else { string originalStr = Encoding.ASCII.GetString(originalData); string unmergedStr = Encoding.ASCII.GetString(unmergedData); int[] originalArray = JsonUtil.JsonStringToArray(originalStr, "myKey", str => int.Parse(str)); int[] unmergedArray = JsonUtil.JsonStringToArray(unmergedStr, "myKey", str => int.Parse(str)); for (int i = 0; i < originalArray.Length; i++) { if (originalArray[i] > unmergedArray[i]) { resolver.ChooseMetadata(original); return; } else if (unmergedArray[i] > originalArray[i]) { resolver.ChooseMetadata(unmerged); return; } } resolver.ChooseMetadata(original); } }
public void ReadBinaryData(ISavedGameMetadata metadata, Action <SavedGameRequestStatus, byte[]> completedCallback) { throw new NotImplementedException(mMessage); }
internal void ShowWriteSavedGame() { DrawTitle("WRITE SAVED GAME"); DrawStatus(); mSavedGameFileContent = GUI.TextArea(CalcGrid(0, 1), mSavedGameFileContent); if (mCurrentSavedGame == null || !mCurrentSavedGame.IsOpen) { mStatus = "No opened saved game selected."; mUi = Ui.SavedGame; return; } var update = new SavedGameMetadataUpdate.Builder() .WithUpdatedDescription("Saved at " + DateTime.Now.ToString()) .WithUpdatedPlayedTime(mCurrentSavedGame.TotalTimePlayed.Add(TimeSpan.FromHours(1))) .Build(); if (GUI.Button(CalcGrid(0, 7), "Write")) { SetStandBy("Writing update"); PlayGamesPlatform.Instance.SavedGame.CommitUpdate( mCurrentSavedGame, update, System.Text.ASCIIEncoding.Default.GetBytes(mSavedGameFileContent), (status, updated) => { mStatus = "Write status was: " + status; mUi = Ui.SavedGame; EndStandBy(); }); mCurrentSavedGame = null; } else if (GUI.Button(CalcGrid(1, 7), "Cancel")) { mUi = Ui.SavedGame; } }
public void SavedGameWritten(SavedGameRequestStatus status, ISavedGameMetadata game) { if (status == SavedGameRequestStatus.Success) { Debug.Log("Game " + game.Description + " written"); } else { Debug.LogWarning("Error saving game: " + status); } }
private void OnSavedGameDataWritten(SavedGameRequestStatus status, ISavedGameMetadata game) { Debug.Log("Saved data to the cloud!"); }
/* * Reads the saved game file. * */ public void CloudLoad(ISavedGameMetadata game) { ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; savedGameClient.ReadBinaryData(game, OnCloudLoad); }
public void SavedGameWritten(SavedGameRequestStatus status, ISavedGameMetadata game) { Debug.Log(status); }
public void OnSaveWritten(SavedGameRequestStatus status, ISavedGameMetadata game) { if (status == SavedGameRequestStatus.Success) { } else { } }
/* * Checks to see if the saved file from the cloud has been successfully opened. Then does the cloud save and load depending on * the operation boolean "doSave". * */ public void OpenCloudSave(SavedGameRequestStatus status, ISavedGameMetadata game) { if (status == SavedGameRequestStatus.Success) { if (doSave) { CloudSave(status, game); } else { CloudLoad(game); } } else { } }
void SaveGameData(ISavedGameMetadata game, byte[] savedData) { ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder(); builder = builder .WithUpdatedPlayedTime(totalPlaytime) .WithUpdatedDescription("Saved game at " + DateTime.Now); SavedGameMetadataUpdate updatedMetadata = builder.Build(); savedGameClient.CommitUpdate(game, updatedMetadata, savedData, OnSavedGameWritten); }
void LoadGameData(ISavedGameMetadata game) { ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; savedGameClient.ReadBinaryData(game, OnSavedGameDataRead); }
// Load Game Data from Game MetaData private void LoadGameData(ISavedGameMetadata game) { ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; savedGameClient.ReadBinaryData(game, OnSavedGameDataRead); }
public void ReadBinaryData(ISavedGameMetadata metadata, Action<SavedGameRequestStatus, byte[]> completedCallback) { throw new NotImplementedException(mMessage); }
private void LoadGame(ISavedGameMetadata game) { PlayGamesPlatform.Instance.SavedGame.ReadBinaryData(game, OnSavedGameDataRead); }
public void SavedGameSelected(SelectUIStatus status, ISavedGameMetadata game) { if (status == SelectUIStatus.SavedGameSelected) { string filename = game.Filename; Debug.Log("opening saved game: " + game); if (mSaving && (filename == null || filename.Length == 0)) { filename = "save" + DateTime.Now.ToBinary(); } //open the data. ((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution(filename, DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, SavedGameOpened); } else { Debug.LogWarning("Error selecting save game: " + status); } }
static void LoadGame(SelectUIStatus status, ISavedGameMetadata game) { if (status == SelectUIStatus.SavedGameSelected) { OpenSavedGame(game, (ISavedGameMetadata openedGame) => { if(game.Description == null || game.Description == string.Empty) { // game has not been saved on cloud before, create new file CreateNewSave(openedGame, (ISavedGameMetadata newlySavedGame) => { LoadGame(SelectUIStatus.SavedGameSelected, newlySavedGame); }); return; } // Pull the time played if (game.TotalTimePlayed != null) timePlayed = game.TotalTimePlayed; // save should be opened now Debug.Log ("Loading save from: " + openedGame.Filename + "\n" + openedGame.Description + "\nOpened = " + openedGame.IsOpen.ToString ()); m_saveBundleMetadata = openedGame; ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; savedGameClient.ReadBinaryData(openedGame, (SavedGameRequestStatus reqStatus, byte[] data) => { Debug.Log("Reading save finished with status: " + reqStatus.ToString()); if (reqStatus == SavedGameRequestStatus.Success) { SaveDataBundle bundle = SaveDataBundle.FromByteArray(data); m_currentSaveBundle = bundle; if (OnSaveLoaded != null) { OnSaveLoaded.Invoke (bundle); OnSaveLoaded = null; } } }); }); } }
public void Delete(ISavedGameMetadata metadata) { Misc.CheckNotNull(metadata); mSnapshotManager.Delete((NativeSnapshotMetadata)metadata); }
public void OnSavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game) { if (status == SavedGameRequestStatus.Success) { int diam = PlayerPrefs.GetInt("Diamonds"); int[] sv = new int[64]; sv[0] = PlayerPrefs.GetInt("Diamonds"); if (PlayerPrefs.GetString("Doubler") == "Have") { sv[1] = 1; } else { sv[1] = 0; } sv[2] = PlayerPrefs.GetInt("olaf_power"); sv[3] = PlayerPrefs.GetInt("olaf_stam"); sv[4] = PlayerPrefs.GetInt("olaf_stam_regen"); sv[5] = PlayerPrefs.GetInt("olaf_castle"); sv[6] = PlayerPrefs.GetInt("olaf_crit_chance"); sv[7] = PlayerPrefs.GetInt("olaf_crit_power"); sv[8] = PlayerPrefs.GetInt("olaf_weapon"); if (PlayerPrefs.GetString("OdiCheck") == "Open") { sv[9] = 1; } else { sv[9] = 0; } sv[10] = PlayerPrefs.GetInt("odi_power"); sv[11] = PlayerPrefs.GetInt("odi_stam"); sv[12] = PlayerPrefs.GetInt("odi_stam_regen"); sv[13] = PlayerPrefs.GetInt("odi_castle"); sv[14] = PlayerPrefs.GetInt("odi_crit_chance"); sv[15] = PlayerPrefs.GetInt("odi_crit_power"); sv[16] = PlayerPrefs.GetInt("odi_weapon"); if (PlayerPrefs.GetString("FionaCheck") == "Open") { sv[17] = 1; } else { sv[17] = 0; } sv[18] = PlayerPrefs.GetInt("fiona_power"); sv[19] = PlayerPrefs.GetInt("fiona_stam"); sv[20] = PlayerPrefs.GetInt("fiona_stam_regen"); sv[21] = PlayerPrefs.GetInt("fiona_castle"); sv[22] = PlayerPrefs.GetInt("fiona_crit_chance"); sv[23] = PlayerPrefs.GetInt("fiona_crit_power"); sv[24] = PlayerPrefs.GetInt("fiona_weapon"); if (PlayerPrefs.GetString("MorganaCheck") == "Open") { sv[25] = 1; } else { sv[25] = 0; } sv[26] = PlayerPrefs.GetInt("morgana_power"); sv[27] = PlayerPrefs.GetInt("morgana_stam"); sv[28] = PlayerPrefs.GetInt("morgana_stam_regen"); sv[29] = PlayerPrefs.GetInt("morgana_castle"); sv[30] = PlayerPrefs.GetInt("morgana_crit_chance"); sv[31] = PlayerPrefs.GetInt("morgana_crit_power"); sv[32] = PlayerPrefs.GetInt("morgana_weapon"); if (PlayerPrefs.GetString("MaximusCheck") == "Open") { sv[33] = 1; } else { sv[33] = 0; } sv[34] = PlayerPrefs.GetInt("maximus_power"); sv[35] = PlayerPrefs.GetInt("maximus_stam"); sv[36] = PlayerPrefs.GetInt("maximus_stam_regen"); sv[37] = PlayerPrefs.GetInt("maximus_castle"); sv[38] = PlayerPrefs.GetInt("maximus_crit_chance"); sv[39] = PlayerPrefs.GetInt("maximus_crit_power"); sv[40] = PlayerPrefs.GetInt("maximus_weapon"); if (PlayerPrefs.GetString("BOOM-BOOMCheck") == "Open") { sv[41] = 1; } else { sv[41] = 0; } sv[42] = PlayerPrefs.GetInt("boom-boom_power"); sv[43] = PlayerPrefs.GetInt("boom-boom_stam"); sv[44] = PlayerPrefs.GetInt("boom-boom_stam_regen"); sv[45] = PlayerPrefs.GetInt("boom-boom_castle"); sv[46] = PlayerPrefs.GetInt("boom-boom_crit_chance"); sv[47] = PlayerPrefs.GetInt("boom-boom_crit_power"); sv[48] = PlayerPrefs.GetInt("boom-boom_weapon"); byte[] data = new byte[sv.Length * 4]; for (int i = 0; i < sv.Length; i++) { Array.Copy(BitConverter.GetBytes(sv[i]), 0, data, i * 4, 4); } TimeSpan tim = new TimeSpan(0, 0, (int)Time.realtimeSinceStartup); //byte[] coins = System.BitConverter.GetBytes(diam); if (save) { SaveGame(game, data, tim); } else { LoadGameData(game); } // handle reading or writing of saved game. } else { // handle error Debug.Log("Saved data opened "); } }
internal void DoDeleteSavedGame() { if (mCurrentSavedGame == null) { ShowEffect(false); Status = "No save game selected"; return; } PlayGamesPlatform.Instance.SavedGame.Delete(mCurrentSavedGame); Status = mCurrentSavedGame.Filename + " deleted."; mCurrentSavedGame = null; }
private void LoadGame(ISavedGameMetadata game) { ((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(game, OnSavedGameDataRead); }
public void CommitUpdate(ISavedGameMetadata metadata, SavedGameMetadataUpdate updateForMetadata, byte[] updatedBinaryData, Action <SavedGameRequestStatus, ISavedGameMetadata> callback) { throw new NotImplementedException(mMessage); }
void OnSavedGameOpenedAndReadConflictResolve(IConflictResolver resolver, ISavedGameMetadata original, byte[] originalData, ISavedGameMetadata unmerged, byte[] unmergedData) { resolver.ChooseMetadata(original); }
internal void DoOpenManual() { SetStandBy("Manual opening file: " + mSavedGameFilename); PlayGamesPlatform.Instance.SavedGame.OpenWithManualConflictResolution( mSavedGameFilename, DataSource.ReadNetworkOnly, true, (resolver, original, originalData, unmerged, unmergedData) => { Logger.d("Entering conflict callback"); mConflictResolver = resolver; mConflictOriginal = original; mConflictOriginalData = System.Text.ASCIIEncoding.Default.GetString(originalData); mConflictUnmerged = unmerged; mConflictUnmergedData = System.Text.ASCIIEncoding.Default.GetString(unmergedData); mUi = Ui.ResolveSaveConflict; EndStandBy(); Logger.d("Encountered manual open conflict."); }, (status, openedFile) => { mStatus = "Open status for file " + mSavedGameFilename + ": " + status + "\n"; if (openedFile != null) { mStatus += "Successfully opened file: " + openedFile.ToString(); Logger.d("Opened file: " + openedFile.ToString()); mCurrentSavedGame = openedFile; } EndStandBy(); }); }
public void CommitUpdate(ISavedGameMetadata metadata, SavedGameMetadataUpdate updateForMetadata, byte[] updatedBinaryData, Action<SavedGameRequestStatus, ISavedGameMetadata> callback) { throw new NotImplementedException(mMessage); }
internal void OpenSavedGame(ConflictResolutionStrategy strategy) { SetStandBy("Opening using strategy: " + strategy); PlayGamesPlatform.Instance.SavedGame.OpenWithAutomaticConflictResolution( mSavedGameFilename, DataSource.ReadNetworkOnly, strategy, (status, openedFile) => { mStatus = "Open status for file " + mSavedGameFilename + ": " + status + "\n"; if (openedFile != null) { mStatus += "Successfully opened file: " + openedFile.ToString(); Logger.d("Opened file: " + openedFile.ToString()); mCurrentSavedGame = openedFile; } EndStandBy(); }); }
private void SaveUpdate(SavedGameRequestStatus status, ISavedGameMetadata meta) { Debug.Log(status); }
private void LoadGame(ISavedGameMetadata game) { #if UNITY_ANDROID ((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(game, OnSavedGameDataRead); #endif }
// Load the game public void LoadGame() { // print ("load"); // Check if signed in if (PlayGamesPlatform.Instance.localUser.authenticated) { // print ("auth"); // Read binary callback Action <SavedGameRequestStatus, byte[]> readBinaryCallback = (SavedGameRequestStatus status, byte[] data) => { // print (status + " " + SavedGameRequestStatus.Success); // Check if read was successful if (status == SavedGameRequestStatus.Success) { // Load game data // try { // print ("7"); //SaveData saveData = SaveData.FromBytes (data); SaveDataManager.instance.cloudPlayerSavedData = SaveDataManager.FromBytes(data); SaveDataManager.instance.ResolveDataConflict(); SaveDataManager.instance.ToJSON(); // print (SaveDataManager.instance.json); // t1.text = SaveDataManager.instance.json; // t3.text = SaveDataManager.instance.json; // SaveDataManager.instance.OverridePlayerPrefs(); // // // We are displaying these values for the purpose of the tutorial. // // Normally you would set the values here. // Debug.Log ("Player name = " + saveData.playerName); // Debug.Log ("Player health = " + saveData.playerHealth); // Debug.Log ("Player score = " + saveData.playerScore); //Debug.Log(saveData); // } catch (Exception e) { // // print ("77"+e.Message); //// Debug.LogError ("Failed to read binary data: " + e.ToString ()); //// t1.text = "Failed to read binary data: " + e.ToString (); // } } else { // print (status); // print (status + " " + SavedGameRequestStatus.Success); } }; // Read game callback Action <SavedGameRequestStatus, ISavedGameMetadata> readCallback = (SavedGameRequestStatus status, ISavedGameMetadata game) => { // Check if read was successful if (status == SavedGameRequestStatus.Success) { currentGame = game; PlayGamesPlatform.Instance.SavedGame.ReadBinaryData(game, readBinaryCallback); } }; // // Replace "MySaveGame" with whatever you would like to save file to be called // ReadSaveGame ("MySaveGameTest1", readCallback); // // for T E S T // try{ReadSaveGame ("MySaveGameTest3", readCallback); // for R E A L S A V E // try { // ReadSaveGame ("SaveGameProgress", readCallback); // } catch (Exception e) { //// t2.text = e.Message; // print (e.Message); // } ReadSaveGame("SaveGameProgress", readCallback); } else { // print ("blom auth"); } }
private void CloudDataWasWrittenCallback(SavedGameRequestStatus status, ISavedGameMetadata game) { UpdateCloudStatus(status == SavedGameRequestStatus.Success ? CloudStatus.CloudUpdated : CloudStatus.CloudDisconnected); }
private void WriteUpdatedOrRead(Action <string> onComplete, byte[] writeData = null) { // Local variable ISavedGameMetadata currentGame = null;//(2)で初期化 newDataRaw = writeData; // SAVE CALLBACK: Handle the result of a write Action <SavedGameRequestStatus, ISavedGameMetadata> writeCallback = (SavedGameRequestStatus status, ISavedGameMetadata game) => { if (status == SavedGameRequestStatus.Success) { onComplete(System.Text.Encoding.UTF8.GetString(writeData)); } else { //エラー onComplete(null); } }; // LOAD CALLBACK: Handle the result of a binary read Action <SavedGameRequestStatus, byte[]> readBinaryCallback = (SavedGameRequestStatus status, byte[] data) => { if (status == SavedGameRequestStatus.Success) { // Read score from the Saved Game if (newDataRaw == null) { //Read Finish //読み出し-Phase3 string readString = System.Text.Encoding.UTF8.GetString(data); onComplete(readString); } } else { //エラー onComplete(null); } }; ReadSavedGame(_cloudDataFileName, (SavedGameRequestStatus status, ISavedGameMetadata game) => { currentGame = game; if (newDataRaw == null) { //読み出し if (status == SavedGameRequestStatus.Success) { PlayGamesPlatform.Instance.SavedGame.ReadBinaryData(game, readBinaryCallback); } else { //エラー onComplete(null); } } else { //書き込み WriteSavedGame(currentGame, newDataRaw, writeCallback); } }); }
/// <summary> /// Opens the saved game. /// </summary> /// <param name="savedGame">Saved game.</param> /// <param name="callback">Invoked when game has been opened</param> private static void OpenSavedGame(ISavedGameMetadata savedGame, Action<ISavedGameMetadata> callback) { if (savedGame == null) return; if (!savedGame.IsOpen) { ISavedGameClient saveGameClient = PlayGamesPlatform.Instance.SavedGame; // save name is generated only when save has not been commited yet saveGameClient.OpenWithAutomaticConflictResolution( savedGame.Filename == string.Empty ? "Save" + UnityEngine.Random.Range(1000000,9999999).ToString() : savedGame.Filename, DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, (SavedGameRequestStatus reqStatus, ISavedGameMetadata openedGame) => { if(reqStatus == SavedGameRequestStatus.Success) { m_saveBundleMetadata = openedGame; if(callback != null) callback.Invoke(m_saveBundleMetadata); } } ); } else { if (callback != null) callback.Invoke(savedGame); } }
/// <summary> /// Prepare data to be saved on GPGS after saved game has been opened /// </summary> /// <param name="status">Status.</param> /// <param name="_gameMD">Game M.</param> static void SaveOnSavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata _gameMD) { if (status == SavedGameRequestStatus.Success) { UIManager.DisplaySaveState(UIManager.SaveState.open); UIManager.Notify(File.Exists(Application.persistentDataPath + fileName).ToString()); if(File.Exists(Application.persistentDataPath + fileName)){ UIManager.Notify("to bytes"); byte[] savedData = File.ReadAllBytes(Application.persistentDataPath + fileName); UIManager.Notify("savedData lenght " + savedData.Length); TimeSpan totalPlaytime = (DateTime.Now - gameStart) + _gameMD.TotalTimePlayed; SetGameStart(); SaveOnGPGS(_gameMD, savedData, totalPlaytime); } else { UIManager.Notify("file doesnt exist"); } } else { // handle error } }
/// <summary> /// Commits the save to cloud. /// </summary> /// <param name="file">Actual save file. This will replace static reference to current save file</param> /// <param name="fileName">File name. Used only when saving for first time</param> /// <param name="callback">Invoked after commit (true = success)</param> private static void CommitSaveToCloud(SaveDataBundle file, string fileName, System.Action<bool> callback) { ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; savedGameClient.OpenWithAutomaticConflictResolution( m_saveBundleMetadata.Filename == string.Empty ? fileName : m_saveBundleMetadata.Filename, DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, (SavedGameRequestStatus reqStatus, ISavedGameMetadata openedGame) => { if(reqStatus == SavedGameRequestStatus.Success) { // adding real time since startup so we can determine longes playtime and resolve future conflicts easilly m_saveBundleMetadata = openedGame; SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder (); builder = builder .WithUpdatedPlayedTime(timePlayed) .WithUpdatedDescription("Saved game at " + DateTime.Now); if (bannerTexture != null) { builder = builder.WithUpdatedPngCoverImage(bannerTexture.EncodeToPNG()); } //m_saveBundleMetadata.TotalTimePlayed.Add (new TimeSpan (0, 0, (int)Time.realtimeSinceStartup)) SavedGameMetadataUpdate updatedMetadata = builder.Build(); savedGameClient.CommitUpdate( m_saveBundleMetadata, updatedMetadata, SaveDataBundle.ToByteArray(file), (SavedGameRequestStatus status, ISavedGameMetadata game) => { Debug.Log("SGI CommitUpdate callback invoked with status " + status + ", proceeding..."); if (status == SavedGameRequestStatus.Success) { m_saveBundleMetadata = game; m_currentSaveBundle = file; } if (callback != null) callback.Invoke(status == SavedGameRequestStatus.Success); } ); } } ); }
/// <summary> /// Restore game data after saved game has been opened on GPGS /// </summary> /// <param name="status">Status.</param> /// <param name="_gameMD">Game M.</param> static void LoadOnSavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata _gameMD) { if (status == SavedGameRequestStatus.Success) { ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; savedGameClient.ReadBinaryData(_gameMD, OnSavedGameDataRead); } else { // handle error } }
void LoadGameData(SavedGameRequestStatus status, ISavedGameMetadata game) { ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; savedGameClient.ReadBinaryData(game, OnSavedGameDataRead); }
// static void DeserializeData(string data){ // string[] ListRecipes; // ListRecipes = data.Split("@"[0]); // // for(int s = 0; s < ListRecipes.Length; s++){ // // if(ListRecipes[s] != null && ListRecipes[s] != ""){ // // string recipe = ListRecipes[s]; // string recipeName = recipe.Substring(0, recipe.Length - 10); // // Debug.Log(recipeName); // int suc = int.Parse(recipe.Substring(recipe.Length - 9, 4)); // // Debug.Log(suc); // int tri = int.Parse(recipe.Substring(recipe.Length - 4, 4)); // // Debug.Log(tri); // // // if(s-1 >= GameManager.Instance.garden.Count){ // // GameManager.Instance.gardenSize++; // // GameManager.Instance.CreateParcel(GameManager.Instance.gardenSize); // // } // // // // // // GameManager.Instance.garden[s-1].GetComponent<Parcel>().SetpH(float.Parse(ph)); // // // // if(listParcel[s].Contains("pt:")){ // // // // GameManager.Instance.currentParcelGO = GameManager.Instance.garden[s-1]; // // GameManager.Instance.currentParcelGO.GetComponent<Parcel>().SetPlant(GardenManager.Instance.PlantFromString(listParcel[s].Substring(10))); // // } // } // // } // loadFinished = true; // TutorialManager.Instance.ShowNextTip(); // } static void OnSavedGameSelected (SelectUIStatus status, ISavedGameMetadata _gameMD) { if (status == SelectUIStatus.SavedGameSelected) { // handle selected game save ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; savedGameClient.ReadBinaryData(_gameMD, OnSavedGameDataRead); } else { // handle cancel or error } }
private void OnSavedGameDataWritten(SavedGameRequestStatus status, ISavedGameMetadata game) { }
/// <summary> /// Prepare updated metadata and commit update to GPGS /// </summary> /// <param name="_gameMetaData">Game meta data.</param> /// <param name="savedData">Saved data.</param> /// <param name="totalPlaytime">Total playtime.</param> static void SaveOnGPGS (ISavedGameMetadata _gameMetaData, byte[] savedData, TimeSpan totalPlaytime) { ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; Texture2D savedImage = getScreenshot(); SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder(); builder = builder .WithUpdatedPlayedTime(totalPlaytime) .WithUpdatedDescription("Saved game at " + DateTime.Now); if (savedImage != null) { // This assumes that savedImage is an instance of Texture2D // and that you have already called a function equivalent to // getScreenshot() to set savedImage // NOTE: see sample definition of getScreenshot() method below byte[] pngData = savedImage.EncodeToPNG(); builder = builder.WithUpdatedPngCoverImage(pngData); } SavedGameMetadataUpdate updatedMetadata = builder.Build(); UIManager.Notify("commiting"); savedGameClient.CommitUpdate(_gameMetaData, updatedMetadata, savedData, OnSavedGameWritten); }
public void CommitUpdate(ISavedGameMetadata metadata, SavedGameMetadataUpdate updateForMetadata, byte[] updatedBinaryData, Action <SavedGameRequestStatus, ISavedGameMetadata> callback) {
static void OnSavedGameWritten (SavedGameRequestStatus status, ISavedGameMetadata game) { if (status == SavedGameRequestStatus.Success) { UIManager.Notify("Cloud saved"); UIManager.DisplaySaveState(UIManager.SaveState.savedOnline); } }
private void ReadGameData(ISavedGameMetadata game, Action <SavedGameRequestStatus, byte[]> onSavedGameDataRead) { ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; savedGameClient.ReadBinaryData(game, onSavedGameDataRead); }
static void DeleteGames(SavedGameRequestStatus status, ISavedGameMetadata gameMetaData){ ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; savedGameClient.Delete(gameMetaData); }
void LoadGameData(ISavedGameMetadata data) { ISavedGameClient savedClient = PlayGamesPlatform.Instance.SavedGame; savedClient.ReadBinaryData(data, OnSavedGameDataRead); }
public void SavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game) { if (status == SavedGameRequestStatus.Success) { if (mSaving) { if (mScreenImage == null) { CaptureScreenshot(); } byte[] pngData = (mScreenImage != null) ? mScreenImage.EncodeToPNG() : null; Debug.Log("Saving to " + game); byte[] data = mProgress.ToBytes(); TimeSpan playedTime = mProgress.TotalPlayingTime; SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder() .WithUpdatedPlayedTime(playedTime) .WithUpdatedDescription("Saved Game at " + DateTime.Now); if (pngData != null) { Debug.Log("Save image of len " + pngData.Length); builder = builder.WithUpdatedPngCoverImage(pngData); } else { Debug.Log("No image avail"); } SavedGameMetadataUpdate updatedMetadata = builder.Build(); ((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(game, updatedMetadata, data, SavedGameWritten); } else { mAutoSaveName = game.Filename; ((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(game, SavedGameLoaded); } } else { Debug.LogWarning("Error opening game: " + status); } }