390 lines
12 KiB
C#
390 lines
12 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Threading.Tasks;
|
||
using UnityEngine;
|
||
|
||
namespace Stary.Evo.UIFarme
|
||
{
|
||
public interface ISpriteRenderSystem : ISystem
|
||
{
|
||
/// <summary>
|
||
/// UI的入栈操作,此操作会显示一个面板
|
||
/// </summary>
|
||
Task PushQueue(string prefabName, string packageName = null, Transform parent = null);
|
||
|
||
Task PushQueue<T>(string packageName = null, Transform parent = null)
|
||
where T : IBaseRenderPanel, new();
|
||
|
||
Task PushStack(string prefabName, string packageName = null, Transform parent = null);
|
||
|
||
/// <summary>
|
||
/// UI的入栈操作,此操作会显示一个面板
|
||
/// </summary>
|
||
Task PushStack<T>(Transform parent = null, string packageName = null) where T : IBaseRenderPanel, new();
|
||
|
||
/// <summary>
|
||
/// 执行面板的出栈操作,此操作会执行面板的OnExit方法
|
||
/// </summary>
|
||
void PopStack();
|
||
|
||
/// <summary>
|
||
/// 执行面板的出栈操作,此操作会执行面板的OnExit方法
|
||
/// </summary>
|
||
void PopQueue(string panelName);
|
||
|
||
void PopQueue<T>() where T : IBaseRenderPanel, new();
|
||
/// <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, IBaseRenderPanel> Get_Dic();
|
||
|
||
IBaseRenderPanel GetPanel(string PanelName);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 面板管理器,用栈来存储UI
|
||
/// </summary>
|
||
public class SpriteRendererSystem : AbstractSystem, ISpriteRenderSystem
|
||
{
|
||
/// <summary>
|
||
/// 存储普通UI面板
|
||
/// </summary>
|
||
private List<IBaseRenderPanel> queuePanel;
|
||
|
||
/// <summary>
|
||
/// 存储堆栈UI面板
|
||
/// </summary>
|
||
private Stack<IBaseRenderPanel> stackPanel;
|
||
|
||
/// <summary>
|
||
/// 存储所有UI信息的字典,每个UI信息都会对应一个GameObject
|
||
/// </summary>
|
||
private Dictionary<string, IBaseRenderPanel> dicUI;
|
||
|
||
|
||
protected override void OnInit()
|
||
{
|
||
stackPanel = new Stack<IBaseRenderPanel>();
|
||
queuePanel = new List<IBaseRenderPanel>();
|
||
dicUI = new Dictionary<string, IBaseRenderPanel>();
|
||
}
|
||
|
||
/// <summary>
|
||
/// UI的入栈操作,此操作会显示一个面板
|
||
/// </summary>
|
||
/// <param name="parent"></param>
|
||
/// <param name="packageName">非热更模式传null</param>
|
||
/// <typeparam name="T"></typeparam>
|
||
public async Task PushQueue(string prefabName, string packageName = null, Transform parent = null)
|
||
{
|
||
IBaseRenderPanel nextPanel = null;
|
||
if (!dicUI.ContainsKey(prefabName))
|
||
{
|
||
nextPanel = new BaseRenderPanel();
|
||
nextPanel.UIName = prefabName;
|
||
await nextPanel.InitializeAsync(this);
|
||
nextPanel.SetPanelParent(parent);
|
||
GameObject panelGo = await nextPanel.CreatePanel(packageName, prefabName);
|
||
///生成面板后,进行初始化操作
|
||
await nextPanel.InitializeAsync(panelGo);
|
||
dicUI.Add(prefabName, nextPanel);
|
||
}
|
||
else
|
||
{
|
||
for (int i = 0; i < queuePanel.Count; i++)
|
||
{
|
||
if (queuePanel[i].GetType().Name == prefabName)
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
|
||
nextPanel = dicUI[prefabName];
|
||
}
|
||
|
||
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 PushQueue<T>(string packageName = null, Transform parent = null)
|
||
where T : IBaseRenderPanel, new()
|
||
{
|
||
var prefabName = typeof(T).Name;
|
||
|
||
IBaseRenderPanel nextPanel = null;
|
||
if (!dicUI.ContainsKey(prefabName))
|
||
{
|
||
nextPanel = new T();
|
||
await nextPanel.InitializeAsync(this);
|
||
nextPanel.SetPanelParent(parent);
|
||
GameObject panelGo = await nextPanel.CreatePanel(packageName, nextPanel.UIName);
|
||
///生成面板后,进行初始化操作
|
||
await nextPanel.InitializeAsync(panelGo);
|
||
dicUI.Add(prefabName, nextPanel);
|
||
}
|
||
else
|
||
{
|
||
for (int i = 0; i < queuePanel.Count; i++)
|
||
{
|
||
if (queuePanel[i].GetType().Name == prefabName)
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
|
||
nextPanel = dicUI[prefabName];
|
||
}
|
||
|
||
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(string prefabName, string packageName = null, Transform parent = null)
|
||
{
|
||
IBaseRenderPanel nextPanel = null;
|
||
if (!dicUI.ContainsKey(prefabName))
|
||
{
|
||
nextPanel = new BaseRenderPanel();
|
||
nextPanel.UIName = prefabName;
|
||
await nextPanel.InitializeAsync(this);
|
||
nextPanel.SetPanelParent(parent);
|
||
GameObject panelGo = await nextPanel.CreatePanel(packageName, prefabName);
|
||
///生成面板后,进行初始化操作
|
||
await nextPanel.InitializeAsync(panelGo);
|
||
|
||
dicUI.Add(prefabName, nextPanel);
|
||
}
|
||
else
|
||
{
|
||
foreach (var panel in stackPanel)
|
||
{
|
||
if (panel.GetType().Name == prefabName)
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
|
||
nextPanel = dicUI[prefabName];
|
||
}
|
||
|
||
if (stackPanel.Count > 0)
|
||
{
|
||
stackPanel.Peek().OnExit();
|
||
}
|
||
|
||
stackPanel.Push(nextPanel);
|
||
nextPanel.OnEnter();
|
||
}
|
||
|
||
/// <summary>
|
||
/// UI的入栈操作,此操作会显示一个面板
|
||
/// </summary>
|
||
/// <param name="parent"></param>
|
||
/// <param name="packageName">非热更模式传null</param>
|
||
/// <typeparam name="T"></typeparam>
|
||
public async Task PushStack<T>(Transform parent = null, string packageName = null)
|
||
where T : IBaseRenderPanel, new()
|
||
{
|
||
var prefabName = typeof(T).Name;
|
||
if (string.IsNullOrEmpty(prefabName))
|
||
{
|
||
prefabName = typeof(T).Name;
|
||
}
|
||
|
||
IBaseRenderPanel nextPanel = null;
|
||
if (!dicUI.ContainsKey(prefabName))
|
||
{
|
||
nextPanel = new T();
|
||
await nextPanel.InitializeAsync(this);
|
||
nextPanel.SetPanelParent(parent);
|
||
GameObject panelGo = await nextPanel.CreatePanel(packageName, nextPanel.UIName);
|
||
///生成面板后,进行初始化操作
|
||
await nextPanel.InitializeAsync(panelGo);
|
||
|
||
dicUI.Add(prefabName, nextPanel);
|
||
}
|
||
else
|
||
{
|
||
foreach (var panel in stackPanel)
|
||
{
|
||
if (panel.GetType().Name == prefabName)
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
|
||
nextPanel = dicUI[prefabName];
|
||
}
|
||
|
||
if (stackPanel.Count > 0)
|
||
{
|
||
stackPanel.Peek().OnExit();
|
||
}
|
||
|
||
stackPanel.Push(nextPanel);
|
||
nextPanel.OnEnter();
|
||
}
|
||
|
||
public void PopQueue(string panelName)
|
||
{
|
||
for (int i = 0; i < queuePanel.Count; i++)
|
||
{
|
||
if (queuePanel[i].GetType().Name == panelName)
|
||
{
|
||
queuePanel[i].OnExit();
|
||
queuePanel.RemoveAt(i);
|
||
}
|
||
}
|
||
}
|
||
public void PopQueue<T>() where T : IBaseRenderPanel, new()
|
||
{
|
||
for (int i = 0; i < queuePanel.Count; i++)
|
||
{
|
||
if (queuePanel[i].GetType().Name == typeof(T).Name)
|
||
{
|
||
queuePanel[i].OnExit();
|
||
queuePanel.RemoveAt(i);
|
||
}
|
||
}
|
||
}
|
||
public void PopStack()
|
||
{
|
||
if (stackPanel.Count > 0)
|
||
{
|
||
stackPanel.Pop().OnExit();
|
||
}
|
||
|
||
if (stackPanel.Count > 0)
|
||
{
|
||
stackPanel.Peek().OnEnter();
|
||
}
|
||
}
|
||
|
||
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, IBaseRenderPanel> Get_Dic()
|
||
{
|
||
if (dicUI.Count > 0)
|
||
{
|
||
return dicUI;
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
public IBaseRenderPanel GetPanel(string PanelName)
|
||
{
|
||
if (dicUI.ContainsKey(PanelName))
|
||
{
|
||
return dicUI[PanelName];
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
public override void Dispose()
|
||
{
|
||
PopAll();
|
||
stackPanel = null;
|
||
queuePanel = null;
|
||
dicUI = null;
|
||
}
|
||
}
|
||
} |