From ed98029a88cd89702980ac7c40b711afddc5aeb2 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期四, 20 十一月 2025 14:44:59 +0800
Subject: [PATCH] Merge branch 'master' of http://mobile.secondworld.net.cn:10010/r/Project_SG_scripts
---
Main/Config/ConfigBase.cs | 109 +++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 86 insertions(+), 23 deletions(-)
diff --git a/Main/Config/ConfigBase.cs b/Main/Config/ConfigBase.cs
index ea87401..e51fef1 100644
--- a/Main/Config/ConfigBase.cs
+++ b/Main/Config/ConfigBase.cs
@@ -1,55 +1,90 @@
using System.Collections.Generic;
using UnityEngine;
+using Cysharp.Threading.Tasks;
+using System.IO;
+using System;
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;
- protected static bool isInit = 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 List<T> GetValues()
+ // public static void ForceRelease()
+ // {
+ // m_dic.Clear();
+ // isInit = false;
+ // }
+
+ public static List<U> GetKeys()
{
- if (!isInit)
- {
- Debug.LogError(typeof(T).Name + " 娌℃湁鍒濆鍖� GetValues");
- return null; // 鎴栬�呮姏鍑哄紓甯革紝瑙嗘儏鍐佃�屽畾
- }
+ List<U> result = new List<U>();
+ result.AddRange(m_dic.Keys);
+ return result;
+ }
+
+
+ public static List<T> GetValues()
+ {
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)
{
- Dictionary<string, string> rawDatas = new Dictionary<string, string>();
+ if (isInit)
+ {
+ return;
+ }
for (int i = 3; i < lines.Length; i++)
{
@@ -64,8 +99,26 @@
T config = new T();
U key = config.LoadKey(strKey);
config.LoadConfig(line);
- dic.Add(key, config);
+ 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
}
+
+
+ // foreach (var cfg in m_dic.Values)
+ // {
+ // cfg.AllConfigLoadFinish();
+ // }
isInit = true;
}
@@ -75,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