11
This commit is contained in:
8
Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem.meta
Normal file
8
Assets/00.StaryEvoTools/Runtime/Tools/PanelSystem.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd3da5461163cd64ab3441b4a74898b9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29ee4f712effada4496defa69962b37d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,240 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
#if HotUpdate
|
||||
using YooAsset;
|
||||
#endif
|
||||
namespace Stary.Evo.UIFarme
|
||||
{
|
||||
public interface IBasePanel : IController
|
||||
{
|
||||
/// <summary>
|
||||
/// UI信息
|
||||
/// </summary>
|
||||
string UIName { get; set; }
|
||||
/// <summary>
|
||||
/// 绑定这个面板的实例
|
||||
/// </summary>
|
||||
void Initialize(GameObject panelGo);
|
||||
|
||||
/// <summary>
|
||||
/// 初始化面板管理器
|
||||
/// </summary>
|
||||
/// <param name="panelManager"></param>
|
||||
void Initialize(IPanelSystem sysytem);
|
||||
|
||||
/// <summary>
|
||||
/// 虚方法,UI进入时执行的操作,只会执行一次
|
||||
/// </summary>
|
||||
void OnEnter();
|
||||
|
||||
/// <summary>
|
||||
/// 虚方法,UI暂停时执行的操作,只会执行一次
|
||||
/// </summary>
|
||||
void OnPause();
|
||||
|
||||
/// <summary>
|
||||
/// 虚方法,UI继续时执行的操作,只会执行一次
|
||||
/// </summary>
|
||||
void OnResume();
|
||||
|
||||
/// <summary>
|
||||
/// 虚方法,UI退出时执行的操作,只会执行一次
|
||||
/// </summary>
|
||||
void OnExit(float delay = 0f);
|
||||
|
||||
void OnDestroy();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成/获取一个UI对象
|
||||
/// </summary>
|
||||
/// <param name="type">ui信息</param>
|
||||
/// <returns></returns>
|
||||
Task<GameObject> CreatePanel(string panelName, string packageName);
|
||||
|
||||
/// <summary>
|
||||
/// 销毁一个Ui对象
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
void DestoryUI();
|
||||
|
||||
void SetPanelParent(Transform parent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///所有UI面板的父类,包含UI面板的状态信息
|
||||
/// </summary>
|
||||
public abstract class BasePanel : IBasePanel
|
||||
{
|
||||
/// <summary>
|
||||
/// UI信息
|
||||
/// </summary>
|
||||
public string UIName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 面板管理器
|
||||
/// </summary>
|
||||
protected IPanelSystem PanelSystem { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 生成的父物体
|
||||
/// </summary>
|
||||
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 BasePanel()
|
||||
{
|
||||
selectableDict = new Dictionary<string, Selectable>();
|
||||
}
|
||||
|
||||
public virtual void Initialize(GameObject panelGo)
|
||||
{
|
||||
activePanel = panelGo;
|
||||
Selectable[] selectables = activePanel.GetComponentsInChildren<Selectable>(true);
|
||||
foreach (Selectable item in selectables)
|
||||
{
|
||||
selectableDict[item.name] = item;
|
||||
}
|
||||
|
||||
canvasGroup = UITool.GetOrAddComponent<CanvasGroup>(activePanel);
|
||||
canvasGroup.alpha = 0f;
|
||||
}
|
||||
|
||||
public virtual void Initialize(IPanelSystem sysytem)
|
||||
{
|
||||
PanelSystem = sysytem;
|
||||
}
|
||||
|
||||
|
||||
public virtual void OnEnter()
|
||||
{
|
||||
activePanel.SetActive(true);
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
canvasGroup.DOFade(1f, 1f);
|
||||
}
|
||||
|
||||
public virtual void OnPause()
|
||||
{
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
}
|
||||
|
||||
public virtual void OnResume()
|
||||
{
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
}
|
||||
|
||||
public virtual void OnExit(float delay = 0f)
|
||||
{
|
||||
canvasGroup.DOFade(0f, delay).OnComplete(() =>
|
||||
{
|
||||
activePanel.SetActive(false);
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
});
|
||||
}
|
||||
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
DestoryUI();
|
||||
}
|
||||
|
||||
|
||||
public async Task<GameObject> CreatePanel(string panelName, string packageName)
|
||||
{
|
||||
if (panelParent == null)
|
||||
{
|
||||
Debug.LogWarning($"UnityEvo:parent为空,{panelName}自动设置为root节点下,请检查是否正确!!!!!");
|
||||
}
|
||||
|
||||
if (this.activePanel != null)
|
||||
{
|
||||
return activePanel.gameObject;
|
||||
}
|
||||
#if HotUpdate
|
||||
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);
|
||||
#else
|
||||
GameObject handle = Resources.Load<GameObject>(panelName);
|
||||
activePanel = GameObject.Instantiate(handle, panelParent);
|
||||
#endif
|
||||
|
||||
|
||||
activePanel.name = this.GetType().Name;
|
||||
|
||||
|
||||
if (!activePanel.GetComponentInChildren<Canvas>() && !activePanel.GetComponentInParent<Canvas>())
|
||||
{
|
||||
Debug.LogError($"UnityEvo:panelParent上不存在Canvas组件,{panelName}无法正常运行,进程已中断,请检查!!!!!");
|
||||
return null;
|
||||
}
|
||||
|
||||
return activePanel;
|
||||
}
|
||||
|
||||
public void DestoryUI()
|
||||
{
|
||||
if (activePanel != null)
|
||||
{
|
||||
GameObject.Destroy(activePanel);
|
||||
PanelSystem.Get_Dic().Remove(this.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPanelParent(Transform parent)
|
||||
{
|
||||
panelParent = parent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取组件:Button,Toggle,Slider,InputField,Dropdown,ScroolBar
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
protected T GetComp<T>(string name) where T : Selectable
|
||||
{
|
||||
selectableDict.TryGetValue(name, out Selectable t);
|
||||
if (t == null)
|
||||
{
|
||||
Debug.LogError($"{this.GetType()}---{name}:在selectableDict不存在");
|
||||
}
|
||||
|
||||
return t as T;
|
||||
}
|
||||
|
||||
public IArchitecture GetArchitecture()
|
||||
{
|
||||
return PanelSystem.GetArchitecture();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40f7e925262e7404ba3b4d8114a222b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac2b1730cea60f24f9a45eb29d21306b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,299 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.UIFarme
|
||||
{
|
||||
public interface IPanelSystem : ISystem
|
||||
{
|
||||
/// <summary>
|
||||
/// UI的入栈操作,此操作会显示一个面板
|
||||
/// </summary>
|
||||
Task PushQueue<T>(string panelName=null,Transform parent = null, string packageName = null) where T : IBasePanel, new();
|
||||
|
||||
/// <summary>
|
||||
/// UI的入栈操作,此操作会显示一个面板
|
||||
/// </summary>
|
||||
Task PushStack<T>(string panelName=null,Transform parent = null, string packageName = null) where T : IBasePanel, new();
|
||||
|
||||
/// <summary>
|
||||
/// 执行面板的出栈操作,此操作会执行面板的OnExit方法
|
||||
/// </summary>
|
||||
void PopQueue<T>(string panelName=null) where T : IBasePanel, new();
|
||||
|
||||
/// <summary>
|
||||
/// 执行面板的出栈操作,此操作会执行面板的OnExit方法
|
||||
/// </summary>
|
||||
void PopStack();
|
||||
|
||||
/// <summary>
|
||||
/// 面板全部出栈此操作会执行面板的OnExit方法
|
||||
/// </summary>
|
||||
void PopAll();
|
||||
|
||||
/// <summary>
|
||||
/// 事件发送
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public void SendPanelEvent<TEvent>(TEvent key) where TEvent : IConvertible;
|
||||
|
||||
/// <summary>
|
||||
/// 事件发送
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public void SendPanelEvent<TEvent, Tvalue1>(TEvent key, Tvalue1 value) where TEvent : IConvertible;
|
||||
|
||||
/// <summary>
|
||||
/// 事件发送
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public void SendPanelEvent<TEvent, Tvalue1, Tvalue2>(TEvent key, Tvalue1 value1, Tvalue2 value2)
|
||||
where TEvent : IConvertible;
|
||||
|
||||
/// <summary>
|
||||
/// 事件发送
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public void SendPanelEvent<TEvent, Tvlue1, Tvlue2, Tvlue3>(TEvent key, Tvlue1 value1, Tvlue2 vlue2,
|
||||
Tvlue3 vlue3)
|
||||
where TEvent : IConvertible;
|
||||
|
||||
/// <summary>
|
||||
/// 返回存储面板实例的字典
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Dictionary<string, IBasePanel> Get_Dic();
|
||||
|
||||
IBasePanel GetPanel(string PanelName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 面板管理器,用栈来存储UI
|
||||
/// </summary>
|
||||
public class PanelSystem : AbstractSystem, IPanelSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 存储普通UI面板
|
||||
/// </summary>
|
||||
private List<IBasePanel> queuePanel;
|
||||
|
||||
/// <summary>
|
||||
/// 存储堆栈UI面板
|
||||
/// </summary>
|
||||
private Stack<IBasePanel> stackPanel;
|
||||
|
||||
/// <summary>
|
||||
/// 存储所有UI信息的字典,每个UI信息都会对应一个GameObject
|
||||
/// </summary>
|
||||
private Dictionary<string, IBasePanel> dicUI;
|
||||
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
stackPanel = new Stack<IBasePanel>();
|
||||
queuePanel = new List<IBasePanel>();
|
||||
dicUI = new Dictionary<string, IBasePanel>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UI的入栈操作,此操作会显示一个面板
|
||||
/// </summary>
|
||||
/// <param name="parent"></param>
|
||||
/// <param name="packageName">非热更模式传null</param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public async Task PushQueue<T>(string panelName=null, Transform parent = null, string packageName = null)
|
||||
where T : IBasePanel, new()
|
||||
{
|
||||
var prefabName = typeof(T).Name;
|
||||
if (string.IsNullOrEmpty(panelName))
|
||||
{
|
||||
panelName = typeof(T).Name;
|
||||
}
|
||||
IBasePanel nextPanel = null;
|
||||
if (!dicUI.ContainsKey(panelName))
|
||||
{
|
||||
nextPanel = new T();
|
||||
nextPanel.UIName = panelName;
|
||||
nextPanel.Initialize(this);
|
||||
nextPanel.SetPanelParent(parent);
|
||||
GameObject panelGo = await nextPanel.CreatePanel($"Prefabs_{prefabName}", packageName);
|
||||
///生成面板后,进行初始化操作
|
||||
nextPanel.Initialize(panelGo);
|
||||
dicUI.Add(panelName, nextPanel);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < queuePanel.Count; i++)
|
||||
{
|
||||
if (queuePanel[i].GetType().Name == panelName)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nextPanel = dicUI[panelName];
|
||||
}
|
||||
|
||||
queuePanel.Add(nextPanel);
|
||||
nextPanel.OnEnter();
|
||||
//TOOD
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UI的入栈操作,此操作会显示一个面板
|
||||
/// </summary>
|
||||
/// <param name="parent"></param>
|
||||
/// <param name="packageName">非热更模式传null</param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public async Task PushStack<T>(string panelName=null,Transform parent = null, string packageName = null) where T : IBasePanel, new()
|
||||
{
|
||||
var prefabName = typeof(T).Name;
|
||||
if (string.IsNullOrEmpty(panelName))
|
||||
{
|
||||
panelName = typeof(T).Name;
|
||||
}
|
||||
|
||||
IBasePanel nextPanel = null;
|
||||
if (!dicUI.ContainsKey(panelName))
|
||||
{
|
||||
nextPanel = new T();
|
||||
nextPanel.UIName = panelName;
|
||||
nextPanel.Initialize(this);
|
||||
nextPanel.SetPanelParent(parent);
|
||||
GameObject panelGo = await nextPanel.CreatePanel($"Prefabs_{prefabName}", packageName);
|
||||
///生成面板后,进行初始化操作
|
||||
nextPanel.Initialize(panelGo);
|
||||
|
||||
dicUI.Add(panelName, nextPanel);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < stackPanel.Count; i++)
|
||||
{
|
||||
if (queuePanel[i].GetType().Name == panelName)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nextPanel = dicUI[panelName];
|
||||
}
|
||||
|
||||
stackPanel.Push(nextPanel);
|
||||
nextPanel.OnEnter();
|
||||
}
|
||||
|
||||
|
||||
public void PopQueue<T>(string panelName=null) where T : IBasePanel, new()
|
||||
{
|
||||
if (string.IsNullOrEmpty(panelName))
|
||||
{
|
||||
panelName = typeof(T).Name;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < queuePanel.Count; i++)
|
||||
{
|
||||
if (queuePanel[i].GetType().Name == panelName)
|
||||
{
|
||||
queuePanel[i].OnExit();
|
||||
queuePanel.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PopStack()
|
||||
{
|
||||
if (stackPanel.Count > 0)
|
||||
{
|
||||
stackPanel.Pop().OnExit();
|
||||
}
|
||||
|
||||
if (stackPanel.Count > 0)
|
||||
{
|
||||
stackPanel.Peek().OnResume();
|
||||
}
|
||||
}
|
||||
|
||||
public void PopAll()
|
||||
{
|
||||
while (stackPanel.Count > 0)
|
||||
stackPanel.Pop().OnExit();
|
||||
foreach (var panel in queuePanel)
|
||||
{
|
||||
panel.OnExit();
|
||||
}
|
||||
|
||||
queuePanel.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 事件发送
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public void SendPanelEvent<TEvent>(TEvent key) where TEvent : IConvertible
|
||||
{
|
||||
this.SendEvent(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 事件发送
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public void SendPanelEvent<TEvent, Tvalue1>(TEvent key, Tvalue1 value) where TEvent : IConvertible
|
||||
{
|
||||
this.SendEvent(key, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 事件发送
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public void SendPanelEvent<TEvent, Tvalue1, Tvalue2>(TEvent key, Tvalue1 value1, Tvalue2 value2)
|
||||
where TEvent : IConvertible
|
||||
{
|
||||
this.SendEvent(key, value1, value2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 事件发送
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public void SendPanelEvent<TEvent, Tvlue1, Tvlue2, Tvlue3>(TEvent key, Tvlue1 value1, Tvlue2 vlue2,
|
||||
Tvlue3 vlue3)
|
||||
where TEvent : IConvertible
|
||||
{
|
||||
this.SendEvent(key, value1, vlue2, vlue3);
|
||||
}
|
||||
|
||||
|
||||
public Dictionary<string, IBasePanel> Get_Dic()
|
||||
{
|
||||
if (dicUI.Count > 0)
|
||||
{
|
||||
return dicUI;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public IBasePanel GetPanel(string PanelName)
|
||||
{
|
||||
if (dicUI.ContainsKey(PanelName))
|
||||
{
|
||||
return dicUI[PanelName];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
PopAll();
|
||||
stackPanel = null;
|
||||
queuePanel = null;
|
||||
dicUI = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe94e5095f79a6e43b88b79996bb6907
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b02fa06ef99a409438a3210be9148e0f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
/// <summary>
|
||||
/// UI管理工具,包括获取某个子对象组件的操作
|
||||
/// </summary>
|
||||
public class UITool
|
||||
{
|
||||
/// <summary>
|
||||
/// 给当前的活动面板获取或者添加一个组件
|
||||
/// </summary>
|
||||
/// <typeparam name="T">组件类型</typeparam>
|
||||
/// <returns>组件</returns>
|
||||
public static T GetOrAddComponent<T>(GameObject activeGo) where T : Component
|
||||
{
|
||||
if (activeGo.GetComponent<T>() == null)
|
||||
activeGo.AddComponent<T>();
|
||||
|
||||
return activeGo.GetComponent<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据名称获取一个子对象的组件
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public static T FindChild<T>(GameObject activeGo, string name)
|
||||
{
|
||||
Transform child = null;
|
||||
Transform[] children = activeGo.GetComponentsInChildren<Transform>(true);
|
||||
for (int i = 0; i < children.Length; i++)
|
||||
{
|
||||
if (children[i].name.Equals(name))
|
||||
{
|
||||
child = children[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (child != null)
|
||||
{
|
||||
return child.GetComponent<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("未找到指定的组件,指定的组件为:" + typeof(T).FullName + "-----" + activeGo);
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: daa3b3944e8c712488cb711a0f3f092b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user