Advertisement

Google services cloud save not working(Unity)

Started by February 13, 2019 04:39 PM
0 comments, last by ggenije 5 years, 7 months ago

Everything worked well until I enabled cloud save.
SignIn and Signout works but achievements don't show up.
SaveGame is enabled on play console


    //now
     PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().EnableSavedGames().Build();
    
    //before
    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();

CloudsaveloadCode
    


 public void ReadSavedGame(string filename,
                                 Action<SavedGameRequestStatus, ISavedGameMetadata> callback)
        {
    
            ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
            savedGameClient.OpenWithAutomaticConflictResolution(
                filename,
                DataSource.ReadCacheOrNetwork,
                ConflictResolutionStrategy.UseLongestPlaytime,
                callback);
        }
    
        public void WriteSavedGame(ISavedGameMetadata game, byte[] savedData,
                                   Action<SavedGameRequestStatus, ISavedGameMetadata> callback)
        {
    
            SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder()
                .WithUpdatedPlayedTime(TimeSpan.FromMinutes(game.TotalTimePlayed.Minutes + 1))
                .WithUpdatedDescription("Saved at: " + System.DateTime.Now);
    
            // You can add an image to saved game data (such as as screenshot)
            // byte[] pngData = <PNG AS BYTES>;
            // builder = builder.WithUpdatedPngCoverImage(pngData);
    
            SavedGameMetadataUpdate updatedMetadata = builder.Build();
    
            ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
            savedGameClient.CommitUpdate(game, updatedMetadata, savedData, callback);
        }
    
        public void WriteGame()
        {
            // Local variable
            ISavedGameMetadata currentGame = null;
    
            // CALLBACK: Handle the result of a write
            Action<SavedGameRequestStatus, ISavedGameMetadata> writeCallback =
            (SavedGameRequestStatus status, ISavedGameMetadata game) => {
                Debug.Log("(Lollygagger) Saved Game Write: " + status.ToString());
            };
    
            // CALLBACK: Handle the result of a binary read
            Action<SavedGameRequestStatus, byte[]> readBinaryCallback =
            (SavedGameRequestStatus status, byte[] data) => {
                Debug.Log("(Lollygagger) Saved Game Binary Read: " + status.ToString());
                if (status == SavedGameRequestStatus.Success)
                {
                    // Read score from the Saved Game
                    int score = 0;
                    try
                    {
                        string scoreString = System.Text.Encoding.UTF8.GetString(data);
                        score = Convert.ToInt32(scoreString);
                    }
                    catch (Exception e)
                    {
                        Debug.Log("(Lollygagger) Saved Game Write: convert exception");
                    }
    
                    // Increment score, convert to byte[]
                    int newScore = int.Parse(tekst.text);
                    string newScoreString = Convert.ToString(newScore);
                    byte[] newData = System.Text.Encoding.UTF8.GetBytes(newScoreString);
    
                    // Write new data
                    Debug.Log("(Lollygagger) Old Score: " + score.ToString());
                   // Debug.Log("(Lollygagger) mHits: " + mHits.ToString());
                    Debug.Log("(Lollygagger) New Score: " + newScore.ToString());
                    WriteSavedGame(currentGame, newData, writeCallback);
                }
            };
    
    
            /*// CALLBACK: Handle the result of a read, which should return metadata
            Action<SavedGameRequestStatus, ISavedGameMetadata> readCallback =
            (SavedGameRequestStatus status, ISavedGameMetadata game) => {
                Debug.Log("(Lollygagger) Saved Game Read: " + status.ToString());
                if (status == SavedGameRequestStatus.Success)
                {
                    // Read the binary game data
                    currentGame = game;
                    PlayGamesPlatform.Instance.SavedGame.ReadBinaryData(game,
                                                        readBinaryCallback);
                }
            };
    
            // Read the current data and kick off the callback chain
            Debug.Log("(Lollygagger) Saved Game: Reading");
            ReadSavedGame("file_total_hits", readCallback);*/
        }
    
        public void LoadGAme()
        {
            // Local variable
            ISavedGameMetadata currentGame = null;
    
    
            // CALLBACK: Handle the result of a binary read
            Action<SavedGameRequestStatus, byte[]> readBinaryCallback =
            (SavedGameRequestStatus status, byte[] data) => {
                Debug.Log("(Lollygagger) Saved Game Binary Read: " + status.ToString());
                if (status == SavedGameRequestStatus.Success)
                {
                    // Read score from the Saved Game
                    int score = 0;
                    try
                    {
                        string scoreString = System.Text.Encoding.UTF8.GetString(data);
                        score = Convert.ToInt32(scoreString);
                    }
                    catch (Exception e)
                    {
                        Debug.Log("(Lollygagger) Saved Game Write: convert exception");
                    }
    
                    // Increment score, convert to byte[]
                    int newScore = int.Parse(tekst.text);
                    string newScoreString = Convert.ToString(newScore);
                    byte[] newData = System.Text.Encoding.UTF8.GetBytes(newScoreString);
    
                    // Write new data
                    Debug.Log("(Lollygagger) Old Score: " + score.ToString());
                    // Debug.Log("(Lollygagger) mHits: " + mHits.ToString());
                    Debug.Log("(Lollygagger) New Score: " + newScore.ToString());
                    
                }
            };
    
            Action<SavedGameRequestStatus, ISavedGameMetadata> readCallback =
            (SavedGameRequestStatus status, ISavedGameMetadata game) => {
                Debug.Log("(Lollygagger) Saved Game Read: " + status.ToString());
                if (status == SavedGameRequestStatus.Success)
                {
                    // Read the binary game data
                    currentGame = game;
                    PlayGamesPlatform.Instance.SavedGame.ReadBinaryData(game,
                                                        readBinaryCallback);
                }
            };
    
            // Read the current data and kick off the callback chain
            Debug.Log("(Lollygagger) Saved Game: Reading");
            ReadSavedGame("file_total_hits", readCallback);
        }

 

This topic is closed to new replies.

Advertisement