Exemplo n.º 1
0
    // Saves the object of generic type <T> as the file of the name of enum SaveFileName.Whatever
    public static void Save(T myObject, SaveFileName saveFileName)
    {
        string json = JsonUtility.ToJson(myObject);

        PlayerPrefs.SetString(saveFileName.ToString(), json);
        PlayerPrefs.Save();
    }
Exemplo n.º 2
0
    // Loads the json with the name of enum SaveFileName.Whatever converts it back to the object type <T> and returns it as an object of type <T>
    public static T Load(SaveFileName saveFileName)
    {
        string json = PlayerPrefs.GetString(saveFileName.ToString());

        return(JsonUtility.FromJson <T>(json));
    }