yyl
2025-06-23 4fde46699701b1a8b74b4dab516624852b24a86d
Main/Config/ConfigBase.cs
@@ -27,7 +27,25 @@
        return null;
    }
    public List<T> GetValues()
    public static void ForceInit()
    {
        ConfigManager.Instance.LoadConfigByType(typeof(T));
    }
    public static List<U> GetKeys()
    {
        if (!isInit)
        {
            Debug.LogError(typeof(U).Name + " 没有初始化 GetKeys");
            return null; // 或者抛出异常,视情况而定
        }
        List<U> result = new List<U>();
        result.AddRange(dic.Keys);
        return result;
    }
    public static List<T> GetValues()
    {
        if (!isInit)
        {
@@ -52,8 +70,8 @@
    public static void Init(string[] lines)
    {
        Dictionary<string, string> rawDatas = new Dictionary<string, string>();
        dic.Clear();
        for (int i = 3; i < lines.Length; i++)
        {
            string line = lines[i];
@@ -67,7 +85,24 @@
            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
        }
        foreach (var cfg in dic.Values)
        {
            cfg.AllConfigLoadFinish();
        }
        isInit = true;
@@ -78,10 +113,20 @@
        return default(U);
    }
    protected virtual void AllConfigLoadFinish()
    {
    }
    public virtual void LoadConfig(string line)
    {
        
    }
    protected virtual void OnConfigParseCompleted()
    {
    }
    
    protected int ParseInt(string str)
    {