hch
2025-07-16 305cf5f85998f47e1ae87ae965f9830b1352f130
Main/Config/ConfigBase.cs
@@ -7,7 +7,16 @@
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;
@@ -15,12 +24,18 @@
    {
        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,7 +47,7 @@
    {
        LazyInit();
        List<U> result = new List<U>();
        result.AddRange(dic.Keys);
        result.AddRange(m_dic.Keys);
        return result;
    }
@@ -41,7 +56,7 @@
    {
        LazyInit();
        List<T> result = new List<T>();
        result.AddRange(dic.Values);
        result.AddRange(m_dic.Values);
        return result;
    }
@@ -49,7 +64,7 @@
    {
        LazyInit();
        return dic.ContainsKey(key);
        return m_dic.ContainsKey(key);
    }
    public static void LazyInit()
@@ -63,37 +78,41 @@
    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)
            {
                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
                dic.Add(key, config);
#if UNITY_EDITOR
            }
            catch (ArgumentException exception)
            {
                Debug.LogError(typeof(T).Name + " 重复的key " + key + " " + exception.Message);
            }
#endif
            Debug.LogError("重复加载表格  类型 " + typeof(T).Name);
            return;
        }
        foreach (var cfg in dic.Values)
        for (int i = 3; i < lines.Length; i++)
            {
                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 + " 重复的key " + key + " " + exception.Message);
                }
#endif
            }
        foreach (var cfg in m_dic.Values)
        {
            cfg.AllConfigLoadFinish();
        }