Files
plugin-library/Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager/SpriteRendererSystem.cs
stary 383c334675
All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 5s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 7s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 22s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 7s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 3s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 35s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 4s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 18s
Plugin Library CI / publish (07.RKTools) (push) Successful in 3s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 4s
Plugin Library CI / publish (12.WeixinMinigame) (push) Successful in 1m5s
Plugin Library CI / publish (08.UniTask) (push) Successful in 4s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 19s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 5s
Plugin Library CI / publish (10.XNode) (push) Successful in 3s
111
2026-05-15 13:43:34 +08:00

410 lines
13 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
namespace Stary.Evo.UIFarme
{
public interface ISpriteRenderSystem : ISystem
{
/// <summary>
/// 资源加载器用于切换不同的资源加载方式YooAsset、Resources等
/// </summary>
IAssetLoader AssetLoader { get; set; }
/// <summary>
/// UI的入栈操作此操作会显示一个面板
/// </summary>
Task PushQueue(string prefabName, string packageName = null, Transform parent = null,BaseRenderPanel.UITweenType tweenType = BaseRenderPanel.UITweenType.Fade);
Task PushQueue<T>(string packageName = null, Transform parent = null,BaseRenderPanel.UITweenType tweenType = BaseRenderPanel.UITweenType.Fade)
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,BaseRenderPanel.UITweenType tweenType = BaseRenderPanel.UITweenType.Fade);
void PopQueue<T>(BaseRenderPanel.UITweenType tweenType = BaseRenderPanel.UITweenType.Fade) 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>
/// 资源加载器
/// </summary>
public IAssetLoader AssetLoader { get; set; }
/// <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>();
if (AssetLoader == null)
{
Debug.LogError("UnityEvo:AssetLoader is null, please set AssetLoader.");
}
}
/// <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,BaseRenderPanel.UITweenType tweenType = BaseRenderPanel.UITweenType.Fade)
{
IBaseRenderPanel nextPanel = null;
if (!dicUI.ContainsKey(prefabName))
{
nextPanel = new BaseRenderPanel();
nextPanel.UIName = prefabName;
await nextPanel.InitializeAsync(this);
nextPanel.SetPanelParent(parent);
nextPanel.TweenType = tweenType;
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,BaseRenderPanel.UITweenType tweenType = BaseRenderPanel.UITweenType.Fade)
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);
nextPanel.TweenType = tweenType;
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,BaseRenderPanel.UITweenType tweenType = BaseRenderPanel.UITweenType.Fade)
{
for (int i = 0; i < queuePanel.Count; i++)
{
if (queuePanel[i].UIName == panelName)
{
queuePanel[i].TweenType = tweenType;
queuePanel[i].OnExit();
queuePanel.RemoveAt(i);
}
}
}
public void PopQueue<T>(BaseRenderPanel.UITweenType tweenType = BaseRenderPanel.UITweenType.Fade) where T : IBaseRenderPanel, new()
{
for (int i = 0; i < queuePanel.Count; i++)
{
if (queuePanel[i].GetType().Name == typeof(T).Name)
{
queuePanel[i].TweenType = tweenType;
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;
}
}
}