| | |
| | |
|
| | | public static T Get(U id)
|
| | | {
|
| | | if (!isInit)
|
| | | {
|
| | | Debug.LogError("ConfigBase 没有初始化");
|
| | | return null; // 或者抛出异常,视情况而定
|
| | | }
|
| | | LazyInit();
|
| | |
|
| | | if (dic.ContainsKey(id))
|
| | | {
|
| | |
| | |
|
| | | public static List<U> GetKeys()
|
| | | {
|
| | | if (!isInit)
|
| | | {
|
| | | Debug.LogError(typeof(U).Name + " 没有初始化 GetKeys");
|
| | | return null; // 或者抛出异常,视情况而定
|
| | | }
|
| | | LazyInit();
|
| | | List<U> result = new List<U>();
|
| | | result.AddRange(dic.Keys);
|
| | | return result;
|
| | |
| | |
|
| | | public static List<T> GetValues()
|
| | | {
|
| | | if (!isInit)
|
| | | {
|
| | | Debug.LogError(typeof(T).Name + " 没有初始化 GetValues");
|
| | | return null; // 或者抛出异常,视情况而定
|
| | | }
|
| | | LazyInit();
|
| | | List<T> result = new List<T>();
|
| | | result.AddRange(dic.Values);
|
| | | return result;
|
| | |
| | |
|
| | | public static bool HasKey(U key)
|
| | | {
|
| | | if (!isInit)
|
| | | {
|
| | | Debug.LogError(typeof(T).Name + " 没有初始化 HasKey");
|
| | | return false; // 或者抛出异常,视情况而定
|
| | | }
|
| | | LazyInit();
|
| | |
|
| | | return dic.ContainsKey(key);
|
| | | }
|
| | |
|
| | | public static void LazyInit()
|
| | | {
|
| | | if (!isInit)
|
| | | {
|
| | | // 实际上是同步的
|
| | | ConfigManager.Instance.LoadConfigByType(typeof(T));
|
| | | }
|
| | | }
|
| | |
|
| | | public static void Init(string[] lines)
|
| | | {
|
| | | dic.Clear();
|
| | | |
| | |
|
| | | for (int i = 3; i < lines.Length; i++)
|
| | | {
|
| | | string line = lines[i];
|
| | |
| | | U key = config.LoadKey(strKey);
|
| | | config.LoadConfig(line);
|
| | | config.OnConfigParseCompleted();
|
| | | #if UNITY_EDITOR
|
| | | #if UNITY_EDITOR
|
| | | try
|
| | | {
|
| | | #endif
|
| | | dic.Add(key, config);
|
| | | #if UNITY_EDITOR
|
| | | #endif
|
| | | dic.Add(key, config);
|
| | | #if UNITY_EDITOR
|
| | | }
|
| | | catch (ArgumentException exception)
|
| | | {
|
| | | Debug.LogError(typeof(T).Name + " 重复的key " + key + " " + exception.Message);
|
| | | Debug.LogError(typeof(T).Name + " 重复的key " + key + " " + exception.Message);
|
| | | }
|
| | | #endif
|
| | | #endif
|
| | | }
|
| | |
|
| | | foreach (var cfg in dic.Values)
|