전체소스


using System;

using System.Collections;

using System.Collections.Generic;

using System.Runtime.Serialization.Formatters.Binary;

using System.IO;

using GooglePlayGames;

using GooglePlayGames.BasicApi;

using GooglePlayGames.BasicApi.SavedGame;

using UnityEngine.SocialPlatforms;

using UnityEngine;

using UnityEngine.UI;


public class Save : MonoBehaviour

{

    public Text debugText;

    public Text text1;

    public Text text2;


    public const string dataName = "Save";


    public CloudVariables c;


    public bool isSaving = true;


    // Use this for initialization

    void Start()

    {

        c = new CloudVariables();



        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()

        // enables saving game progress.

        .EnableSavedGames()

        .Build();


        PlayGamesPlatform.InitializeInstance(config);

        PlayGamesPlatform.Activate();

        //Login();

    }


    public void Saver()

    {

        isSaving = true;

        OpenSavedGame(dataName);

    }

    public void Loader()

    {

        isSaving = false;

        OpenSavedGame(dataName);

    }




    void OpenSavedGame(string filename)

    {

        if (!Social.localUser.authenticated)

        {

            debugText.text = "You should login first";

            return;

        }

        debugText.text = "OpenSavedGame..";

        ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;

        savedGameClient.OpenWithAutomaticConflictResolution(filename, DataSource.ReadCacheOrNetwork,

            ConflictResolutionStrategy.UseLongestPlaytime, OnSavedGameOpened);

    }


    public void OnSavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game)

    {

        if (status == SavedGameRequestStatus.Success)

        {

            debugText.text = "SavedGameRequesSucces..";

            // handle reading or writing of saved game.

            if (isSaving)

            {

                CloudVariables cv = new CloudVariables();

                cv.test1 = 50;

                cv.test2 = 20;

                debugText.text = "CheckisSaving..";

                ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;

                SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder();

                SavedGameMetadataUpdate updatedMeta>

                debugText.text = "SaveGame..";

                //((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(game, updatedMetadata, ClassToByteArray(cv), OnSavedGameWritten);

                savedGameClient.CommitUpdate(game, updatedMetadata, ClassToByteArray(cv), OnSavedGameWritten);

                debugText.text = "CommitUpdateComplete..";

                //SaveGame(game, ClassToByteArray(cv));

            }

            else

                LoadGameData(game);

        }

        else

        {

            // handle error

        }

    }


    void SaveGame(ISavedGameMetadata game, byte[] savedData)

    {

        ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;


        SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder();


        SavedGameMetadataUpdate updatedMeta>

        savedGameClient.CommitUpdate(game, updatedMetadata, savedData, OnSavedGameWritten);

    }


    public void OnSavedGameWritten(SavedGameRequestStatus status, ISavedGameMetadata game)

    {

        if (status == SavedGameRequestStatus.Success)

        {

            debugText.text = "SaveGameWrittenSuccess..";

            // handle reading or writing of saved game.

        }

        else

        {

            // handle error

        }

    }


    void LoadGameData(ISavedGameMetadata game)

    {

        debugText.text = "LoadGameData..";

        ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;

        savedGameClient.ReadBinaryData(game, OnSavedGameDataRead);

    }


    public void OnSavedGameDataRead(SavedGameRequestStatus status, byte[] data)

    {

        if (status == SavedGameRequestStatus.Success)

        {

            BinaryFormatter bf = new BinaryFormatter();

            debugText.text = "SaveGameDataReadSuccess..";

            CloudVariables cv = (CloudVariables)bf.Deserialize(new MemoryStream(data));

            c = cv;

        }

        else

        {

            // handle error

        }

    }


    public byte[] ClassToByteArray(CloudVariables cv)

    {

        using (var memoryStream = new MemoryStream())

        {

            BinaryFormatter bf = new BinaryFormatter();

            memoryStream.Flush();

            memoryStream.Position = 0;

            bf.Serialize(memoryStream, cv);

            return memoryStream.ToArray();

        }

    }

}


[System.Serializable]

public class CloudVariables

{

    public int test1;

    public int test2;

}






문제일것 같은 소스


savedGameClient.OpenWithAutomaticConflictResolution(filename, DataSource.ReadCacheOrNetwork,

            ConflictResolutionStrategy.UseLongestPlaytime, OnSavedGameOpened);


여기서 막히는것 같은데 해결방법좀...