Example #1
0
        public void SaveData()
        {
            Debug.Log("Saving...");

            SaveFileWrapper wrapper = new SaveFileWrapper();

            wrapper.data = data;

            string contents = JsonUtility.ToJson(wrapper, true);

            File.WriteAllText(path, contents);
            Debug.Log("Saved!");
        }
Example #2
0
 public void ReadData()                  // This needs to be called when changing scenes
 {
     try
     {                                   // Checks if data is tampered
         if (File.Exists(path))          // Checks if data is lost
         {
             string          contents = File.ReadAllText(path);
             SaveFileWrapper wrapper  = JsonUtility.FromJson <SaveFileWrapper>(contents);
             data = wrapper.data;
             Debug.Log("reading");
         }
         else
         {
             print("Unable to read game data. File does not exist. Creating new save file");
             data = new SaveFileData();
             SaveData();
         }
     }
     catch (System.Exception ex)
     {
         print(ex.Message);
     }
 }