From 7677bf7ab5f15f55b7e1366f1601e541a9a31f4d Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期三, 16 七月 2025 16:30:09 +0800
Subject: [PATCH] 0312 界面层级
---
Main/Config/ConfigBase.cs | 126 +++++++++++++++++++++++++++--------------
1 files changed, 83 insertions(+), 43 deletions(-)
diff --git a/Main/Config/ConfigBase.cs b/Main/Config/ConfigBase.cs
index 41f3c51..93f9299 100644
--- a/Main/Config/ConfigBase.cs
+++ b/Main/Config/ConfigBase.cs
@@ -7,24 +7,35 @@
public class ConfigBase<U, T> where T : ConfigBase<U, T>, new()
{
- public static Dictionary<U, T> dic = new Dictionary<U, T>();
+ private static Dictionary<U, T> m_dic = new Dictionary<U, T>();
+
+ public static Dictionary<U, T> dic
+ {
+ get
+ {
+ LazyInit();
+ return m_dic;
+ }
+ }
public static bool isInit = false;
public static T Get(U id)
{
- if (!isInit)
- {
- Debug.LogError("ConfigBase 娌℃湁鍒濆鍖�");
- return null; // 鎴栬�呮姏鍑哄紓甯革紝瑙嗘儏鍐佃�屽畾
- }
+ LazyInit();
- if (dic.ContainsKey(id))
+ if (m_dic.ContainsKey(id))
{
- return dic[id];
+ return m_dic[id];
}
return null;
+ }
+
+ public static void ForceRelease()
+ {
+ m_dic.Clear();
+ isInit = false;
}
public static void ForceInit()
@@ -32,59 +43,78 @@
ConfigManager.Instance.LoadConfigByType(typeof(T));
}
- public List<T> GetValues()
+ public static List<U> GetKeys()
{
- if (!isInit)
- {
- Debug.LogError(typeof(T).Name + " 娌℃湁鍒濆鍖� GetValues");
- return null; // 鎴栬�呮姏鍑哄紓甯革紝瑙嗘儏鍐佃�屽畾
- }
+ LazyInit();
+ List<U> result = new List<U>();
+ result.AddRange(m_dic.Keys);
+ return result;
+ }
+
+
+ public static List<T> GetValues()
+ {
+ LazyInit();
List<T> result = new List<T>();
- result.AddRange(dic.Values);
+ result.AddRange(m_dic.Values);
return result;
}
public static bool HasKey(U key)
{
+ LazyInit();
+
+ return m_dic.ContainsKey(key);
+ }
+
+ public static void LazyInit()
+ {
if (!isInit)
{
- Debug.LogError(typeof(T).Name + " 娌℃湁鍒濆鍖� HasKey");
- return false; // 鎴栬�呮姏鍑哄紓甯革紝瑙嗘儏鍐佃�屽畾
+ // 瀹為檯涓婃槸鍚屾鐨�
+ ConfigManager.Instance.LoadConfigByType(typeof(T));
}
-
- return dic.ContainsKey(key);
}
public static void Init(string[] lines)
{
- dic.Clear();
-
- for (int i = 3; i < lines.Length; i++)
+ if (isInit)
{
- string line = lines[i];
- var index = line.IndexOf("\t");
- if (index == -1)
+ Debug.LogError("閲嶅鍔犺浇琛ㄦ牸 绫诲瀷 " + typeof(T).Name);
+ return;
+ }
+
+ for (int i = 3; i < lines.Length; i++)
{
- continue;
+ string line = lines[i];
+ var index = line.IndexOf("\t");
+ if (index == -1)
+ {
+ continue;
+ }
+
+ string strKey = line.Substring(0, index);
+ T config = new T();
+ U key = config.LoadKey(strKey);
+ config.LoadConfig(line);
+ config.OnConfigParseCompleted();
+#if UNITY_EDITOR
+ try
+ {
+#endif
+ m_dic.Add(key, config);
+#if UNITY_EDITOR
+ }
+ catch (ArgumentException exception)
+ {
+ Debug.LogError(typeof(T).Name + " 閲嶅鐨刱ey " + key + " " + exception.Message);
+ }
+#endif
}
- string strKey = line.Substring(0, index);
- T config = new T();
- U key = config.LoadKey(strKey);
- config.LoadConfig(line);
- #if UNITY_EDITOR
- try
- {
- #endif
- dic.Add(key, config);
- #if UNITY_EDITOR
- }
- catch (ArgumentException exception)
- {
- Debug.LogError(typeof(T).Name + " 閲嶅鐨刱ey " + key + " " + exception.Message);
- }
- #endif
-
+ foreach (var cfg in m_dic.Values)
+ {
+ cfg.AllConfigLoadFinish();
}
isInit = true;
@@ -95,10 +125,20 @@
return default(U);
}
+ protected virtual void AllConfigLoadFinish()
+ {
+
+ }
+
public virtual void LoadConfig(string line)
{
}
+
+ protected virtual void OnConfigParseCompleted()
+ {
+
+ }
protected int ParseInt(string str)
{
--
Gitblit v1.8.0