MySettingsManager.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using UnityEditor.SettingsManagement;
  2. namespace UnityEditor.SettingsManagement.Examples
  3. {
  4. /// <summary>
  5. /// This class will act as a manager for the <see cref="Settings"/> singleton.
  6. /// </summary>
  7. static class MySettingsManager
  8. {
  9. // Replace this with your own package name. Project settings will be stored in a JSON file in a directory matching
  10. // this name.
  11. internal const string k_PackageName = "com.unity.settings-manager-examples";
  12. static Settings s_Instance;
  13. internal static Settings instance
  14. {
  15. get
  16. {
  17. if (s_Instance == null)
  18. s_Instance = new Settings(k_PackageName);
  19. return s_Instance;
  20. }
  21. }
  22. // The rest of this file is just forwarding the various setting methods to the instance.
  23. public static void Save()
  24. {
  25. instance.Save();
  26. }
  27. public static T Get<T>(string key, SettingsScope scope = SettingsScope.Project, T fallback = default(T))
  28. {
  29. return instance.Get<T>(key, scope, fallback);
  30. }
  31. public static void Set<T>(string key, T value, SettingsScope scope = SettingsScope.Project)
  32. {
  33. instance.Set<T>(key, value, scope);
  34. }
  35. public static bool ContainsKey<T>(string key, SettingsScope scope = SettingsScope.Project)
  36. {
  37. return instance.ContainsKey<T>(key, scope);
  38. }
  39. }
  40. }