I'm not too sure if this question will get answered or not. But I just wanted to know. Is there anyway to turn the json file into a string for Google Cloud Services saving and then loading the string back into json to be used by the asset?
This is just something I thought of, not sure if it can be done.
Thank you.
Here is the script if it will help. The string to be saved is at the bottom.
Code: Select all
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('|');
debugText.text = data[0];
}
private void saveUpdate(SavedGameRequestStatus status, ISavedGameMetadata meta)
{
//Debug
debugText.text = "Successfully added data to cloud";
}
private string GetDataToStoreInCloud()
{
string Data = "";
Data += dataToCloud.text;
Data += "|";
return Data;
}