2using System.Collections.Generic;
15 public class TriLibSettings : ScriptableObject, ISerializationCallbackReceiver
17 private Dictionary<string, bool> _boolPreferences;
20 private List<string> _boolKeys;
23 private List<bool> _boolValues;
27 var preferencesFiles = Resources.LoadAll<
TriLibSettings>(
string.Empty);
29 if (preferencesFiles.Length == 0)
32 var triLibDirectories = AssetDatabase.FindAssets(
"TriLibMainFolderPlaceholder");
33 var triLibDirectory = triLibDirectories.Length > 0 ? FileUtils.GetFileDirectory(AssetDatabase.GUIDToAssetPath(triLibDirectories[0])) :
"";
34 triLibSettings = CreateInstance<TriLibSettings>();
35 AssetDatabase.CreateAsset(triLibSettings, $
"{triLibDirectory}/TriLibSettings.asset");
36 AssetDatabase.SaveAssets();
38 throw new Exception(
"Could not find TriLib preferences file.");
43 if (preferencesFiles.Length > 1)
45 Debug.LogWarning(
"There is more than one TriLibSettings asset, and there is only one allowed per project.");
47 triLibSettings = preferencesFiles[0];
49 return triLibSettings;
52 public Dictionary<string, bool>.Enumerator
GetKvp()
54 return _boolPreferences.GetEnumerator();
59 var triLibPreferences = GetTriLibPreferences();
60 if (triLibPreferences._boolPreferences ==
null || !triLibPreferences._boolPreferences.TryGetValue(key, out var value))
67 public static void SetBool(
string key,
bool value)
69 var triLibPreferences = GetTriLibPreferences();
70 if (triLibPreferences._boolPreferences ==
null)
72 triLibPreferences._boolPreferences =
new Dictionary<string, bool>();
74 triLibPreferences._boolPreferences[key] = value;
76 if (Application.isPlaying)
78 Debug.LogWarning(
"Can't save TriLib settings while in play mode. Please refer to the Project Settings/TriLib area.");
80 EditorUtility.SetDirty(triLibPreferences);
81 AssetDatabase.SaveAssets();
82 AssetDatabase.Refresh();
88 if (_boolPreferences ==
null)
92 if (_boolKeys ==
null || _boolValues ==
null)
94 _boolKeys =
new List<string>();
95 _boolValues =
new List<bool>();
99 foreach (var kvp
in _boolPreferences)
101 _boolKeys.Add(kvp.Key);
102 _boolValues.Add(kvp.Value);
108 if (_boolKeys ==
null || _boolValues ==
null)
112 if (_boolPreferences ==
null)
114 _boolPreferences =
new Dictionary<string, bool>();
116 _boolPreferences.Clear();
117 for (var i = 0; i < _boolKeys.Count; i++)
119 _boolPreferences.Add(_boolKeys[i], _boolValues[i]);
Represents the TriLib project settings provider. You can override this behavior to store the settings...
Dictionary< string, bool >.Enumerator GetKvp()
static void SetBool(string key, bool value)
static bool GetBool(string key)
void OnAfterDeserialize()