using System; using System.Collections.Generic; using Cysharp.Threading.Tasks; using UnityEngine; using YooAsset; namespace SkierFramework { [System.Serializable] public class UIConfigJson { public string uiType; public string path; public bool isWindow; public string uiLayer; } public class UIConfig { public string path; public string uiType; public UILayer uiLayer; public Type viewType; public bool isWindow; private const string UIConfigPath = "Assets/UI/UISystemPackage/UIConfig.json"; public const string UIPackageName = "PanelPackage"; public static async UniTask> GetAllConfigs() { var handle = await ResourceManager.Instance.GetResourceCore(UIPackageName) .LoadAssetAsync(UIConfigPath); var textAsset = handle.GetAssetObject(); if (textAsset != null) { var list = new List(); var uiConfigs = Newtonsoft.Json.JsonConvert.DeserializeObject>(textAsset.text); foreach (var config in uiConfigs) { if (!Enum.TryParse(config.uiLayer, out UILayer layer)) { layer = UILayer.NormalLayer; Debug.LogErrorFormat("UIConfig.json 中的:{0} uiLayer解析异常 {1}", config.path, config.uiLayer); } Type viewType = GetType(config.uiType.ToString()); if (viewType == null) { viewType = GetType($"{typeof(UIConfig).Namespace}.{config.uiType}"); } list.Add(new UIConfig { path = config.path, uiLayer = layer, uiType = config.uiType, viewType = viewType, isWindow = config.isWindow }); } return list; } else { Debug.LogError("未找到配置:" + UIConfigPath); return null; } } public static Type GetType(string typeName) { var type = Type.GetType(typeName); if (type != null) { return type; } var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (System.Reflection.Assembly assembly in assemblies) { type = Type.GetType(string.Format("{0}, {1}", typeName, assembly.FullName)); if (type != null) { return type; } } return null; } } }