|
- using System;
- using System.Collections.Generic;
- using UnityEngine;
-
- namespace SUISSEngine
- {
- public abstract class SettingsObject<T> : ScriptableObject where T : SettingsObject<T>
- {
- public static T Instance
- {
- get
- {
- string name = typeof(T).Name;
- SettingsObject<T>._instance = (Resources.Load(name) as T);
- if (SettingsObject<T>._instance == null)
- {
- SettingsObject<T>._instance = ScriptableObject.CreateInstance<T>();
- SettingsObject<T>._instance.platformDependent = new PlatformDependentSettings(SettingsObject<T>._instance.GetKeys());
- }
- return SettingsObject<T>._instance;
- }
- }
-
- public abstract List<string> GetKeys();
-
- public string GetSetting(string key, string defaultValue = "")
- {
- string setting = this.platformDependent.GetSetting(key);
- if (string.IsNullOrEmpty(setting))
- {
- UnityEngine.Debug.LogWarning(string.Format("{0}: Returning default value ('{1}') for setting '{2}'.", base.GetType(), defaultValue, key));
- return defaultValue;
- }
- return setting;
- }
-
- private const string SettingsFolder = "Settings/Resources";
-
- private const string AssetExtension = ".asset";
-
- private static T _instance;
-
- public PlatformDependentSettings platformDependent;
- }
- }
|