public void Save() { string path = filePath; if (Application.isEditor) { path += "/testSetups.dat"; } else { path += "/setups.dat"; } // convert dictionary to save glob SetupListGlob saveGlob = new SetupListGlob(SetupList()); BinaryFormatter bf = new BinaryFormatter(); using (FileStream file = File.Create(path)) { bf.Serialize(file, saveGlob.data); } HasUnsavedData = false; }
public void Load() { string path = filePath; if (Application.isEditor) { path += "/testSetups.dat"; } else { path += "/setups.dat"; } // File exists if (File.Exists(path)) { using (FileStream file = File.Open(path, FileMode.Open)) { // Make sure file isn't empty if (file.Length != 0) { BinaryFormatter bf = new BinaryFormatter(); // Deserialize SetupListGlob loadGlob = new SetupListGlob(); loadGlob.data = (List <SetupSaveGlob>)bf.Deserialize(file); Setup setup; foreach (SetupSaveGlob save in loadGlob.data) { setup = new Setup(save, CacheManager.SetupTab.Setup.Player); Add(setup.SetupName, setup); } } } Debug.Log($"Setups loaded from file"); } // File doesn't exist else { using (FileStream file = File.Create(path)) { } Debug.Log("Setups file created"); } // Add a default setup if there are none if (setupDictionary.Count == 0) { Debug.Log("Adding default setup"); setupDictionary.Add("Default", new Setup("Default", CacheManager.SetupTab.Setup.Player)); } }