| namespace UnityEditor.SettingsManagement |
| { |
| |
| |
| |
| public class UserSettingsRepository : ISettingsRepository |
| { |
| static string GetEditorPrefKey<T>(string key) |
| { |
| return GetEditorPrefKey(typeof(T).FullName, key); |
| } |
|
|
| static string GetEditorPrefKey(string fullName, string key) |
| { |
| return fullName + "::" + key; |
| } |
|
|
| static void SetEditorPref<T>(string key, T value) |
| { |
| var k = GetEditorPrefKey<T>(key); |
|
|
| if (typeof(T) == typeof(string)) |
| EditorPrefs.SetString(k, (string)(object)value); |
| else if (typeof(T) == typeof(bool)) |
| EditorPrefs.SetBool(k, (bool)(object)value); |
| else if (typeof(T) == typeof(float)) |
| EditorPrefs.SetFloat(k, (float)(object)value); |
| else if (typeof(T) == typeof(int)) |
| EditorPrefs.SetInt(k, (int)(object)value); |
| else |
| EditorPrefs.SetString(k, ValueWrapper<T>.Serialize(value)); |
| } |
|
|
| static T GetEditorPref<T>(string key, T fallback = default(T)) |
| { |
| var k = GetEditorPrefKey<T>(key); |
|
|
| if (!EditorPrefs.HasKey(k)) |
| return fallback; |
|
|
| var o = (object)fallback; |
|
|
| if (typeof(T) == typeof(string)) |
| o = EditorPrefs.GetString(k, (string)o); |
| else if (typeof(T) == typeof(bool)) |
| o = EditorPrefs.GetBool(k, (bool)o); |
| else if (typeof(T) == typeof(float)) |
| o = EditorPrefs.GetFloat(k, (float)o); |
| else if (typeof(T) == typeof(int)) |
| o = EditorPrefs.GetInt(k, (int)o); |
| else |
| return ValueWrapper<T>.Deserialize(EditorPrefs.GetString(k)); |
|
|
| return (T)o; |
| } |
|
|
| |
| |
| |
| |
| public SettingsScope scope |
| { |
| get { return SettingsScope.User; } |
| } |
|
|
| |
| |
| |
| public string name |
| { |
| get { return "EditorPrefs"; } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public string path |
| { |
| get { return string.Empty; } |
| } |
|
|
| |
| |
| |
| |
| public void Save() |
| { |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public void Set<T>(string key, T value) |
| { |
| SetEditorPref<T>(key, value); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public T Get<T>(string key, T fallback = default(T)) |
| { |
| return GetEditorPref<T>(key, fallback); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public bool ContainsKey<T>(string key) |
| { |
| return EditorPrefs.HasKey(GetEditorPrefKey<T>(key)); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public void Remove<T>(string key) |
| { |
| EditorPrefs.DeleteKey(GetEditorPrefKey<T>(key)); |
| } |
| } |
| } |
|
|