From 51b0f6ed9f4e1d3bb6f8144470b46908c7699a96 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期一, 11 五月 2026 16:20:37 +0800
Subject: [PATCH] Merge branch 'master' into h5version
---
Main/Config/ConfigBase.cs | 113 +++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 78 insertions(+), 35 deletions(-)
diff --git a/Main/Config/ConfigBase.cs b/Main/Config/ConfigBase.cs
index 41f3c51..04098ed 100644
--- a/Main/Config/ConfigBase.cs
+++ b/Main/Config/ConfigBase.cs
@@ -7,85 +7,118 @@
public class ConfigBase<U, T> where T : ConfigBase<U, T>, new()
{
- public static Dictionary<U, T> dic = new Dictionary<U, T>();
+ /// <summary>
+ /// 鏄惁璁块棶杩囬潤鎬佹瀯閫犲嚱鏁�
+ /// </summary>
+ public static bool visit = false;
+
+ // 绉婚櫎闈欐�佹瀯閫犲嚱鏁颁腑鐨勫悓姝ユ噿鍔犺浇锛岀姝㈠悓姝ラ樆濉�
+ // static鏋勯�犲嚱鏁颁笉鍐嶈Е鍙慙azyInit
+
+ private static Dictionary<U, T> m_dic = new Dictionary<U, T>();
+
+ public static Dictionary<U, T> dic
+ {
+ get
+ {
+ return m_dic;
+ }
+ }
public static bool isInit = false;
public static T Get(U id)
{
- if (!isInit)
+ if (m_dic.ContainsKey(id))
{
- Debug.LogError("ConfigBase 娌℃湁鍒濆鍖�");
- return null; // 鎴栬�呮姏鍑哄紓甯革紝瑙嗘儏鍐佃�屽畾
- }
-
- if (dic.ContainsKey(id))
- {
- return dic[id];
+ return m_dic[id];
}
return null;
}
- public static void ForceInit()
+ // public static void ForceRelease()
+ // {
+ // m_dic.Clear();
+ // isInit = false;
+ // }
+
+ public static List<U> GetKeys()
{
- ConfigManager.Instance.LoadConfigByType(typeof(T));
+ List<U> result = new List<U>();
+ result.AddRange(m_dic.Keys);
+ return result;
}
- public List<T> GetValues()
+
+ public static List<T> GetValues()
{
- if (!isInit)
- {
- Debug.LogError(typeof(T).Name + " 娌℃湁鍒濆鍖� GetValues");
- return null; // 鎴栬�呮姏鍑哄紓甯革紝瑙嗘儏鍐佃�屽畾
- }
List<T> result = new List<T>();
- result.AddRange(dic.Values);
+ result.AddRange(m_dic.Values);
return result;
}
public static bool HasKey(U key)
{
- if (!isInit)
- {
- Debug.LogError(typeof(T).Name + " 娌℃湁鍒濆鍖� HasKey");
- return false; // 鎴栬�呮姏鍑哄紓甯革紝瑙嗘儏鍐佃�屽畾
- }
-
- return dic.ContainsKey(key);
+ return m_dic.ContainsKey(key);
}
+ // 寮傛鎳掑姞杞藉叆鍙�
+ public static async UniTask LazyInitAsync()
+ {
+ if (!isInit)
+ {
+ await ConfigManager.Instance.LoadConfigByTypeAsync(typeof(T));
+ }
+ }
+
+ // 鍚屾鍒濆鍖�
public static void Init(string[] lines)
{
- dic.Clear();
-
+ if (isInit)
+ {
+ return;
+ }
+
for (int i = 3; i < lines.Length; i++)
{
string line = lines[i];
+
+ // 璺宠繃绌鸿
+ if (string.IsNullOrEmpty(line))
+ continue;
+
var index = line.IndexOf("\t");
if (index == -1)
{
- continue;
+ string result = line.Trim();
+ index = result.Length;
}
string strKey = line.Substring(0, index);
T config = new T();
U key = config.LoadKey(strKey);
config.LoadConfig(line);
- #if UNITY_EDITOR
+ config.OnConfigParseCompleted();
+#if UNITY_EDITOR
try
{
- #endif
- dic.Add(key, config);
- #if UNITY_EDITOR
+#endif
+ m_dic.Add(key, config);
+#if UNITY_EDITOR
}
catch (ArgumentException exception)
{
- Debug.LogError(typeof(T).Name + " 閲嶅鐨刱ey " + key + " " + exception.Message);
+ Debug.LogError(typeof(T).Name + " 閲嶅鐨刱ey " + key + " " + exception.Message);
}
- #endif
-
+#endif
}
+
+ // foreach (var cfg in m_dic.Values)
+ // {
+ // cfg.AllConfigLoadFinish();
+ // }
+ // Debug.LogError("config " + typeof(T).Name + " load finish! total count:" + m_dic.Count);
isInit = true;
}
@@ -95,10 +128,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