| | |
| | | using UnityEngine;
|
| | | using Cysharp.Threading.Tasks;
|
| | | using System.Reflection;
|
| | | using System.IO;
|
| | |
|
| | |
|
| | | public class ConfigManager : ManagerBase<ConfigManager>
|
| | |
| | | {
|
| | | 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)
|
| | | {
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | Debug.LogError($"找不到配置文件: {configName}");
|
| | | Debug.LogError($"{configName} 内容为空或加载失败");
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | 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)
|
| | | {
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | Debug.LogError($"找不到配置文件: {configName}");
|
| | | Debug.LogError($"{configName} 内容为空或加载失败");
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | 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 字典
|