private static void SaveSettingsAsBinary(SettingsOptions options, string subPath) { var binaryFormatter = new BinaryFormatter(); var fullPath = Path.Combine(Application.persistentDataPath, subPath); using var streamWriter = File.Open(fullPath, FileMode.OpenOrCreate); binaryFormatter.Serialize(streamWriter, options); }
public static void SaveSettings(SettingsOptions options, string subPath) { #if UNITY_EDITOR SaveSettingsAsJson(options, subPath); #else SaveSettingsAsBinary(options, subPath); #endif }
private static void SaveSettingsAsJson(SettingsOptions options, string subPath) { var jsonString = JsonUtility.ToJson(options); var fullPath = Path.Combine(Application.persistentDataPath, subPath); using var streamWriter = File.CreateText(fullPath); streamWriter.Write(jsonString); }
private void Awake() { SettingsOptions _settingsOptions; #if UNITY_EDITOR _settingsOptions = LoadSettings(PATH); #else _settingsOptions = LoadSettings(BIN_PATH); #endif if (_settingsOptions != null) { settingsOptions = _settingsOptions; } else { var newSettings = new SettingsOptions(); settingsOptions = newSettings; } }