'Save multiple Variables with Google play games

I am currently setting up a wild system for a mobile game in unity thanks to the google play games plugin.

I have currently managed to save a value through the tutorial provided here: http://resocoder.com/2017/03/10/gpg-tutorial-saved-games-code/

But I can not manage to save a larger number of variables.

I would like according to the code above to be able to return not a float, but a table of value.

Someone would have an idea of how I can do it please? And if you do not know, would you be kind enough to explain to me how does the serialization or deserialization of data in tables [] byte?

Thank you



Solution 1:[1]

I know this is old question but, for the future this answer should be useful.

Unity have Json support hereafter UnityEngine.JSONSerializeModule. So we can keep a little more data with GPGS without 3rd party packages.

You can crate a class for your all data. (Thee deep of data length should less than 7 floor)

   using UnityEngine;
public class Try : MonoBehaviour
{
    string theDataWhichWillSendToCloud;
    public MyData saveJson;
    public void JsonToString()//BeforeSave
    {
        theDataWhichWillSendToCloud = JsonUtility.ToJson(saveJson);
    }
    public void StringToJson()//AfterLoad
    {
        saveJson = (MyData)JsonUtility.FromJson<MyData>(theDataWhichWillSendToCloud);
    }
}

[System.Serializable]
public class MyData
{
    [SerializeField] private float health;
    [SerializeField] private float money;
    public float Health { get { return health; } set { health = value; } }
    public float Money { get { return money; } set { money = value; } }
}

Finally when you want to save data, Call JsonToString() when you load, after the load re-set the data from string with StringToJson()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Heavy Dream