yyl
2025-05-16 f4c97339a01fdd75d8b862be572eefe66bd51d5a
Main/Manager/ConfigManager.cs
@@ -3,6 +3,7 @@
using UnityEngine;
using Cysharp.Threading.Tasks;
using System.Reflection;
using System.IO;
public class ConfigManager : ManagerBase<ConfigManager>
@@ -57,10 +58,10 @@
        {
            configName = configName.Substring(0, configName.Length - 6);
        }
        TextAsset textAsset = await ResManager.Instance.LoadAsset<TextAsset>("Config", configName);
        if (textAsset != null)
        string texts = await Load(configName);
        if (!string.IsNullOrEmpty(texts))
        {
            string[] lines = textAsset.text.Split('\n');
            string[] lines = texts.Split('\n');
            var methodInfo = configType.GetMethod("Init", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy);
            if (methodInfo != null)
            {
@@ -80,7 +81,7 @@
        }
        else
        {
            Debug.LogError($"找不到配置文件: {configName}");
            Debug.LogError($"{configName} 内容为空或加载失败");
        }
    }
@@ -88,10 +89,10 @@
    {
        string configName = typeof(T).Name;
        TextAsset textAsset = await ResManager.Instance.LoadAsset<TextAsset>("Config", configName);
        if (textAsset != null)
        string texts = await Load(configName);
        if (!string.IsNullOrEmpty(texts))
        {
            string[] lines = textAsset.text.Split('\n');
            string[] lines = texts.Split('\n');
            var methodInfo = typeof(T).GetMethod("Init", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
            if (methodInfo != null)
            {
@@ -111,7 +112,7 @@
        }
        else
        {
            Debug.LogError($"找不到配置文件: {configName}");
            Debug.LogError($"{configName} 内容为空或加载失败");
        }
    }
@@ -130,6 +131,23 @@
        }
    }
    public static async UniTask<string> Load(string configName)
    {
      var path = string.Empty;
        if (AssetSource.refdataFromEditor)
        {
            path = ResourcesPath.CONFIG_FODLER + $"/{configName}.txt";
        }
        else
        {
            path = AssetVersionUtility.GetAssetFilePath($"config/{configName}.txt");
        }
        string texts = await File.ReadAllTextAsync(path);
        return texts;
    }
    public override void Release()
    {
        // 清空 FamilyConfig 字典