コード例 #1
0
        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);
        }
コード例 #2
0
        public static void SaveSettings(SettingsOptions options, string subPath)
        {
#if UNITY_EDITOR
            SaveSettingsAsJson(options, subPath);
#else
            SaveSettingsAsBinary(options, subPath);
#endif
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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;
            }
        }