From 485db99b5c51a971c173664cf6e808dc8424b0a0 Mon Sep 17 00:00:00 2001
From: lcy <1459594991@qq.com>
Date: 星期五, 17 十月 2025 17:19:51 +0800
Subject: [PATCH] 136 子 【挑战】战锤秘境 / 【挑战】战锤秘境-客户端 移除错误接入
---
Main/Config/ConfigBase.cs | 134 +++++++++++++++++++++++++++++---------------
1 files changed, 88 insertions(+), 46 deletions(-)
diff --git a/Main/Config/ConfigBase.cs b/Main/Config/ConfigBase.cs
index 41f3c51..14a45c5 100644
--- a/Main/Config/ConfigBase.cs
+++ b/Main/Config/ConfigBase.cs
@@ -7,84 +7,116 @@
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 ConfigBase()
+ {
+ if (isInit)
+ {
+ return;
+ }
+
+ LazyInit();
+ }
+
+ 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)
{
+ 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)
+ 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 +127,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