Example #1
0
    // Update is called once per frame
    public void LoadSaveFromFile()
    {
        if (File.Exists(Application.persistentDataPath + "/gamesave.sav"))
        {
            //BinaryFormatter bf = new BinaryFormatter();
            //FileStream file = File.Open(Application.persistentDataPath + "/gamesave.sav", FileMode.Open);
            //SaveObject oldSave = (SaveObject)bf.Deserialize(file);
            //stats.LoadFromSaveObject(oldSave);
            //file.Close();

            string     json    = File.ReadAllText(Application.persistentDataPath + "/gamesave.sav");
            SaveObject oldSave = JsonUtility.FromJson <SaveObject>(json);
            stats.LoadFromSaveObject(oldSave);
            Debug.Log("Loaded game from " + Application.persistentDataPath + "/gamesave.sav");
            return;
        }

        else
        {
            Debug.LogWarning("Load Failed! File does not exist.");
        }
    }