40 lines
844 B
C#
40 lines
844 B
C#
using System.IO;
|
|
using UnityEngine;
|
|
|
|
[System.Serializable]
|
|
public class PreferenceData {
|
|
// Preference Fields
|
|
public int themeIndex;
|
|
public bool useLoopback;
|
|
|
|
// Others
|
|
string _path;
|
|
|
|
public PreferenceData(string path) {
|
|
_path = path;
|
|
themeIndex = 0;
|
|
useLoopback = true;
|
|
}
|
|
|
|
public PreferenceData Load() {
|
|
try {
|
|
string json = File.ReadAllText(_path);
|
|
JsonUtility.FromJsonOverwrite(json, this);
|
|
return this;
|
|
} catch {
|
|
// file doesn't exist yet
|
|
return Save();
|
|
}
|
|
}
|
|
|
|
public PreferenceData Save() {
|
|
File.WriteAllText(_path, JsonUtility.ToJson(this));
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public interface IPreferenceData {
|
|
PreferenceData LoadPreferences();
|
|
PreferenceData SavePreferences();
|
|
}
|