yyl
2025-05-08 a48ae9384860a71264b88bfa4810c896270e9e0a
config loading
3个文件已修改
52 ■■■■■ 已修改文件
Main/Config/ConfigBase.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/Manager/ConfigManager.cs 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/Manager/StageManager.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/Config/ConfigBase.cs
@@ -134,7 +134,7 @@
        }
        else
        {
            Debug.LogError("GetKey 类型错误");
            Debug.LogError("GetKey 意外的key类型 类型错误 " + typeof(U).Name);
            return default(U);
        }
    }
Main/Manager/ConfigManager.cs
@@ -13,6 +13,14 @@
        private set;
    }
    private float loadingProgress = 0f;
    public override void Init()
    {
        base.Init();
        InitConfigs();
    }
    public virtual async UniTask InitConfigs()
    {
        // 加载配置文件
@@ -21,13 +29,46 @@
    protected async UniTask LoadConfigs()
    {
        loadingProgress = 0f;
        isLoadFinished = false;
        // 加载配置文件
        // 加载完成后设置isLoadFinished为true
        loadingProgress = 1f;
        isLoadFinished = true;
    }
    private async UniTask LoadConfigByType(Type configType)
    {
        string configName = configType.Name;
        TextAsset textAsset = await ResManager.Instance.LoadAsset<TextAsset>("Config", configName);
        if (textAsset != null)
        {
            string[] lines = textAsset.text.Split('\n');
            var methodInfo = configType.GetMethod("Init", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
            if (methodInfo != null)
            {
                methodInfo.Invoke(null, new object[] { lines });
                // 设置初始化标志
                var isInitField = configType.GetField("isInit", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
                if (isInitField != null)
                {
                    isInitField.SetValue(null, true);
                }
                Debug.Log($"加载配置: {configType.Name} 成功");
            }
            else
            {
                Debug.LogError($"配置类 {configType.Name} 没有静态Init方法");
            }
        }
        else
        {
            Debug.LogError($"找不到配置文件: {configName}");
        }
    }
@@ -64,6 +105,11 @@
        }
    }
    public float GetLoadingProgress()
    {
        return loadingProgress;
    }
    private void ClearConfigDictionary<T>() where T : class
    {
        // 重置 T 初始化状态
@@ -76,9 +122,11 @@
    public override void Release()
    {
        // 没有找到配置类
    }
}
Main/Manager/StageManager.cs
@@ -29,7 +29,7 @@
        AsyncOperation asyncOperation = SceneManager.LoadSceneAsync("Login");
        await OnLoading(asyncOperation, () => 1f);
        await OnLoading(asyncOperation, ConfigManager.Instance.GetLoadingProgress);
        Main.OnSwitchToLoginScene();