Search Unity

Cloud Saving Google Play Games

Discussion in 'Scripting' started by TheFuzzyDev, Mar 21, 2019.

  1. TheFuzzyDev

    TheFuzzyDev

    Joined:
    Feb 18, 2019
    Posts:
    3
    i dont know why my cloud saving its nor working, My Code
    Code (CSharp):
    1.     #region SaveGames
    2.     private string GetSaveString()
    3.     {
    4.         String r = "";
    5.         r += PlayerPrefs.GetFloat("HighScoreEz").ToString();
    6.         r += "|";
    7.         r += PlayerPrefs.GetFloat("HighScore").ToString();
    8.         r += "|";
    9.         r += PlayerPrefs.GetFloat("HighScoreDrop").ToString();
    10.         r += "|";
    11.         r += PlayerPrefs.GetFloat("ActualXp").ToString();
    12.         r += "|";
    13.         r += PlayerPrefs.GetFloat("ActualLevel").ToString();
    14.         r += "|";
    15.         r += PlayerPrefs.GetFloat("CurrentCoins", Coins.ActualCoins).ToString();
    16.  
    17.         return r;
    18.     }
    19.     private void LoadSaveString(string save)
    20.     {
    21.         string[] data = save.Split('|');
    22.         PlayerPrefs.SetFloat("HighScoreEz", float.Parse(data[0]));
    23.         PlayerPrefs.SetFloat("HighScore", float.Parse(data[1]));
    24.         PlayerPrefs.SetFloat("HighScoreDrop", float.Parse(data[2]));
    25.         PlayerPrefs.SetFloat("ActualXP", float.Parse(data[3]));
    26.         PlayerPrefs.SetFloat("ActualLevel", float.Parse(data[4]));
    27.         PlayerPrefs.SetFloat("CurrentCoins", float.Parse(data[5]));
    28.     }
    29.     private bool isSaving = false;
    30.     public void OpenSave(bool saving)
    31.     {
    32.         Debug.Log(saving);
    33.         if (Social.localUser.authenticated)
    34.         {
    35.             isSaving = saving;
    36.             ((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution("CubeColors", GooglePlayGames.BasicApi.DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, SaveGameOpened);
    37.         }
    38.     }
    39.  
    40.     private void SaveGameOpened(SavedGameRequestStatus status, ISavedGameMetadata meta)
    41.     {
    42.         if(status == SavedGameRequestStatus.Success)
    43.         {
    44.             if (isSaving)
    45.             {
    46.                 Byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(GetSaveString());
    47.                 SavedGameMetadataUpdate UpdateS = new SavedGameMetadataUpdate.Builder().WithUpdatedDescription("Saved At" + DateTime.Now.ToString()).Build();
    48.  
    49.                 ((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(meta, UpdateS, data, SaveUpdate);
    50.             }
    51.             else
    52.             {
    53.                 ((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(meta, SaveRead);
    54.             }
    55.         }
    56.     }
    57.  
    58.     private void SaveRead(SavedGameRequestStatus status, byte[] data)
    59.     {
    60.         if(status == SavedGameRequestStatus.Success)
    61.         {
    62.             string SaveData = System.Text.ASCIIEncoding.ASCII.GetString(data);
    63.             LoadSaveString(SaveData);
    64.         }
    65.     }
    66.  
    67.     private void SaveUpdate(SavedGameRequestStatus status, ISavedGameMetadata meta)
    68.     {
    69.        
    70.     }
    71.  
    72.  
    73.     #endregion /SaveGames
    74.     private void Update()
    75.     {
    76.         SignIn();
    77.     }
    78.     private void OnApplicationQuit()
    79.     {
    80.         if (Social.localUser.authenticated)
    81.         {
    82.             OpenSave(true);
    83.         }
    84.     }
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    No one ever gets help on the forum if they are not willing to describe their problem in more detail than it is not working.

    That is like calling a mechanic and only saying your car is not working and expecting them to tell you exactly why. Obviously a lot more details are needed.