- Home /
Play Services Cloud saving help.
Hello,
It doesn't look like there much recent help on this. I've started looking into Google Play Services. I've got to the point where I can have the user/player login to their Google play account, deal with achievements and so on without any issue now.
I am really struggling with the cloud saving. I have gotten it to work but it doesn't seem like it's the best way.
private bool isSaving = false;
private string SAVE_NAME = "mainSaveFile";
public Text debugText;
[SerializeField] InputField dataToCloud;
public void openSaveToCloud(bool saving)
{
if (Social.localUser.authenticated)
{
isSaving = saving;
((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution(SAVE_NAME, GooglePlayGames.BasicApi.DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, savedgameopen);
}
}
private void savedgameopen(SavedGameRequestStatus status, ISavedGameMetadata meta)
{
if (status == SavedGameRequestStatus.Success)
{
if (isSaving)
{
byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(GetDataToStoreInCloud());
SavedGameMetadataUpdate update = new SavedGameMetadataUpdate.Builder().Build();
((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(meta, update, data, saveUpdate);
}
else
{
((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(meta, ReadDataFromCloud);
}
}
}
private void ReadDataFromCloud(SavedGameRequestStatus status, byte[] data)
{
if (status == SavedGameRequestStatus.Success)
{
string saveData = System.Text.ASCIIEncoding.ASCII.GetString(data);
LoadDataFromCloudToGame(saveData);
}
}
private void LoadDataFromCloudToGame(string saveData)
{
string[] data = saveData.Split('|');
GetComponent<InterstitialAdExample>().ads = data[0];
}
private void saveUpdate(SavedGameRequestStatus status, ISavedGameMetadata meta)
{
//Debug
debugText.text = "Successfully added data to cloud";
}
private string GetDataToStoreInCloud()
{
string Data = "";
Data += "string To Save";
Data += "|";
return Data;
}
It does work but it feels like it would become very messy after awhile when having to save hitpoints, NPC's positions, NPC's hitpoints, and so on.
So I think the following would start to look like
private string GetDataToStoreInCloud()
{
string Data = "";
Data += "string To Save";
Data += "|";
Data += "another thing to save";
Data += "|";
Data += "another";
Data += "|";
return Data;
}
and so on.
I would use
string[] data = saveData.Split('|');
dataNeeded = Data[0];
to then get the data needed.
Is this nonsense?
Your answer
Follow this Question
Related Questions
Is the Cloud Build API key machine specific? 0 Answers
What API does Unity use to start UnityCrashHandler.exe 0 Answers
One save for a free and premium version of the game on iOS 0 Answers
YAML support? 3 Answers
Can you save a user's in-game currency using google play cloud save? Is it a good idea to do so? 1 Answer