06 优化加载资源包读取路径
This commit is contained in:
@@ -9,8 +9,6 @@ namespace Stary.Evo.UIFarme
|
||||
{
|
||||
public interface IBasePanel : IController
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 绑定这个面板的实例
|
||||
/// </summary>
|
||||
@@ -50,14 +48,14 @@ namespace Stary.Evo.UIFarme
|
||||
/// </summary>
|
||||
/// <param name="type">ui信息</param>
|
||||
/// <returns></returns>
|
||||
Task<GameObject> CreatePanel(string panelName);
|
||||
Task<GameObject> CreatePanel(string panelName, string packageName);
|
||||
|
||||
/// <summary>
|
||||
/// 销毁一个Ui对象
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
void DestoryUI();
|
||||
|
||||
|
||||
void SetPanelParent(Transform parent);
|
||||
}
|
||||
|
||||
@@ -79,21 +77,20 @@ namespace Stary.Evo.UIFarme
|
||||
/// <summary>
|
||||
/// 生成的父物体
|
||||
/// </summary>
|
||||
protected Transform panelParent{get; private set;}
|
||||
|
||||
protected Transform panelParent { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 缓存该面板所有的Button,Toggle,Slider,InputField,Dropdown,ScroolBar
|
||||
/// </summary>
|
||||
private Dictionary<string, Selectable> selectableDict;
|
||||
|
||||
protected CanvasGroup canvasGroup{get;private set;}
|
||||
|
||||
protected GameObject activePanel{get;private set;}
|
||||
protected CanvasGroup canvasGroup { get; private set; }
|
||||
|
||||
protected GameObject activePanel { get; private set; }
|
||||
|
||||
protected BasePanel()
|
||||
{
|
||||
|
||||
selectableDict = new Dictionary<string, Selectable>();
|
||||
}
|
||||
|
||||
@@ -148,32 +145,49 @@ namespace Stary.Evo.UIFarme
|
||||
}
|
||||
|
||||
|
||||
public async Task<GameObject> CreatePanel(string panelName)
|
||||
public async Task<GameObject> CreatePanel(string panelName, string packageName)
|
||||
{
|
||||
if (panelParent == null)
|
||||
{
|
||||
Debug.LogError($"UnityEvo:parent为空,{panelName}无法创建,进程已中断,请检查!!!!!");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (this.activePanel != null)
|
||||
{
|
||||
return activePanel.gameObject;
|
||||
}
|
||||
|
||||
var handle= YooAssets.LoadAssetAsync<GameObject>(panelName);
|
||||
AssetHandle handle = null;
|
||||
if (packageName == null)
|
||||
{
|
||||
handle = YooAssets.LoadAssetAsync<GameObject>(panelName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package= YooAssets.TryGetPackage(packageName);
|
||||
if (package == null)
|
||||
{
|
||||
handle = YooAssets.LoadAssetAsync<GameObject>(panelName);
|
||||
}
|
||||
else
|
||||
{
|
||||
handle = package.LoadAssetAsync<GameObject>(panelName);
|
||||
}
|
||||
}
|
||||
|
||||
await handle.Task;
|
||||
|
||||
activePanel = GameObject.Instantiate(handle.AssetObject as GameObject,panelParent);
|
||||
|
||||
activePanel = GameObject.Instantiate(handle.AssetObject as GameObject, panelParent);
|
||||
activePanel.name = this.GetType().Name;
|
||||
|
||||
|
||||
|
||||
|
||||
if (!activePanel.GetComponent<Canvas>())
|
||||
{
|
||||
Debug.LogError($"UnityEvo:panelParent上不存在Canvas组件,{panelName}无法正常运行,进程已中断,请检查!!!!!");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return activePanel;
|
||||
}
|
||||
|
||||
@@ -204,6 +218,7 @@ namespace Stary.Evo.UIFarme
|
||||
{
|
||||
Debug.LogError($"{this.GetType()}---{name}:在selectableDict不存在");
|
||||
}
|
||||
|
||||
return t as T;
|
||||
}
|
||||
|
||||
@@ -212,6 +227,4 @@ namespace Stary.Evo.UIFarme
|
||||
return PanelSystem.GetArchitecture();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,12 +10,12 @@ namespace Stary.Evo.UIFarme
|
||||
/// <summary>
|
||||
/// UI的入栈操作,此操作会显示一个面板
|
||||
/// </summary>
|
||||
Task PushQueue<T>(Transform parent) where T : IBasePanel, new();
|
||||
Task PushQueue<T>(Transform parent,string packageName=null) where T : IBasePanel, new();
|
||||
|
||||
/// <summary>
|
||||
/// UI的入栈操作,此操作会显示一个面板
|
||||
/// </summary>
|
||||
Task PushStack<T>(Transform parent) where T : IBasePanel, new();
|
||||
Task PushStack<T>(Transform parent,string packageName=null) where T : IBasePanel, new();
|
||||
|
||||
/// <summary>
|
||||
/// 执行面板的出栈操作,此操作会执行面板的OnExit方法
|
||||
@@ -94,7 +94,7 @@ namespace Stary.Evo.UIFarme
|
||||
}
|
||||
|
||||
|
||||
public async Task PushQueue<T>(Transform parent) where T : IBasePanel, new()
|
||||
public async Task PushQueue<T>(Transform parent,string packageName=null) where T : IBasePanel, new()
|
||||
{
|
||||
string panelName = typeof(T).Name;
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Stary.Evo.UIFarme
|
||||
nextPanel = new T();
|
||||
nextPanel.Initialize(this);
|
||||
nextPanel.SetPanelParent(parent);
|
||||
GameObject panelGo = await nextPanel.CreatePanel($"Prefabs_{panelName}");
|
||||
GameObject panelGo = await nextPanel.CreatePanel($"Prefabs_{panelName}",packageName);
|
||||
///生成面板后,进行初始化操作
|
||||
nextPanel.Initialize(panelGo);
|
||||
dicUI.Add(panelName, nextPanel);
|
||||
@@ -127,7 +127,7 @@ namespace Stary.Evo.UIFarme
|
||||
//TOOD
|
||||
}
|
||||
|
||||
public async Task PushStack<T>(Transform parent) where T : IBasePanel, new()
|
||||
public async Task PushStack<T>(Transform parent,string packageName=null) where T : IBasePanel, new()
|
||||
{
|
||||
string panelName = typeof(T).Name;
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace Stary.Evo.UIFarme
|
||||
nextPanel = new T();
|
||||
nextPanel.Initialize(this);
|
||||
nextPanel.SetPanelParent(parent);
|
||||
GameObject panelGo = await nextPanel.CreatePanel(panelName);
|
||||
GameObject panelGo = await nextPanel.CreatePanel(panelName,packageName);
|
||||
///生成面板后,进行初始化操作
|
||||
nextPanel.Initialize(panelGo);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.staryevo.uifarme",
|
||||
"displayName": "06.UIFarme",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"description": "UI模板框架工具",
|
||||
"unity": "2021.3",
|
||||
"unityRelease": "30f1",
|
||||
|
||||
Reference in New Issue
Block a user