111
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
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
This commit is contained in:
8
Assets/00.StaryEvo/Runtime/Tool/PanelSystem.meta
Normal file
8
Assets/00.StaryEvo/Runtime/Tool/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: 4d89fa7f5efc28243a1c998e29f158a6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.UIFarme
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源加载策略接口,用于抽象不同的资源加载方式(如YooAsset、Resources等)
|
||||
/// </summary>
|
||||
public interface IAssetLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步加载GameObject资源
|
||||
/// </summary>
|
||||
/// <param name="assetPath">资源路径</param>
|
||||
/// <param name="packageName">YooAsset包名,Resources模式可忽略</param>
|
||||
/// <returns>加载到的GameObject资源(非实例,是原始Prefab)</returns>
|
||||
Task<GameObject> LoadGameObjectAsync(string assetPath, string packageName = null);
|
||||
|
||||
/// <summary>
|
||||
/// 卸载指定资源,释放底层资源句柄
|
||||
/// </summary>
|
||||
/// <param name="assetPath">资源路径</param>
|
||||
void UnloadAsset(string assetPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eee0c2ac899cda04d8ec4a2bb7687195
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.UIFarme
|
||||
{
|
||||
/// <summary>
|
||||
/// 基于Resources的资源加载实现
|
||||
/// </summary>
|
||||
public class ResourcesAssetLoader : IAssetLoader
|
||||
{
|
||||
private readonly Dictionary<string, Object> _assetCache = new Dictionary<string, Object>();
|
||||
|
||||
/// <summary>
|
||||
/// 通过Resources异步加载GameObject资源
|
||||
/// </summary>
|
||||
public async Task<GameObject> LoadGameObjectAsync(string assetPath, string packageName = null)
|
||||
{
|
||||
// Resources模式下忽略packageName
|
||||
var request = Resources.LoadAsync<GameObject>(assetPath);
|
||||
while (!request.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
var asset = request.asset as GameObject;
|
||||
if (asset != null)
|
||||
{
|
||||
_assetCache[assetPath] = asset;
|
||||
}
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放Resources加载的资源
|
||||
/// </summary>
|
||||
public void UnloadAsset(string assetPath)
|
||||
{
|
||||
if (_assetCache.TryGetValue(assetPath, out Object asset) && asset != null)
|
||||
{
|
||||
Resources.UnloadAsset(asset);
|
||||
_assetCache.Remove(assetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21c72a85d6a282940bb331dfd1c926fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base.meta
Normal file
8
Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29ee4f712effada4496defa69962b37d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
291
Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base/BasePanel.cs
Normal file
291
Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Base/BasePanel.cs
Normal file
@@ -0,0 +1,291 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Stary.Evo.UIFarme
|
||||
{
|
||||
public interface IBasePanel : IController
|
||||
{
|
||||
/// <summary>
|
||||
/// UI信息
|
||||
/// </summary>
|
||||
string UIName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 绑定这个面板的实例
|
||||
/// </summary>
|
||||
void Initialize(GameObject panelGo);
|
||||
/// <summary>
|
||||
/// 绑定这个面板的实例
|
||||
/// </summary>
|
||||
Task InitializeAsync(GameObject panelGo);
|
||||
/// <summary>
|
||||
/// 初始化面板管理器
|
||||
/// </summary>
|
||||
/// <param name="panelManager"></param>
|
||||
void Initialize(IPanelSystem sysytem);
|
||||
/// <summary>
|
||||
/// 初始化面板管理器
|
||||
/// </summary>
|
||||
/// <param name="panelManager"></param>
|
||||
Task InitializeAsync(IPanelSystem sysytem);
|
||||
/// <summary>
|
||||
/// 虚方法,UI进入时执行的操作,只会执行一次
|
||||
/// </summary>
|
||||
void OnEnter(Action complete = null);
|
||||
|
||||
/// <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; }
|
||||
|
||||
public abstract UITweenType TweenType { get; }
|
||||
|
||||
/// <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; }
|
||||
|
||||
/// <summary>
|
||||
/// 记录当前面板的资源路径,用于释放资源句柄
|
||||
/// </summary>
|
||||
private string _assetPath;
|
||||
|
||||
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 Task InitializeAsync(GameObject panelGo)
|
||||
{
|
||||
Initialize(panelGo);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual void Initialize(IPanelSystem sysytem)
|
||||
{
|
||||
PanelSystem = sysytem;
|
||||
}
|
||||
|
||||
public virtual Task InitializeAsync(IPanelSystem sysytem)
|
||||
{
|
||||
Initialize(sysytem);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
public virtual void OnEnter(Action complete = null)
|
||||
{
|
||||
activePanel.SetActive(true);
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
if (TweenType == UITweenType.None)
|
||||
{
|
||||
canvasGroup.alpha = 1f;
|
||||
}
|
||||
|
||||
if (TweenType == UITweenType.Fade)
|
||||
{
|
||||
canvasGroup.DOFade(1f, 2f).OnComplete(() => { complete?.Invoke(); });
|
||||
}
|
||||
else if (TweenType == UITweenType.Yoyo)
|
||||
{
|
||||
canvasGroup.DOFade(1, 2f).SetLoops(2, LoopType.Yoyo).OnComplete(() => { complete?.Invoke(); });
|
||||
}
|
||||
else
|
||||
{
|
||||
canvasGroup.DOFade(1, 2f).SetLoops(-1).OnComplete(() => { complete?.Invoke(); });
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
_assetPath = panelName;
|
||||
var asset = await PanelSystem.AssetLoader.LoadGameObjectAsync(panelName, packageName);
|
||||
if (asset == null)
|
||||
{
|
||||
Debug.LogError($"UnityEvo:资源加载失败,{panelName}未找到!");
|
||||
return null;
|
||||
}
|
||||
|
||||
activePanel = GameObject.Instantiate(asset, panelParent);
|
||||
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);
|
||||
if (!string.IsNullOrEmpty(_assetPath))
|
||||
{
|
||||
PanelSystem.AssetLoader.UnloadAsset(_assetPath);
|
||||
_assetPath = null;
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
public enum UITweenType
|
||||
{
|
||||
/// <summary>
|
||||
/// 无动画
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// 淡入淡出
|
||||
/// </summary>
|
||||
Fade,
|
||||
|
||||
/// <summary>
|
||||
/// 循环播放
|
||||
/// </summary>
|
||||
Loop,
|
||||
|
||||
/// <summary>
|
||||
/// 往返播放
|
||||
/// </summary>
|
||||
Yoyo,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40f7e925262e7404ba3b4d8114a222b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,267 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.UIFarme
|
||||
{
|
||||
public interface IBaseRenderPanel : IController
|
||||
{
|
||||
/// <summary>
|
||||
/// UI信息
|
||||
/// </summary>
|
||||
string UIName { get; set; }
|
||||
|
||||
BaseRenderPanel.UITweenType TweenType { get; set; }
|
||||
/// <summary>
|
||||
/// 绑定这个面板的实例
|
||||
/// </summary>
|
||||
void Initialize(GameObject panelGo);
|
||||
|
||||
/// <summary>
|
||||
/// 绑定这个面板的实例
|
||||
/// </summary>
|
||||
Task InitializeAsync(GameObject panelGo);
|
||||
|
||||
/// <summary>
|
||||
/// 初始化面板管理器
|
||||
/// </summary>
|
||||
/// <param name="panelManager"></param>
|
||||
void Initialize(ISpriteRenderSystem sysytem);
|
||||
|
||||
/// <summary>
|
||||
/// 初始化面板管理器
|
||||
/// </summary>
|
||||
/// <param name="panelManager"></param>
|
||||
Task InitializeAsync(ISpriteRenderSystem sysytem);
|
||||
|
||||
/// <summary>
|
||||
/// 虚方法,UI进入时执行的操作,只会执行一次
|
||||
/// </summary>
|
||||
void OnEnter(Action complete = null);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 虚方法,UI退出时执行的操作,只会执行一次
|
||||
/// </summary>
|
||||
void OnExit(float delay = 0f);
|
||||
|
||||
void OnDestroy();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成/获取一个UI对象
|
||||
/// </summary>
|
||||
/// <param name="type">ui信息</param>
|
||||
/// <returns></returns>
|
||||
Task<GameObject> CreatePanel(string packageName, string panelName);
|
||||
|
||||
/// <summary>
|
||||
/// 销毁一个Ui对象
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
void DestoryUI();
|
||||
|
||||
void SetPanelParent(Transform parent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///所有UI面板的父类,包含UI面板的状态信息
|
||||
/// </summary>
|
||||
public class BaseRenderPanel : IBaseRenderPanel
|
||||
{
|
||||
/// <summary>
|
||||
/// UI信息
|
||||
/// </summary>
|
||||
public virtual string UIName { get; set; }
|
||||
|
||||
public UITweenType TweenType { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 面板管理器
|
||||
/// </summary>
|
||||
protected ISpriteRenderSystem PanelSystem { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 生成的父物体
|
||||
/// </summary>
|
||||
protected Transform panelParent { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 缓存该面板所有的SpriteRenderer
|
||||
/// </summary>
|
||||
private Dictionary<string, SpriteRenderer> spriteRendererDict;
|
||||
|
||||
|
||||
protected GameObject activePanel { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 记录当前面板的资源路径,用于释放资源句柄
|
||||
/// </summary>
|
||||
private string _assetPath;
|
||||
|
||||
|
||||
public virtual void Initialize(GameObject panelGo)
|
||||
{
|
||||
activePanel = panelGo;
|
||||
spriteRendererDict = new Dictionary<string, SpriteRenderer>();
|
||||
SpriteRenderer[] spriteRenderers = activePanel.GetComponentsInChildren<SpriteRenderer>(true);
|
||||
foreach (SpriteRenderer item in spriteRenderers)
|
||||
{
|
||||
spriteRendererDict.Add(item.name,item);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Task InitializeAsync(GameObject panelGo)
|
||||
{
|
||||
Initialize(panelGo);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual void Initialize(ISpriteRenderSystem sysytem)
|
||||
{
|
||||
PanelSystem = sysytem;
|
||||
}
|
||||
|
||||
public virtual Task InitializeAsync(ISpriteRenderSystem sysytem)
|
||||
{
|
||||
Initialize(sysytem);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
public virtual void OnEnter(Action complete = null)
|
||||
{
|
||||
activePanel.SetActive(true);
|
||||
|
||||
|
||||
SetCanvasGroupTween(1f, complete);
|
||||
}
|
||||
|
||||
|
||||
public virtual void OnExit(float delay = 0f)
|
||||
{
|
||||
SetCanvasGroupTween(0f, () => { activePanel.SetActive(false); });
|
||||
}
|
||||
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
DestoryUI();
|
||||
}
|
||||
|
||||
|
||||
public async Task<GameObject> CreatePanel(string packageName, string panelName)
|
||||
{
|
||||
if (panelParent == null)
|
||||
{
|
||||
Debug.LogWarning($"UnityEvo:parent为空,{panelName}自动设置为root节点下,请检查是否正确!!!!!");
|
||||
}
|
||||
|
||||
if (this.activePanel != null)
|
||||
{
|
||||
return activePanel.gameObject;
|
||||
}
|
||||
|
||||
_assetPath = panelName;
|
||||
var asset = await PanelSystem.AssetLoader.LoadGameObjectAsync(panelName, packageName);
|
||||
if (asset == null)
|
||||
{
|
||||
Debug.LogError($"UnityEvo:资源加载失败,{panelName}未找到!");
|
||||
return null;
|
||||
}
|
||||
|
||||
activePanel = GameObject.Instantiate(asset, panelParent);
|
||||
activePanel.name = panelName;
|
||||
|
||||
return activePanel;
|
||||
}
|
||||
|
||||
public void DestoryUI()
|
||||
{
|
||||
if (activePanel != null)
|
||||
{
|
||||
GameObject.Destroy(activePanel);
|
||||
if (!string.IsNullOrEmpty(_assetPath))
|
||||
{
|
||||
PanelSystem.AssetLoader.UnloadAsset(_assetPath);
|
||||
_assetPath = null;
|
||||
}
|
||||
PanelSystem.Get_Dic().Remove(this.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPanelParent(Transform parent)
|
||||
{
|
||||
panelParent = parent;
|
||||
}
|
||||
|
||||
private void SetCanvasGroup(float alpha)
|
||||
{
|
||||
foreach (var spriteRenderer in spriteRendererDict)
|
||||
{
|
||||
Color c = spriteRenderer.Value.color;
|
||||
c.a = alpha;
|
||||
spriteRenderer.Value.color = c;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCanvasGroupTween(float alpha, Action complete = null)
|
||||
{
|
||||
|
||||
// 创建一个新的序列
|
||||
Sequence sequence = DOTween.Sequence();
|
||||
|
||||
|
||||
foreach (var spriteRenderer in spriteRendererDict)
|
||||
{
|
||||
if (TweenType == UITweenType.None)
|
||||
{
|
||||
Color c = spriteRenderer.Value.color;
|
||||
c.a = alpha;
|
||||
spriteRenderer.Value.color = c;
|
||||
}
|
||||
else if (TweenType == UITweenType.Fade)
|
||||
{
|
||||
sequence.Join(spriteRenderer.Value.DOFade(alpha, 1f));
|
||||
}
|
||||
// else if (TweenType == UITweenType.Yoyo)
|
||||
// {
|
||||
// sequence.Join(spriteRenderer.Value.DOFade(alpha, 1f)
|
||||
// .SetLoops(-1, LoopType.Yoyo));
|
||||
// }
|
||||
}
|
||||
|
||||
if (TweenType == UITweenType.None)
|
||||
{
|
||||
complete?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
sequence.OnComplete(() => complete?.Invoke());
|
||||
sequence.Play();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public IArchitecture GetArchitecture()
|
||||
{
|
||||
return PanelSystem.GetArchitecture();
|
||||
}
|
||||
|
||||
public enum UITweenType
|
||||
{
|
||||
/// <summary>
|
||||
/// 无动画
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// 淡入淡出
|
||||
/// </summary>
|
||||
Fade,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba0c8ac52d5440d8a07046b9dd2de8b1
|
||||
timeCreated: 1765527320
|
||||
8
Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager.meta
Normal file
8
Assets/00.StaryEvo/Runtime/Tool/PanelSystem/Manager.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac2b1730cea60f24f9a45eb29d21306b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,321 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.UIFarme
|
||||
{
|
||||
public interface IPanelSystem : ISystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源加载器,用于切换不同的资源加载方式(YooAsset、Resources等)
|
||||
/// </summary>
|
||||
IAssetLoader AssetLoader { get; set; }
|
||||
|
||||
/// <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();
|
||||
|
||||
void PopQueue<T>(T 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>
|
||||
/// 资源加载器
|
||||
/// </summary>
|
||||
public IAssetLoader AssetLoader { get; set; }
|
||||
|
||||
/// <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>();
|
||||
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<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;
|
||||
await nextPanel.InitializeAsync(this);
|
||||
nextPanel.SetPanelParent(parent);
|
||||
GameObject panelGo = await nextPanel.CreatePanel(prefabName, packageName);
|
||||
///生成面板后,进行初始化操作
|
||||
await nextPanel.InitializeAsync(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;
|
||||
await nextPanel.InitializeAsync(this);
|
||||
nextPanel.SetPanelParent(parent);
|
||||
GameObject panelGo = await nextPanel.CreatePanel(prefabName, packageName);
|
||||
///生成面板后,进行初始化操作
|
||||
await nextPanel.InitializeAsync(panelGo);
|
||||
|
||||
dicUI.Add(panelName, nextPanel);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var panel in stackPanel)
|
||||
{
|
||||
if (panel.GetType().Name == panelName)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nextPanel = dicUI[panelName];
|
||||
}
|
||||
if(stackPanel.Count > 0)
|
||||
{
|
||||
stackPanel.Peek().OnExit();
|
||||
}
|
||||
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 PopQueue<T>(T t, string panelName = null) where T : IBasePanel, new()
|
||||
{
|
||||
PopQueue<T>(panelName);
|
||||
}
|
||||
|
||||
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, 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,410 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c8492e998a14a6f96e96902acbf587a
|
||||
timeCreated: 1765527058
|
||||
8
Assets/00.StaryEvo/Runtime/Tool/PanelSystem/UITool.meta
Normal file
8
Assets/00.StaryEvo/Runtime/Tool/PanelSystem/UITool.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b02fa06ef99a409438a3210be9148e0f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
Assets/00.StaryEvo/Runtime/Tool/PanelSystem/UITool/UITool.cs
Normal file
50
Assets/00.StaryEvo/Runtime/Tool/PanelSystem/UITool/UITool.cs
Normal file
@@ -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:
|
||||
@@ -2,7 +2,8 @@
|
||||
"name": "com.stary.evo.runtime",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"UniTask"
|
||||
"UniTask",
|
||||
"DOTween.Modules"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
Reference in New Issue
Block a user