save/load Data to Google Play games

Hello;

I m developing an android Game . the game uses Google Games Services. I can successfully sign in and show achievement and leaderboard.
My first problem now when i use the saved Services, I have for exemple a public float Coins, is it possible to save it to the Cloud . I want to save some variable to the Google Cloud, when the player open my games and when the player close the game, save these variable to the cloud. Is it possible and how can i do that. there isn’t documentation to explain that. Can you help please. Thanks a lot

2 Answers

2

Yes its possible.Google Play Game services allows cloud data save.You can save anything converted to a binary (bytes) data.If you are using the play games plugin provided by Google in GitHub,everything is explained in detail there. GitHub - playgameservices/play-games-plugin-for-unity: Google Play Games plugin for Unity

The plugin should be initialized with save game feature enabled

PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
        // enables saving game progress.
        .EnableSavedGames()
        .Build();
    PlayGamesPlatform.InitializeInstance(config);

Check for opening and saving games section under ‘Saving Game State to the Cloud’ .

Hello sethuraj, Thanks for your answer , imagine if i have a public float Coins , how can i convert this variable to binary(bytes[]) and how can i save it to the cloud.Thanks again

@IronGirl A coin count will be always an integer.So there is no need to use a float to denote the coin count //The variable which holds the coin count public int Coins; //Convert the coin count integer to a byte array byte[] CoinData = BitConverter.GetBytes( Coins); You can then write the value in 'CoinData' to cloud.Please read through this documentation for using play games services.Its very simple to understand https://github.com/playgameservices/play-games-plugin-for-unity

@sethuraj Its too hard for me to understand =(

@sethuraj @IronGirl I am saving gems in my game using same process. But it opens a popup showing previous saves. Any way I can bypass that? Or using cloud method in this scenario is wrong. (In my Game, Player buy gems & I want to use some secure methods to save it on cloud) Please answer my question at http://answers.unity3d.com/questions/1185506/saving-coins-online-after-in-app-purchase.html Thanks :(

google play service api support save data with snapshot api.
this is a code show how to save data.
Game Snapshot

Display saved snapshot with default ui

GoogleGame.Instance().showSnapshots(“saved games”, true, true, 10);
Save Game State with google play snapshot api.open snapshot first

GoogleGame.Instance().openSnapshot(“firstgamesnap”, true, GameConst.RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED);
and then write snapshot after event onOpenSnapshotResult,snapshotfilePath is a image path,the second param is your game data

GoogleGame.Instance().writeSnapshot(snapshotfilePath, System.Text.Encoding.UTF8.GetBytes(“{‘score’:20}”));
open a snapshot first and then get you saved data

GoogleGame.Instance().openSnapshot(“firstgamesnap”, true, GameConst.RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED);
after open success

byte gamedata=GoogleGame.Instance().readSnapshot();

https://github.com/unity-plugins/google-play-game-service-unity-plugin/wiki/google--Play-Game-Service-unity-plugin-Tutorial