private GoSettingsSave CreateSave() { GoSettingsSave save = new GoSettingsSave(); LogManager.Log(this, LogContexts.Saves, "Start create save."); // Int { foreach (int id in m_IntSettings.Keys) { int value = m_IntSettings[id]; save.AddInt(id, value); LogManager.Log(this, LogContexts.Saves, "(int) " + id + " --> " + value); } } // Float { foreach (int id in m_FloatSettings.Keys) { float value = m_FloatSettings[id]; save.AddFloat(id, value); LogManager.Log(this, LogContexts.Saves, "(float) " + id + " --> " + value); } } // Bool { foreach (int id in m_BoolSettings.Keys) { bool value = m_BoolSettings[id]; save.AddBool(id, value); LogManager.Log(this, LogContexts.Saves, "(bool) " + id + " --> " + value); } } // String { foreach (int id in m_StringSettings.Keys) { string value = m_StringSettings[id]; save.AddString(id, value); LogManager.Log(this, LogContexts.Saves, "(string) " + id + " --> " + value); } } LogManager.Log(this, LogContexts.Saves, "Save created."); return(save); }
private void InternalSave() { GoSettingsSave save = CreateSave(); string filePath = Application.persistentDataPath + "/Settings.sav"; BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(filePath); LogManager.Log(this, LogContexts.Saves, "File created at '" + filePath + "'. The saved will be writed."); bf.Serialize(file, save); file.Close(); }
private void ApplyState(GoSettingsSave i_Save) { LogManager.Log(this, LogContexts.Saves, "Start load save."); ClearAll(); if (i_Save == null) { return; } for (int index = 0; index < i_Save.settingsCount; ++index) { GoSetting setting = i_Save.GetSetting(index); if (setting == null) { continue; } int id = setting.id; switch (setting.type) { case SettingType.Bool: SetBool(id, setting.boolValue); LogManager.Log(this, LogContexts.Saves, "Loaded: (bool)" + id + " --> " + setting.boolValue); break; case SettingType.Float: SetFloat(id, setting.floatValue); LogManager.Log(this, LogContexts.Saves, "Loaded: (float)" + id + " --> " + setting.floatValue); break; case SettingType.Int: SetInt(id, setting.intValue); LogManager.Log(this, LogContexts.Saves, "Loaded: (int)" + id + " --> " + setting.intValue); break; case SettingType.String: SetString(id, setting.stringValue); LogManager.Log(this, LogContexts.Saves, "Loaded: (string)" + id + " --> " + setting.stringValue); break; } } LogManager.Log(this, LogContexts.Saves, "Save loaded."); }
private void InternalLoad() { GoSettingsSave save = null; string filePath = Application.persistentDataPath + "/Settings.sav"; if (File.Exists(Application.persistentDataPath + "/Settings.sav")) { LogManager.Log(this, LogContexts.Saves, "Found file at '" + filePath + "'. The file will be loaded."); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(filePath, FileMode.Open); save = (GoSettingsSave)bf.Deserialize(file); file.Close(); } else { LogManager.Log(this, LogContexts.Saves, "Cannot load from '" + filePath + "'. File not found."); } ApplyState(save); }