111
This commit is contained in:
@@ -21,29 +21,34 @@ namespace Stary.Evo.UIFarme
|
||||
/// 绑定这个面板的实例
|
||||
/// </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退出时执行的操作,只会执行一次
|
||||
@@ -58,7 +63,7 @@ namespace Stary.Evo.UIFarme
|
||||
/// </summary>
|
||||
/// <param name="type">ui信息</param>
|
||||
/// <returns></returns>
|
||||
Task<GameObject> CreatePanel(string packageName, string panelName);
|
||||
Task<GameObject> CreatePanel(string panelName, string packageName);
|
||||
|
||||
/// <summary>
|
||||
/// 销毁一个Ui对象
|
||||
@@ -81,8 +86,6 @@ namespace Stary.Evo.UIFarme
|
||||
|
||||
public abstract UITweenType TweenType { get; }
|
||||
|
||||
public abstract UIInstantiateType UIType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 面板管理器
|
||||
/// </summary>
|
||||
@@ -94,44 +97,31 @@ namespace Stary.Evo.UIFarme
|
||||
protected Transform panelParent { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 缓存该面板所有的SpriteRenderer
|
||||
/// </summary>
|
||||
private Dictionary<string, SpriteRenderer> spriteRendererDict;
|
||||
|
||||
/// <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()
|
||||
{
|
||||
spriteRendererDict = new Dictionary<string, SpriteRenderer>();
|
||||
selectableDict = new Dictionary<string, Selectable>();
|
||||
}
|
||||
|
||||
public virtual void Initialize(GameObject panelGo)
|
||||
{
|
||||
activePanel = panelGo;
|
||||
if (UIType == UIInstantiateType.SpriteNormal)
|
||||
Selectable[] selectables = activePanel.GetComponentsInChildren<Selectable>(true);
|
||||
foreach (Selectable item in selectables)
|
||||
{
|
||||
SpriteRenderer[] spriteRenderers = activePanel.GetComponentsInChildren<SpriteRenderer>(true);
|
||||
foreach (SpriteRenderer item in spriteRenderers)
|
||||
{
|
||||
spriteRendererDict[item.name] = item;
|
||||
}
|
||||
}else if(UIType == UIInstantiateType.UINormal){
|
||||
Selectable[] selectables = activePanel.GetComponentsInChildren<Selectable>(true);
|
||||
foreach (Selectable item in selectables)
|
||||
{
|
||||
selectableDict[item.name] = item;
|
||||
}
|
||||
var canvasGroup = UITool.GetOrAddComponent<CanvasGroup>(activePanel);
|
||||
canvasGroup.alpha = 0f;
|
||||
selectableDict[item.name] = item;
|
||||
}
|
||||
|
||||
|
||||
canvasGroup = UITool.GetOrAddComponent<CanvasGroup>(activePanel);
|
||||
canvasGroup.alpha = 0f;
|
||||
}
|
||||
|
||||
public virtual Task InitializeAsync(GameObject panelGo)
|
||||
@@ -155,15 +145,43 @@ namespace Stary.Evo.UIFarme
|
||||
public virtual void OnEnter(Action complete = null)
|
||||
{
|
||||
activePanel.SetActive(true);
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
if (TweenType == UITweenType.None)
|
||||
{
|
||||
canvasGroup.alpha = 1f;
|
||||
}
|
||||
|
||||
|
||||
SetCanvasGroupTween(1f, complete);
|
||||
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)
|
||||
{
|
||||
SetCanvasGroupTween(0f, () => { activePanel.SetActive(false); });
|
||||
canvasGroup.DOFade(0f, delay).OnComplete(() =>
|
||||
{
|
||||
activePanel.SetActive(false);
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
});
|
||||
}
|
||||
|
||||
public virtual void OnDestroy()
|
||||
@@ -172,7 +190,7 @@ namespace Stary.Evo.UIFarme
|
||||
}
|
||||
|
||||
|
||||
public async Task<GameObject> CreatePanel(string packageName, string panelName)
|
||||
public async Task<GameObject> CreatePanel(string panelName, string packageName)
|
||||
{
|
||||
if (panelParent == null)
|
||||
{
|
||||
@@ -184,8 +202,7 @@ namespace Stary.Evo.UIFarme
|
||||
return activePanel.gameObject;
|
||||
}
|
||||
#if HotUpdate
|
||||
|
||||
AssetHandle handle = null;
|
||||
AssetHandle handle = null;
|
||||
if (packageName == null)
|
||||
{
|
||||
handle = YooAssets.LoadAssetAsync<GameObject>(panelName);
|
||||
@@ -212,15 +229,14 @@ namespace Stary.Evo.UIFarme
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
activePanel.name = this.GetType().Name;
|
||||
|
||||
|
||||
// if (!activePanel.GetComponentInChildren<Canvas>() && !activePanel.GetComponentInParent<Canvas>())
|
||||
// {
|
||||
// Debug.LogError($"UnityEvo:panelParent上不存在Canvas组件,{panelName}无法正常运行,进程已中断,请检查!!!!!");
|
||||
// return null;
|
||||
// }
|
||||
if (!activePanel.GetComponentInChildren<Canvas>() && !activePanel.GetComponentInParent<Canvas>())
|
||||
{
|
||||
Debug.LogError($"UnityEvo:panelParent上不存在Canvas组件,{panelName}无法正常运行,进程已中断,请检查!!!!!");
|
||||
return null;
|
||||
}
|
||||
|
||||
return activePanel;
|
||||
}
|
||||
@@ -239,79 +255,21 @@ namespace Stary.Evo.UIFarme
|
||||
panelParent = parent;
|
||||
}
|
||||
|
||||
private void SetCanvasGroup(float alpha)
|
||||
/// <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
|
||||
{
|
||||
foreach (var spriteRenderer in spriteRendererDict)
|
||||
selectableDict.TryGetValue(name, out Selectable t);
|
||||
if (t == null)
|
||||
{
|
||||
Color c = spriteRenderer.Value.color;
|
||||
c.a = alpha;
|
||||
spriteRenderer.Value.color = c;
|
||||
Debug.LogError($"{this.GetType()}---{name}:在selectableDict不存在");
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCanvasGroupTween(float alpha, Action complete = null)
|
||||
{
|
||||
if (UIType == UIInstantiateType.SpriteNormal)
|
||||
{
|
||||
// 创建一个新的序列
|
||||
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(2, LoopType.Yoyo));
|
||||
}
|
||||
}
|
||||
|
||||
if (TweenType == UITweenType.None)
|
||||
{
|
||||
complete?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
sequence.OnComplete(() => complete?.Invoke());
|
||||
}
|
||||
}
|
||||
else if (UIType == UIInstantiateType.UINormal)
|
||||
{
|
||||
activePanel.SetActive(true);
|
||||
var canvasGroup = activePanel.GetComponent<CanvasGroup>();
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
if (TweenType == UITweenType.None)
|
||||
{
|
||||
canvasGroup.alpha = alpha;
|
||||
}
|
||||
|
||||
if (TweenType == UITweenType.Fade)
|
||||
{
|
||||
canvasGroup.DOFade(alpha, 1f).OnComplete(() =>
|
||||
{
|
||||
complete?.Invoke();
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
});
|
||||
}
|
||||
else if (TweenType == UITweenType.Yoyo)
|
||||
{
|
||||
canvasGroup.DOFade(alpha, 1f).SetLoops(2, LoopType.Yoyo).OnComplete(() => { complete?.Invoke(); });
|
||||
}
|
||||
else
|
||||
{
|
||||
canvasGroup.DOFade(alpha, 1f).SetLoops(-1).OnComplete(() => { complete?.Invoke(); });
|
||||
}
|
||||
}
|
||||
return t as T;
|
||||
}
|
||||
|
||||
public IArchitecture GetArchitecture()
|
||||
@@ -341,18 +299,5 @@ namespace Stary.Evo.UIFarme
|
||||
/// </summary>
|
||||
Yoyo,
|
||||
}
|
||||
|
||||
public enum UIInstantiateType
|
||||
{
|
||||
/// <summary>
|
||||
/// 普通面板
|
||||
/// </summary>
|
||||
SpriteNormal,
|
||||
|
||||
/// <summary>
|
||||
/// UI普通面板
|
||||
/// </summary>
|
||||
UINormal
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
using System;
|
||||
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 IBaseRenderPanel : 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(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 abstract class BaseRenderPanel : IBaseRenderPanel
|
||||
{
|
||||
/// <summary>
|
||||
/// UI信息
|
||||
/// </summary>
|
||||
public string UIName { get; set; }
|
||||
|
||||
public abstract UITweenType TweenType { get; }
|
||||
|
||||
|
||||
/// <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; }
|
||||
|
||||
protected void Awake()
|
||||
{
|
||||
spriteRendererDict = new Dictionary<string, SpriteRenderer>();
|
||||
}
|
||||
|
||||
public virtual void Initialize(GameObject panelGo)
|
||||
{
|
||||
activePanel = panelGo;
|
||||
|
||||
SpriteRenderer[] spriteRenderers = activePanel.GetComponentsInChildren<SpriteRenderer>(true);
|
||||
foreach (SpriteRenderer item in spriteRenderers)
|
||||
{
|
||||
spriteRendererDict[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;
|
||||
}
|
||||
#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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
public IArchitecture GetArchitecture()
|
||||
{
|
||||
return PanelSystem.GetArchitecture();
|
||||
}
|
||||
|
||||
public enum UITweenType
|
||||
{
|
||||
/// <summary>
|
||||
/// 无动画
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// 淡入淡出
|
||||
/// </summary>
|
||||
Fade,
|
||||
|
||||
/// <summary>
|
||||
/// 循环播放
|
||||
/// </summary>
|
||||
Loop,
|
||||
|
||||
/// <summary>
|
||||
/// 往返播放
|
||||
/// </summary>
|
||||
Yoyo,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba0c8ac52d5440d8a07046b9dd2de8b1
|
||||
timeCreated: 1765527320
|
||||
Reference in New Issue
Block a user