281 lines
8.3 KiB
C#
281 lines
8.3 KiB
C#
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>(Transform parent,string packageName=null) where T : IBasePanel, new();
|
||
|
||
/// <summary>
|
||
/// UI的入栈操作,此操作会显示一个面板
|
||
/// </summary>
|
||
Task PushStack<T>(Transform parent,string packageName=null) where T : IBasePanel, new();
|
||
|
||
/// <summary>
|
||
/// 执行面板的出栈操作,此操作会执行面板的OnExit方法
|
||
/// </summary>
|
||
void PopQueue<T>() 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>(Transform parent,string packageName=null) where T : IBasePanel, new()
|
||
{
|
||
string panelName = typeof(T).Name;
|
||
|
||
IBasePanel nextPanel = null;
|
||
if (!dicUI.ContainsKey(panelName))
|
||
{
|
||
nextPanel = new T();
|
||
nextPanel.Initialize(this);
|
||
nextPanel.SetPanelParent(parent);
|
||
GameObject panelGo = await nextPanel.CreatePanel($"Prefabs_{panelName}",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>(Transform parent,string packageName=null) where T : IBasePanel, new()
|
||
{
|
||
string panelName = typeof(T).Name;
|
||
|
||
IBasePanel nextPanel = null;
|
||
if (!dicUI.ContainsKey(panelName))
|
||
{
|
||
nextPanel = new T();
|
||
nextPanel.Initialize(this);
|
||
nextPanel.SetPanelParent(parent);
|
||
GameObject panelGo = await nextPanel.CreatePanel(panelName,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>() where T : IBasePanel, new()
|
||
{
|
||
string 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;
|
||
}
|
||
}
|
||
} |