Save file to Google Services Cloud

Discussion and help for Easy Save 3
Post Reply
GumballFight
Posts: 5
Joined: Tue Jul 14, 2020 7:13 pm

Save file to Google Services Cloud

Post by GumballFight »

Hello.

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;
    }
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Save file to Google Services Cloud

Post by Joel »

Hi there,

You can use the ES3.LoadRawString method to get a file as a string. There's information on integrating with external services here:

https://docs.moodkie.com/easy-save-3/es ... rage-apis/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
GumballFight
Posts: 5
Joined: Tue Jul 14, 2020 7:13 pm

Re: Save file to Google Services Cloud

Post by GumballFight »

Thank you Joel.
Post Reply