93 lines
2.9 KiB
C#
93 lines
2.9 KiB
C#
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<List<UIConfig>> GetAllConfigs()
|
|
{
|
|
var handle = await ResourceManager.Instance.GetResourceCore(UIPackageName)
|
|
.LoadAssetAsync<UnityEngine.TextAsset>(UIConfigPath);
|
|
var textAsset = handle.GetAssetObject<TextAsset>();
|
|
if (textAsset != null)
|
|
{
|
|
var list = new List<UIConfig>();
|
|
var uiConfigs = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UIConfigJson>>(textAsset.text);
|
|
foreach (var config in uiConfigs)
|
|
{
|
|
if (!Enum.TryParse<UILayer>(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;
|
|
}
|
|
}
|
|
} |