You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

46 line
1.3 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace SUISSEngine
  5. {
  6. public abstract class SettingsObject<T> : ScriptableObject where T : SettingsObject<T>
  7. {
  8. public static T Instance
  9. {
  10. get
  11. {
  12. string name = typeof(T).Name;
  13. SettingsObject<T>._instance = (Resources.Load(name) as T);
  14. if (SettingsObject<T>._instance == null)
  15. {
  16. SettingsObject<T>._instance = ScriptableObject.CreateInstance<T>();
  17. SettingsObject<T>._instance.platformDependent = new PlatformDependentSettings(SettingsObject<T>._instance.GetKeys());
  18. }
  19. return SettingsObject<T>._instance;
  20. }
  21. }
  22. public abstract List<string> GetKeys();
  23. public string GetSetting(string key, string defaultValue = "")
  24. {
  25. string setting = this.platformDependent.GetSetting(key);
  26. if (string.IsNullOrEmpty(setting))
  27. {
  28. UnityEngine.Debug.LogWarning(string.Format("{0}: Returning default value ('{1}') for setting '{2}'.", base.GetType(), defaultValue, key));
  29. return defaultValue;
  30. }
  31. return setting;
  32. }
  33. private const string SettingsFolder = "Settings/Resources";
  34. private const string AssetExtension = ".asset";
  35. private static T _instance;
  36. public PlatformDependentSettings platformDependent;
  37. }
  38. }