首次提交
This commit is contained in:
8
Assets/Scripts/NBC/UI/Runtime.meta
Normal file
8
Assets/Scripts/NBC/UI/Runtime.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e54d4b9d5d9fd9c4bae1cd40f3d9698d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
Assets/Scripts/NBC/UI/Runtime/Attributes.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/Attributes.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65441e72d19f4334b7d4e9748762839e
|
||||
timeCreated: 1607069598
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true)]
|
||||
public class AutoFindAttribute : Attribute
|
||||
{
|
||||
public string Name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 370e0f8ad369463ca826cbb7c3d2cc21
|
||||
timeCreated: 1607069612
|
||||
3
Assets/Scripts/NBC/UI/Runtime/Component.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/Component.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cf70d9f97294cf284d2a538d95c762c
|
||||
timeCreated: 1606991848
|
||||
39
Assets/Scripts/NBC/UI/Runtime/Component/IUIPanel.cs
Normal file
39
Assets/Scripts/NBC/UI/Runtime/Component/IUIPanel.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public interface IUIPanel
|
||||
{
|
||||
FairyGUI.GComponent ContentPane { get; }
|
||||
|
||||
// string UILayer { get; }
|
||||
/// <summary>
|
||||
/// 模块id
|
||||
/// </summary>
|
||||
int Id { get; }
|
||||
|
||||
bool IsTop { get; }
|
||||
bool IsShowing { get; }
|
||||
bool IsCanVisible { get; }
|
||||
bool IsDotDel { get; }
|
||||
|
||||
|
||||
bool IsModal { get; }
|
||||
|
||||
bool IsShowCursor { get; }
|
||||
|
||||
void SetUIManager(UIManager kit);
|
||||
void SetData(object args);
|
||||
object GetData();
|
||||
string[] GetDependPackages();
|
||||
void SetLanguage();
|
||||
|
||||
void Init();
|
||||
void Show();
|
||||
void Hide();
|
||||
void Update();
|
||||
void HideImmediately();
|
||||
void Refresh();
|
||||
void Dispose();
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/UI/Runtime/Component/IUIPanel.cs.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/Component/IUIPanel.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85e70ef2de904307919fe91865311fc1
|
||||
timeCreated: 1606989126
|
||||
316
Assets/Scripts/NBC/UI/Runtime/Component/UIPanel.cs
Normal file
316
Assets/Scripts/NBC/UI/Runtime/Component/UIPanel.cs
Normal file
@@ -0,0 +1,316 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FairyGUI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public abstract class UIPanel : IUIPanel
|
||||
{
|
||||
public static Func<string, string> GetUIPackNameFunc = s => $"{s}/{s}";
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示在最顶层
|
||||
/// </summary>
|
||||
public bool IsTop => _ui.IsTop(this);
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示黑色背景蒙版
|
||||
/// </summary>
|
||||
public bool IsModal { get; protected set; }
|
||||
|
||||
public virtual bool IsShowing => ContentPane != null && ContentPane.parent != null;
|
||||
|
||||
public virtual bool IsCanVisible => ContentPane != null && ContentPane.parent != null && ContentPane.visible;
|
||||
|
||||
public bool IsDotDel { get; protected set; }
|
||||
public virtual string UIPackRootUrl => string.Empty;
|
||||
|
||||
public virtual string UIPackName { get; set; }
|
||||
public virtual string UIResName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模块id,(可用于对模块编号实现一些特定功能,如新手引导)
|
||||
/// </summary>
|
||||
public virtual int Id { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示光标,屏蔽游戏内输入
|
||||
/// </summary>
|
||||
public virtual bool IsShowCursor { get; protected set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 面板打开动画
|
||||
/// </summary>
|
||||
public UIAnimTask ShowAnim = null;
|
||||
|
||||
/// <summary>
|
||||
/// 面板关闭动画
|
||||
/// </summary>
|
||||
public UIAnimTask HideAnim = null;
|
||||
|
||||
private object _paramData;
|
||||
private bool _isInited;
|
||||
|
||||
public GComponent ContentPane { get; protected set; }
|
||||
protected UIManager _ui;
|
||||
|
||||
public void SetUIManager(UIManager manager)
|
||||
{
|
||||
_ui = manager;
|
||||
}
|
||||
|
||||
public void SetData(object args)
|
||||
{
|
||||
_paramData = args;
|
||||
}
|
||||
|
||||
public object GetData()
|
||||
{
|
||||
return _paramData;
|
||||
}
|
||||
|
||||
public virtual string[] GetDependPackages()
|
||||
{
|
||||
return new string[] { };
|
||||
}
|
||||
|
||||
|
||||
public void Init()
|
||||
{
|
||||
try
|
||||
{
|
||||
var uiPackRootUrl = string.IsNullOrEmpty(UIPackRootUrl) ? UIConst.UIPackRootUrl : UIPackRootUrl;
|
||||
//实例化预设
|
||||
if (!_isInited)
|
||||
{
|
||||
var dependPackages = GetDependPackages();
|
||||
if (dependPackages != null && dependPackages.Length > 0)
|
||||
{
|
||||
foreach (var package in dependPackages)
|
||||
{
|
||||
if (package != UIPackName)
|
||||
{
|
||||
_ui.AddPackage(uiPackRootUrl, GetUIPackNameFunc(package));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_ui.AddPackage(uiPackRootUrl, GetUIPackNameFunc(UIPackName));
|
||||
|
||||
GObject panelObj = UIPackage.CreateObject(UIPackName, UIResName);
|
||||
if (panelObj == null)
|
||||
{
|
||||
throw new Exception("不存在包名:" + UIPackName + "/ResName=" + UIResName);
|
||||
}
|
||||
|
||||
// panelObj.name = UIResName;
|
||||
panelObj.SetSize(GRoot.inst.width, GRoot.inst.height);
|
||||
panelObj.position = Vector3.zero;
|
||||
panelObj.ToSafeArea();
|
||||
panelObj.scale = Vector2.one;
|
||||
panelObj.pivotX = 0.5f;
|
||||
panelObj.pivotY = 0.5f;
|
||||
ContentPane = panelObj.asCom;
|
||||
ContentPane.name = UIResName;
|
||||
this.AutoFindAllField();
|
||||
OnInit();
|
||||
|
||||
// FairyBatching
|
||||
GComponent panelObjCom = panelObj.asCom;
|
||||
if (panelObjCom != null)
|
||||
{
|
||||
panelObjCom.fairyBatching = true;
|
||||
}
|
||||
|
||||
_isInited = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!IsShowing)
|
||||
{
|
||||
GRoot.inst.AddChild(ContentPane);
|
||||
ContentPane.visible = true;
|
||||
_ui.AdjustModalLayer();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!IsTop) _ui.BringToFront(this);
|
||||
if (IsModal)
|
||||
{
|
||||
_ui.AdjustModalLayer();
|
||||
}
|
||||
}
|
||||
|
||||
_ui.TryPlayPanelTween(ContentPane);
|
||||
OpenAnimBegin();
|
||||
if (ShowAnim != null)
|
||||
{
|
||||
ShowAnim.SetDefaultInfo();
|
||||
ShowAnim.OnCompleted(OpenAnimFinished, true);
|
||||
ShowAnim.Run(UIRunner.Def);
|
||||
}
|
||||
else
|
||||
{
|
||||
OpenAnimFinished(null);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error($"UIPackName={UIPackName} UIResName={UIResName} e={e}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
if (!IsShowing) return;
|
||||
if (HideAnim != null)
|
||||
{
|
||||
HideAnim.SetDefaultInfo();
|
||||
HideAnim.OnCompleted(HideAnimFinished);
|
||||
HideAnim.Run(UIRunner.Def);
|
||||
}
|
||||
else
|
||||
{
|
||||
HideAnimFinished(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
OnUpdate();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
Show();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置刷新多语言
|
||||
/// </summary>
|
||||
public void SetLanguage()
|
||||
{
|
||||
_ui.TrySetPanelLanguage(ContentPane);
|
||||
OnSetLanguage();
|
||||
}
|
||||
|
||||
public void HideImmediately()
|
||||
{
|
||||
// ContentPane.visible = false;
|
||||
if (ContentPane.parent != null)
|
||||
{
|
||||
// UIKit.
|
||||
GRoot.inst.RemoveChild(ContentPane);
|
||||
_ui.AdjustModalLayer();
|
||||
|
||||
_ui?.DispatchEventWith(UIEvents.UIHide, this);
|
||||
// UIKit.LayerManager.RemoveChild(this);
|
||||
}
|
||||
|
||||
OnHide();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!IsDotDel)
|
||||
{
|
||||
HideImmediately();
|
||||
ContentPane.Dispose();
|
||||
OnDestroy();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("当前panel标记为不可删除,name=" + UIResName);
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenAnimBegin()
|
||||
{
|
||||
OnShow();
|
||||
SetLanguage();
|
||||
_ui?.DispatchEventWith(UIEvents.UIShow, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开动画播放完成
|
||||
/// </summary>
|
||||
/// <param name="task"></param>
|
||||
private void OpenAnimFinished(ITask task)
|
||||
{
|
||||
OnShowed();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭动画播放完成
|
||||
/// </summary>
|
||||
/// <param name="task"></param>
|
||||
private void HideAnimFinished(ITask task)
|
||||
{
|
||||
HideImmediately();
|
||||
}
|
||||
|
||||
#region 接口
|
||||
|
||||
/// <summary>
|
||||
/// 界面初始化的时候
|
||||
/// </summary>
|
||||
protected virtual void OnInit()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代码设置多语言,OnShow后和语言变化时会调用
|
||||
/// </summary>
|
||||
protected virtual void OnSetLanguage()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示界面显示
|
||||
/// </summary>
|
||||
/// <param name="param"></param>
|
||||
protected virtual void OnShow()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示界面完成(动画后)
|
||||
/// </summary>
|
||||
protected virtual void OnShowed()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 界面隐藏的时候
|
||||
/// </summary>
|
||||
protected virtual void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 界面销毁的时候
|
||||
/// </summary>
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/UI/Runtime/Component/UIPanel.cs.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/Component/UIPanel.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6717340027374964a13049a5b6f18c2f
|
||||
timeCreated: 1606992345
|
||||
3
Assets/Scripts/NBC/UI/Runtime/Const.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/Const.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 324106ae827a4b39a7d306901d9cf61d
|
||||
timeCreated: 1603427397
|
||||
25
Assets/Scripts/NBC/UI/Runtime/Const/UIConst.cs
Normal file
25
Assets/Scripts/NBC/UI/Runtime/Const/UIConst.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public static class UIConst
|
||||
{
|
||||
public const string ServiceName = "NBC.UIKit";
|
||||
|
||||
/// <summary>
|
||||
/// UI资源前缀
|
||||
/// </summary>
|
||||
public static string UIPackRootUrl = "";
|
||||
|
||||
/// <summary>
|
||||
/// UI安全区域
|
||||
/// </summary>
|
||||
public static Rect SafeArea = Rect.zero;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 开启UI安全区域
|
||||
/// </summary>
|
||||
internal static bool OpenSafeArea = false;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/UI/Runtime/Const/UIConst.cs.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/Const/UIConst.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8599513d5235498b9f2cc5894451a3e6
|
||||
timeCreated: 1603427408
|
||||
9
Assets/Scripts/NBC/UI/Runtime/Const/UIEvents.cs
Normal file
9
Assets/Scripts/NBC/UI/Runtime/Const/UIEvents.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace NBC
|
||||
{
|
||||
public static class UIEvents
|
||||
{
|
||||
public const string UIShow = "UIShow";
|
||||
|
||||
public const string UIHide = "UIHide";
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/UI/Runtime/Const/UIEvents.cs.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/Const/UIEvents.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 398ef2627f5f47c2969f775329e212c0
|
||||
timeCreated: 1658111393
|
||||
3
Assets/Scripts/NBC/UI/Runtime/Extension.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/Extension.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 301625d0537e4abd8e4d2be119c2d6a8
|
||||
timeCreated: 1607073119
|
||||
181
Assets/Scripts/NBC/UI/Runtime/Extension/UIExtension.cs
Normal file
181
Assets/Scripts/NBC/UI/Runtime/Extension/UIExtension.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using FairyGUI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public static class UIExtension
|
||||
{
|
||||
public static void AutoFindAllField<T>(this T self) where T : UIPanel
|
||||
{
|
||||
var fields = self.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var attrs = field.GetCustomAttributes<AutoFindAttribute>().ToArray();
|
||||
if (attrs.Length <= 0) continue;
|
||||
var findInfo = attrs[0];
|
||||
var name = string.IsNullOrEmpty(findInfo.Name) ? field.Name : findInfo.Name;
|
||||
object obj;
|
||||
// var type = field.FieldType;
|
||||
if (field.FieldType == typeof(Controller))
|
||||
{
|
||||
obj = self.ContentPane.GetController(name);
|
||||
}
|
||||
else if (field.FieldType == typeof(Transition))
|
||||
{
|
||||
obj = self.ContentPane.GetTransition(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = self.ContentPane.GetChild(name);
|
||||
}
|
||||
|
||||
if (obj == null)
|
||||
{
|
||||
throw new Exception("查找子物体失败" + "type=" + field.FieldType + "/name=" + findInfo.Name);
|
||||
}
|
||||
|
||||
// Log.I(self.UIResName + "查找子物体" + "type=" + field.FieldType + "/name=" + findInfo.Name);
|
||||
field.SetValue(self, obj);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动注册点击事件
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="btnStartName">FGUI中按钮以什么开头</param>
|
||||
/// <param name="onClick"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public static void AutoAddClick<T>(this T self, Action<GComponent> onClick, string btnStartName = "Btn")
|
||||
where T : UIPanel
|
||||
{
|
||||
for (int i = 0; i < self.ContentPane.numChildren; i++)
|
||||
{
|
||||
GObject gObject = self.ContentPane.GetChildAt(i);
|
||||
if (gObject.name.StartsWith(btnStartName))
|
||||
{
|
||||
gObject.onClick.Add(a => { onClick?.Invoke(a.sender as GComponent); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void AutoClearClick<T>(this T self, string btnStartName = "Btn")
|
||||
where T : UIPanel
|
||||
{
|
||||
for (int i = 0; i < self.ContentPane.numChildren; i++)
|
||||
{
|
||||
GObject gObject = self.ContentPane.GetChildAt(i);
|
||||
if (gObject.name.StartsWith(btnStartName))
|
||||
{
|
||||
gObject.onClick.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 自动注册点击事件
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="btnStartName"></param>
|
||||
/// <param name="onClick"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public static void AutoAddClick(this GComponent self, Action<GComponent> onClick, string btnStartName = "Btn")
|
||||
{
|
||||
for (int i = 0; i < self.numChildren; i++)
|
||||
{
|
||||
GObject gObject = self.GetChildAt(i);
|
||||
if (gObject.name.StartsWith(btnStartName))
|
||||
{
|
||||
gObject.onClick.Add(a => { onClick?.Invoke(a.sender as GComponent); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void AutoSetClick(this GComponent self, Action<GComponent> onClick, string btnStartName = "Btn")
|
||||
{
|
||||
for (int i = 0; i < self.numChildren; i++)
|
||||
{
|
||||
GObject gObject = self.GetChildAt(i);
|
||||
if (gObject.name.StartsWith(btnStartName))
|
||||
{
|
||||
gObject.onClick.Set(a => { onClick?.Invoke(a.sender as GComponent); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void AutoClearClick(this GComponent self, string btnStartName = "Btn")
|
||||
{
|
||||
for (int i = 0; i < self.numChildren; i++)
|
||||
{
|
||||
GObject gObject = self.GetChildAt(i);
|
||||
if (gObject.name.StartsWith(btnStartName))
|
||||
{
|
||||
gObject.onClick.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region 安全距离
|
||||
|
||||
private static bool _isInitArea = false;
|
||||
|
||||
private static void InitArea()
|
||||
{
|
||||
var safeArea = Screen.safeArea;
|
||||
Rect norSafeArea = Rect.zero;
|
||||
var width = GRoot.inst.width;
|
||||
norSafeArea.width = width;
|
||||
norSafeArea.height = safeArea.height / safeArea.width * width;
|
||||
|
||||
var y = Screen.height - Screen.safeArea.yMax;
|
||||
var x = Screen.width - Screen.safeArea.xMax;
|
||||
|
||||
norSafeArea.x = (x / Screen.width) * GRoot.inst.width;
|
||||
norSafeArea.y = (y / Screen.height) * GRoot.inst.height;
|
||||
if (norSafeArea.y < 1)
|
||||
{
|
||||
norSafeArea.y = GRoot.inst.size.y - norSafeArea.height;
|
||||
}
|
||||
|
||||
UIConst.SafeArea = norSafeArea;
|
||||
_isInitArea = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置对象安全距离
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
public static void ToSafeArea(this GObject self)
|
||||
{
|
||||
if (!UIConst.OpenSafeArea) return;
|
||||
if (!_isInitArea) InitArea();
|
||||
var safeArea = UIConst.SafeArea;
|
||||
if (Math.Abs(self.size.x - safeArea.width) < 1)
|
||||
{
|
||||
self.SetSize(safeArea.width, safeArea.height);
|
||||
|
||||
self.position = new Vector3(0, safeArea.y);
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector2 ToSafeArea(this Vector2 vector2)
|
||||
{
|
||||
if (!UIConst.OpenSafeArea) return vector2;
|
||||
if (!_isInitArea) InitArea();
|
||||
return vector2;
|
||||
}
|
||||
|
||||
public static Vector3 ToSafeArea(this Vector3 vector3)
|
||||
{
|
||||
if (!UIConst.OpenSafeArea) return vector3;
|
||||
if (!_isInitArea) InitArea();
|
||||
return vector3;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6e1faca2d324be59996ac7b326ac9a7
|
||||
timeCreated: 1607073126
|
||||
3
Assets/Scripts/NBC/UI/Runtime/Interfaces.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/Interfaces.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5dc408ef68f470386edde3039dc804b
|
||||
timeCreated: 1603427536
|
||||
7
Assets/Scripts/NBC/UI/Runtime/Interfaces/IBind.cs
Normal file
7
Assets/Scripts/NBC/UI/Runtime/Interfaces/IBind.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace NBC
|
||||
{
|
||||
public interface IBind
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/UI/Runtime/Interfaces/IBind.cs.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/Interfaces/IBind.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0acf981fdc74a7685b9298cbbeb959a
|
||||
timeCreated: 1608000546
|
||||
19
Assets/Scripts/NBC/UI/Runtime/NBC.UI.asmdef
Normal file
19
Assets/Scripts/NBC/UI/Runtime/NBC.UI.asmdef
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "NBC.UI",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:b3c9c3fa0cbae6e438ac062aa5d78b76",
|
||||
"GUID:8c8f9d96103e94a7da84b012fd7e9f13",
|
||||
"GUID:3f4a88279c0696a488a2e08f8bccf903",
|
||||
"GUID:8beb767f9f7a66f4e87dd9db57cdd64e"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Assets/Scripts/NBC/UI/Runtime/NBC.UI.asmdef.meta
Normal file
7
Assets/Scripts/NBC/UI/Runtime/NBC.UI.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78a9aa383c5e7074d8c134031782f5b2
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
171
Assets/Scripts/NBC/UI/Runtime/UICommand.cs
Normal file
171
Assets/Scripts/NBC/UI/Runtime/UICommand.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
internal enum UICmdType
|
||||
{
|
||||
Show,
|
||||
Hide,
|
||||
Del
|
||||
}
|
||||
|
||||
internal enum UICommandState
|
||||
{
|
||||
None,
|
||||
Wait,
|
||||
Done,
|
||||
}
|
||||
|
||||
internal class UICommand
|
||||
{
|
||||
|
||||
#region 静态
|
||||
|
||||
private static UIManager _uiKit;
|
||||
private static readonly Queue<UICommand> _pools = new();
|
||||
private static readonly List<UICommand> _curCmd = new();
|
||||
|
||||
public static void Init(UIManager uiKit)
|
||||
{
|
||||
_uiKit = uiKit;
|
||||
MonoManager.Inst.OnUpdate += OnUpdate;
|
||||
}
|
||||
|
||||
public static bool HasCmd(Type type, UICmdType cmdType)
|
||||
{
|
||||
return _curCmd.Exists(a => a.UIType == type && a.CmdType == cmdType);
|
||||
}
|
||||
|
||||
public static UICommand GetCmd(UICmdType uiCmdType)
|
||||
{
|
||||
var cmd = _pools.Count > 0 ? _pools.Dequeue() : new UICommand();
|
||||
cmd.CmdType = uiCmdType;
|
||||
return cmd;
|
||||
}
|
||||
|
||||
public static void RevertCmd(UICommand cmd)
|
||||
{
|
||||
cmd.RestData();
|
||||
_pools.Enqueue(cmd);
|
||||
}
|
||||
|
||||
private static void OnUpdate()
|
||||
{
|
||||
if (_curCmd.Count < 1) return;
|
||||
var cur = _curCmd[0];
|
||||
if (cur.State == UICommandState.None)
|
||||
{
|
||||
cur.State = UICommandState.Wait;
|
||||
switch (cur.CmdType)
|
||||
{
|
||||
case UICmdType.Show:
|
||||
cur.Show();
|
||||
break;
|
||||
case UICmdType.Hide:
|
||||
cur.Hide();
|
||||
break;
|
||||
case UICmdType.Del:
|
||||
cur.Del();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (cur.State == UICommandState.Done)
|
||||
{
|
||||
var cmd = _curCmd[0];
|
||||
_curCmd.RemoveAt(0);
|
||||
if (cmd != null) RevertCmd(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public UICmdType CmdType;
|
||||
public Type UIType;
|
||||
public Action<IUIPanel> Callback;
|
||||
public object Param;
|
||||
public IUIPanel Panel;
|
||||
public string UIName;
|
||||
|
||||
public UICommandState State;
|
||||
|
||||
public void RestData()
|
||||
{
|
||||
Param = null;
|
||||
Panel = null;
|
||||
State = UICommandState.None;
|
||||
Callback = null;
|
||||
UIType = null;
|
||||
}
|
||||
|
||||
public UICommand SetCallback(Action<IUIPanel> callback)
|
||||
{
|
||||
Callback = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UICommand SetUIData(Type uiType, string uiName, object param)
|
||||
{
|
||||
UIType = uiType;
|
||||
UIName = uiName;
|
||||
Param = param;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public void Run()
|
||||
{
|
||||
State = UICommandState.None;
|
||||
_curCmd.Add(this);
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
if (UIName == "PlotPanel")
|
||||
{
|
||||
|
||||
}
|
||||
IUIPanel panel = _uiKit.GetUI(UIName);
|
||||
if (panel == null)
|
||||
{
|
||||
panel = Activator.CreateInstance(UIType) as IUIPanel;
|
||||
if (panel != null)
|
||||
{
|
||||
panel.SetUIManager(_uiKit);
|
||||
panel.SetData(Param);
|
||||
panel.Init();
|
||||
_uiKit.AddUI(UIName, panel);
|
||||
}
|
||||
}
|
||||
|
||||
State = UICommandState.Done;
|
||||
_uiKit.ShowUI(UIName, Param);
|
||||
Callback?.Invoke(panel);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
State = UICommandState.Done;
|
||||
IUIPanel wind = _uiKit.GetUI(UIName);
|
||||
if (wind == null)
|
||||
{
|
||||
Log.Warning($"要隐藏的界面不存在:{UIName}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wind.IsShowing)
|
||||
{
|
||||
Log.Warning($"要隐藏的界面未打开{UIName}");
|
||||
return;
|
||||
}
|
||||
|
||||
wind.Hide();
|
||||
}
|
||||
|
||||
public void Del()
|
||||
{
|
||||
State = UICommandState.Done;
|
||||
_uiKit.RemoveUI(UIName);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/UI/Runtime/UICommand.cs.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/UICommand.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63138e7895924fc981b6fa6d13ccf184
|
||||
timeCreated: 1664330627
|
||||
21
Assets/Scripts/NBC/UI/Runtime/UIKitFacade.cs
Normal file
21
Assets/Scripts/NBC/UI/Runtime/UIKitFacade.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace NBC
|
||||
{
|
||||
public class UI
|
||||
{
|
||||
private static UIManager _inst;
|
||||
|
||||
public static UIManager Inst
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_inst == null)
|
||||
{
|
||||
_inst = new UIManager();
|
||||
_inst.Start();
|
||||
}
|
||||
|
||||
return _inst;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/UI/Runtime/UIKitFacade.cs.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/UIKitFacade.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e31143f2c014a7ba1ef31aaa3c4159c
|
||||
timeCreated: 1630661745
|
||||
3
Assets/Scripts/NBC/UI/Runtime/UILanguage.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/UILanguage.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc014662f0324fc093a0fa05eed3b511
|
||||
timeCreated: 1715247626
|
||||
@@ -0,0 +1,153 @@
|
||||
using System.Collections.Generic;
|
||||
using FairyGUI;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public class UIComponentLanguage : Dictionary<string, string>
|
||||
{
|
||||
}
|
||||
|
||||
public abstract class UIComponentLanguagePack : Dictionary<string, UIComponentLanguage>
|
||||
{
|
||||
public bool Has(string url)
|
||||
{
|
||||
return ContainsKey(url);
|
||||
}
|
||||
|
||||
public void TrySetComponentLanguage(GComponent component)
|
||||
{
|
||||
if (component.packageItem == null) return;
|
||||
SetComponentFont(component);
|
||||
if (!Has(component.resourceURL)) return;
|
||||
SetComponentLanguage(component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置Panel时不判断配置中是否有数据
|
||||
/// </summary>
|
||||
/// <param name="component"></param>
|
||||
public void TrySetPanelLanguage(GComponent component)
|
||||
{
|
||||
SetComponentFont(component);
|
||||
SetComponentLanguage(component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置组件多语言
|
||||
/// </summary>
|
||||
/// <param name="component"></param>
|
||||
public void SetComponentLanguage(GComponent component)
|
||||
{
|
||||
bool comHasLanConfig = false;
|
||||
UIComponentLanguage componentLangeage = null;
|
||||
if (component.packageItem != null && TryGetValue(component.resourceURL, out componentLangeage))
|
||||
comHasLanConfig = true;
|
||||
|
||||
var count = component.numChildren;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var child = component.GetChildAt(i);
|
||||
if (child.packageItem != null && child is GComponent childCom)
|
||||
{
|
||||
SetComponentLanguage(childCom);
|
||||
}
|
||||
else if (child is GList list)
|
||||
{
|
||||
SetComponentLanguage(list);
|
||||
}
|
||||
|
||||
if (comHasLanConfig)
|
||||
{
|
||||
var id = child.id;
|
||||
if (componentLangeage.TryGetValue(id, out var key))
|
||||
{
|
||||
if (child is GLoader gLoader)
|
||||
{
|
||||
gLoader.SetLanguageImage(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
child.SetLanguage(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// private void SetChildLanguage(object child, string value)
|
||||
// {
|
||||
// if (child is TextField textField)
|
||||
// {
|
||||
// textField.text = value;
|
||||
// }
|
||||
// else if (child is GRichTextField richTextField)
|
||||
// {
|
||||
// richTextField.text = value;
|
||||
// }
|
||||
// else if (child is GButton button)
|
||||
// {
|
||||
// button.title = value;
|
||||
// }
|
||||
// else if (child is GLabel label)
|
||||
// {
|
||||
// label.title = value;
|
||||
// }
|
||||
// else if (child is GTextField gtextField)
|
||||
// {
|
||||
// gtextField.text = value;
|
||||
// }
|
||||
// }
|
||||
|
||||
void SetComponentFont(GComponent component)
|
||||
{
|
||||
var count = component.numChildren;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var child = component.GetChildAt(i);
|
||||
if (child is GComponent childCom)
|
||||
{
|
||||
SetComponentFont(childCom);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetChildFont(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetChildFont(GObject child)
|
||||
{
|
||||
GTextField curField = null;
|
||||
if (child is GRichTextField richTextField)
|
||||
{
|
||||
curField = richTextField;
|
||||
}
|
||||
else if (child is GButton button)
|
||||
{
|
||||
curField = button.GetTextField();
|
||||
}
|
||||
else if (child is GLabel label)
|
||||
{
|
||||
curField = label.GetTextField();
|
||||
}
|
||||
else if (child is GTextField gtextField)
|
||||
{
|
||||
curField = gtextField;
|
||||
}
|
||||
|
||||
if (curField == null) return;
|
||||
var textFormat = curField.textFormat;
|
||||
Log.Info($"font={textFormat.font}");
|
||||
var fontName = textFormat.font;
|
||||
if (string.IsNullOrEmpty(fontName))
|
||||
{
|
||||
fontName = UIConfig.defaultFont;
|
||||
}
|
||||
|
||||
var font = Lan.GetLanFontByCurFont(fontName);
|
||||
if (font == null) return;
|
||||
textFormat.font = font;
|
||||
curField.textFormat = textFormat;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de429c9a72354bac8521f78835cda342
|
||||
timeCreated: 1715247635
|
||||
21
Assets/Scripts/NBC/UI/Runtime/UILanguage/UILanguage.cs
Normal file
21
Assets/Scripts/NBC/UI/Runtime/UILanguage/UILanguage.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using FairyGUI;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
/// <summary>
|
||||
/// UI多语言
|
||||
/// </summary>
|
||||
public static class UILanguage
|
||||
{
|
||||
/// <summary>
|
||||
/// 用于过滤界面设置语言时,避免导出脚本的组件重复设置语言
|
||||
/// </summary>
|
||||
public static bool isPanelSetting = false;
|
||||
|
||||
public static void TrySetComponentLanguage(GComponent component)
|
||||
{
|
||||
if (!isPanelSetting)
|
||||
UI.Inst.TrySetComponentLanguage(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f212c92129c344f2a73daa0f46b99010
|
||||
timeCreated: 1715247696
|
||||
445
Assets/Scripts/NBC/UI/Runtime/UIManager.cs
Normal file
445
Assets/Scripts/NBC/UI/Runtime/UIManager.cs
Normal file
@@ -0,0 +1,445 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FairyGUI;
|
||||
using NBC.Asset;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public class UIManager : EventDispatcher
|
||||
{
|
||||
/// <summary>
|
||||
/// 所有UI
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, IUIPanel> _uiArray = new Dictionary<string, IUIPanel>();
|
||||
|
||||
private GGraph _modalLayer;
|
||||
private GRoot _uiRoot;
|
||||
|
||||
private UIComponentLanguagePack _uiLanguageConfig;
|
||||
|
||||
// 新增 Tween 配置
|
||||
private UIComponentTweenPack _uiTweenConfig;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Log.Info("UI 模块初始化");
|
||||
_uiRoot = GRoot.inst;
|
||||
MonoManager.Inst.OnUpdate += Update;
|
||||
UICommand.Init(this);
|
||||
}
|
||||
|
||||
public void Quit()
|
||||
{
|
||||
MonoManager.Inst.OnUpdate -= Update;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
UIRunner.Update();
|
||||
foreach (var panel in _uiArray.Values)
|
||||
{
|
||||
if (panel != null && panel.IsShowing)
|
||||
{
|
||||
panel.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
|
||||
internal void ShowUI(string uiName, object param = null)
|
||||
{
|
||||
IUIPanel panel = GetUI(uiName);
|
||||
panel.SetData(param);
|
||||
if (panel.IsShowing)
|
||||
{
|
||||
panel.Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplyPanelRootTween(panel); // 根动效设置为 ShowAnim
|
||||
panel.Show();
|
||||
}
|
||||
}
|
||||
|
||||
internal void RemoveUI(string uiName)
|
||||
{
|
||||
IUIPanel wind = GetUI(uiName);
|
||||
if (wind == null)
|
||||
{
|
||||
Log.Warning($"要删除的界面不存在:{uiName}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wind.IsDotDel)
|
||||
{
|
||||
wind.Dispose();
|
||||
_uiArray.Remove(uiName);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateModalLayer()
|
||||
{
|
||||
var modalLayerColor = UIConfig.modalLayerColor;
|
||||
|
||||
if (_modalLayer != null)
|
||||
{
|
||||
_modalLayer.onClick.Clear();
|
||||
}
|
||||
|
||||
_modalLayer = new GGraph();
|
||||
_modalLayer.DrawRect(_uiRoot.width, _uiRoot.height, 0, Color.white,
|
||||
modalLayerColor);
|
||||
_modalLayer.AddRelation(_uiRoot, RelationType.Size);
|
||||
_modalLayer.name = _modalLayer.gameObjectName = "ModalLayer";
|
||||
_modalLayer.SetHome(_uiRoot);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 动画
|
||||
|
||||
public void SetUITween<T>() where T : UIComponentTweenPack
|
||||
{
|
||||
_uiTweenConfig = Activator.CreateInstance<T>();
|
||||
}
|
||||
|
||||
public void TryPlayComponentTween(GComponent component)
|
||||
{
|
||||
_uiTweenConfig?.TryPlayComponentTween(component);
|
||||
}
|
||||
|
||||
public void TryPlayPanelTween(GComponent component)
|
||||
{
|
||||
_uiTweenConfig?.TryPlayPanelTween(component);
|
||||
}
|
||||
|
||||
private void ApplyPanelRootTween(IUIPanel panel)
|
||||
{
|
||||
if (panel?.ContentPane == null || _uiTweenConfig == null) return;
|
||||
var url = panel.ContentPane.resourceURL;
|
||||
if (string.IsNullOrEmpty(url)) return;
|
||||
var tweenName = _uiTweenConfig.GetRootTween(url);
|
||||
if (string.IsNullOrEmpty(tweenName)) return;
|
||||
if (panel is not UIPanel upPanel) return; // 需要具体 UIPanel 才能设置 ShowAnim
|
||||
|
||||
if (upPanel.ShowAnim != null) return;
|
||||
switch (tweenName)
|
||||
{
|
||||
case "Fade": upPanel.ShowAnim = UIPanelAnimation.GetFade(upPanel); break;
|
||||
case "Scale": upPanel.ShowAnim = UIPanelAnimation.GetCenterScaleBig(upPanel); break;
|
||||
case "Pop": upPanel.ShowAnim = UIPanelAnimation.GetCenterPopScaleFade(upPanel); break;
|
||||
case "SlideInL": upPanel.ShowAnim = UIPanelAnimation.GetLeftToSlideFade(upPanel); break;
|
||||
case "SlideInR": upPanel.ShowAnim = UIPanelAnimation.GetRightToSlideFade(upPanel); break;
|
||||
case "SlideInT": upPanel.ShowAnim = UIPanelAnimation.GetUpToSlideFade(upPanel); break;
|
||||
case "SlideInB": upPanel.ShowAnim = UIPanelAnimation.GetDownToSlideFade(upPanel); break;
|
||||
case "Bounce": upPanel.ShowAnim = UIPanelAnimation.GetBounceVertical(upPanel); break;
|
||||
case "Rotate": upPanel.ShowAnim = UIPanelAnimation.GetRotate(upPanel); break;
|
||||
case "Shake": upPanel.ShowAnim = UIPanelAnimation.GetShake(upPanel); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void OpenUI<T>(object param = null)
|
||||
{
|
||||
Type type = typeof(T);
|
||||
|
||||
OpenUI(type.Name, type, param);
|
||||
}
|
||||
|
||||
public void OpenUI(Type type, object param = null)
|
||||
{
|
||||
OpenUI(type.Name, type, param);
|
||||
}
|
||||
|
||||
public void OpenUI<T>(string uiName, object param = null,
|
||||
Action<IUIPanel> callback = null)
|
||||
{
|
||||
Type type = typeof(T);
|
||||
OpenUI(uiName, type, param, callback);
|
||||
}
|
||||
|
||||
public void OpenUI(string uiName, Type type, object param = null,
|
||||
Action<IUIPanel> callback = null)
|
||||
{
|
||||
UICommand.GetCmd(UICmdType.Show).SetUIData(type, uiName, param).SetCallback(callback).Run();
|
||||
}
|
||||
|
||||
internal void AddUI(string uiName, IUIPanel panel)
|
||||
{
|
||||
if (_uiArray.ContainsKey(uiName))
|
||||
{
|
||||
Log.Error("AddUI重复添加");
|
||||
}
|
||||
|
||||
_uiArray.Add(uiName, panel);
|
||||
}
|
||||
|
||||
public T GetUI<T>() where T : class
|
||||
{
|
||||
IUIPanel wind = null;
|
||||
Type type = typeof(T);
|
||||
var uiName = type.Name;
|
||||
foreach (var name in _uiArray.Keys)
|
||||
{
|
||||
if (name != uiName) continue;
|
||||
wind = _uiArray[name];
|
||||
break;
|
||||
}
|
||||
|
||||
return wind as T;
|
||||
}
|
||||
|
||||
public IUIPanel GetUI(Type type)
|
||||
{
|
||||
return GetUI(type.Name);
|
||||
}
|
||||
|
||||
public IUIPanel GetUI(string uiName)
|
||||
{
|
||||
IUIPanel wind = null;
|
||||
foreach (var name in _uiArray.Keys)
|
||||
{
|
||||
if (name != uiName) continue;
|
||||
wind = _uiArray[name];
|
||||
break;
|
||||
}
|
||||
|
||||
return wind;
|
||||
}
|
||||
|
||||
public IUIPanel[] GetAllUI()
|
||||
{
|
||||
return _uiArray.Values.ToArray();
|
||||
}
|
||||
|
||||
public List<string> GetAllUIName()
|
||||
{
|
||||
return _uiArray.Keys.ToList();
|
||||
}
|
||||
|
||||
public void HideUI(Type type)
|
||||
{
|
||||
HideUI(type.Name);
|
||||
}
|
||||
|
||||
public void HideUI<T>()
|
||||
{
|
||||
Type type = typeof(T);
|
||||
HideUI(type.Name);
|
||||
}
|
||||
|
||||
public void HideUI(string uiName)
|
||||
{
|
||||
UICommand.GetCmd(UICmdType.Hide).SetUIData(null, uiName, null).Run();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏所有窗口
|
||||
/// </summary>
|
||||
public void HideAllUI(bool isDotDel = false)
|
||||
{
|
||||
var names = GetAllUIName();
|
||||
foreach (var uiName in names)
|
||||
{
|
||||
IUIPanel panel = GetUI(uiName);
|
||||
if (panel.IsShowing)
|
||||
{
|
||||
if (!panel.IsDotDel || isDotDel)
|
||||
{
|
||||
HideUI(uiName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除所有打开的窗口
|
||||
/// </summary>
|
||||
public void DeleteAllUI()
|
||||
{
|
||||
var names = GetAllUIName();
|
||||
foreach (var uiName in names)
|
||||
{
|
||||
DestroyUI(uiName);
|
||||
}
|
||||
}
|
||||
|
||||
public void DestroyUI<T>()
|
||||
{
|
||||
Type type = typeof(T);
|
||||
DestroyUI(type.Name);
|
||||
}
|
||||
|
||||
public void DestroyUI(Type type)
|
||||
{
|
||||
DestroyUI(type.Name);
|
||||
}
|
||||
|
||||
public void DestroyUI(string uiName)
|
||||
{
|
||||
UICommand.GetCmd(UICmdType.Del).SetUIData(null, uiName, null).Run();
|
||||
}
|
||||
|
||||
public void BringToFront(IUIPanel uiPanel)
|
||||
{
|
||||
var uiRoot = GRoot.inst;
|
||||
var contentPane = uiPanel.ContentPane;
|
||||
if (contentPane.parent != uiRoot)
|
||||
{
|
||||
Log.Error("不在root内,无法置顶==");
|
||||
return;
|
||||
}
|
||||
|
||||
var cnt = uiRoot.numChildren;
|
||||
var i = 0;
|
||||
if (_modalLayer != null && _modalLayer.parent != null && !uiPanel.IsModal)
|
||||
{
|
||||
i = uiRoot.GetChildIndex(_modalLayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
i = cnt - 1;
|
||||
}
|
||||
|
||||
if (i >= 0)
|
||||
{
|
||||
uiRoot.SetChildIndex(contentPane, i);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsTop(IUIPanel uiPanel)
|
||||
{
|
||||
var parent = uiPanel.ContentPane.parent;
|
||||
if (parent == null) return false;
|
||||
var sortingOrder = uiPanel.ContentPane.sortingOrder;
|
||||
var maxIndex = -1;
|
||||
var panels = _uiArray.Values;
|
||||
foreach (var panel in panels)
|
||||
{
|
||||
if (panel.IsShowing && panel.ContentPane.sortingOrder == sortingOrder)
|
||||
{
|
||||
//只判断同层级的
|
||||
var index = parent.GetChildIndex(panel.ContentPane);
|
||||
if (index > maxIndex)
|
||||
{
|
||||
maxIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var uiIndex = parent.GetChildIndex(uiPanel.ContentPane);
|
||||
return uiIndex >= maxIndex;
|
||||
}
|
||||
|
||||
public void AdjustModalLayer()
|
||||
{
|
||||
if (_modalLayer == null || _modalLayer.isDisposed)
|
||||
{
|
||||
CreateModalLayer();
|
||||
}
|
||||
|
||||
var showDic = new Dictionary<GObject, IUIPanel>();
|
||||
var panels = _uiArray.Values;
|
||||
foreach (var panel in panels)
|
||||
{
|
||||
if (panel.IsShowing)
|
||||
{
|
||||
showDic[panel.ContentPane] = panel;
|
||||
}
|
||||
}
|
||||
|
||||
var cnt = _uiRoot.numChildren;
|
||||
for (var i = cnt - 1; i >= 0; i--)
|
||||
{
|
||||
var g = _uiRoot.GetChildAt(i);
|
||||
if (showDic.TryGetValue(g, out var panel))
|
||||
{
|
||||
if (panel.IsModal)
|
||||
{
|
||||
if (_modalLayer.parent == null)
|
||||
_uiRoot.AddChildAt(_modalLayer, i);
|
||||
else
|
||||
{
|
||||
_uiRoot.SetChildIndexBefore(_modalLayer, i);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_modalLayer != null && _modalLayer.parent != null)
|
||||
{
|
||||
_uiRoot.RemoveChild(_modalLayer);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsOpen(string uiName)
|
||||
{
|
||||
IUIPanel wind = GetUI(uiName);
|
||||
return wind != null && wind.IsShowing;
|
||||
}
|
||||
|
||||
public void AddPackage(string assetPath)
|
||||
{
|
||||
AddPackage(UIConst.UIPackRootUrl, assetPath);
|
||||
}
|
||||
|
||||
public void AddPackage(string root, string assetPath)
|
||||
{
|
||||
var path = root + assetPath;
|
||||
if (path.StartsWith("Assets/"))
|
||||
{
|
||||
UIPackage.AddPackage(path, (string name, string extension, Type type,
|
||||
out DestroyMethod method) =>
|
||||
{
|
||||
method = DestroyMethod.None;
|
||||
var pro = Assets.LoadAsset(name.Replace("\\", "/") + extension, type);
|
||||
return pro?.Asset;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
UIPackage.AddPackage(path);
|
||||
}
|
||||
// UIPackage.AddPackage(path);
|
||||
}
|
||||
|
||||
public void OpenSafeArea()
|
||||
{
|
||||
UIConst.OpenSafeArea = true;
|
||||
}
|
||||
|
||||
public void SetSafeArea(Rect rect)
|
||||
{
|
||||
UIConst.SafeArea = rect;
|
||||
}
|
||||
|
||||
public Rect GetSafeArea()
|
||||
{
|
||||
return UIConst.SafeArea;
|
||||
}
|
||||
|
||||
|
||||
public void SetUILanguage<T>() where T : UIComponentLanguagePack
|
||||
{
|
||||
_uiLanguageConfig = Activator.CreateInstance<T>();
|
||||
}
|
||||
|
||||
public void TrySetComponentLanguage(GComponent component)
|
||||
{
|
||||
_uiLanguageConfig.TrySetComponentLanguage(component);
|
||||
}
|
||||
|
||||
public void TrySetPanelLanguage(GComponent component)
|
||||
{
|
||||
_uiLanguageConfig.TrySetPanelLanguage(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/UI/Runtime/UIManager.cs.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/UIManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e062ec5ffbb4339b33d1d75a965f4c2
|
||||
timeCreated: 1607415282
|
||||
3
Assets/Scripts/NBC/UI/Runtime/UITween.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/UITween.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2fcace3b3ca4e21948ba0bce5002c82
|
||||
timeCreated: 1770173105
|
||||
7
Assets/Scripts/NBC/UI/Runtime/UITween/UIAnimTask.cs
Normal file
7
Assets/Scripts/NBC/UI/Runtime/UITween/UIAnimTask.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace NBC
|
||||
{
|
||||
public abstract class UIAnimTask : NTask
|
||||
{
|
||||
public abstract void SetDefaultInfo();
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/UI/Runtime/UITween/UIAnimTask.cs.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/UITween/UIAnimTask.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22a6b4eac2614a4e9d0872508f9f7249
|
||||
timeCreated: 1770179810
|
||||
103
Assets/Scripts/NBC/UI/Runtime/UITween/UIPackageTween.cs
Normal file
103
Assets/Scripts/NBC/UI/Runtime/UITween/UIPackageTween.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FairyGUI;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public class UIComponentTween : Dictionary<string, string>
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 组件动效配置包。与 UIComponentLanguagePack 结构类似,根据 resourceURL 映射到每个组件的子节点动效名称。
|
||||
/// </summary>
|
||||
public abstract class UIComponentTweenPack : Dictionary<string, UIComponentTween>
|
||||
{
|
||||
public bool Has(string url)
|
||||
{
|
||||
return ContainsKey(url);
|
||||
}
|
||||
|
||||
public void TryPlayComponentTween(GComponent component)
|
||||
{
|
||||
if (component == null || component.packageItem == null) return;
|
||||
if (!Has(component.resourceURL)) return;
|
||||
PlayComponentTween(component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 面板调用,不判断是否存在,根节点如果配置了 __root__ 会播放。
|
||||
/// </summary>
|
||||
public void TryPlayPanelTween(GComponent component)
|
||||
{
|
||||
if (component == null) return;
|
||||
PlayComponentTween(component);
|
||||
}
|
||||
|
||||
public string GetRootTween(string url)
|
||||
{
|
||||
if (TryGetValue(url, out var cfg) && cfg != null && cfg.TryGetValue("__root__", out var tween))
|
||||
return tween;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void PlayComponentTween(GComponent component)
|
||||
{
|
||||
if (component == null) return;
|
||||
bool comHasTweenConfig = false;
|
||||
UIComponentTween tweenCfg = null;
|
||||
if (component.packageItem != null && TryGetValue(component.resourceURL, out tweenCfg))
|
||||
{
|
||||
comHasTweenConfig = true;
|
||||
}
|
||||
|
||||
var count = component.numChildren;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var child = component.GetChildAt(i);
|
||||
if (child.packageItem != null && child is GComponent childCom)
|
||||
{
|
||||
PlayComponentTween(childCom); // 先递归子组件
|
||||
}
|
||||
|
||||
if (comHasTweenConfig)
|
||||
{
|
||||
var id = child.id;
|
||||
if (tweenCfg.TryGetValue(id, out var tweenName))
|
||||
{
|
||||
PlayTween(child, tweenName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 顶层UIPanel根节点动效改由 UIManager 设置 ShowAnim,不在这里直接播放
|
||||
if (component.parent == GRoot.inst) return;
|
||||
// if (comHasTweenConfig && tweenCfg.TryGetValue("__root__", out var rootTween))
|
||||
// {
|
||||
// PlayTween(component, rootTween);
|
||||
// }
|
||||
}
|
||||
|
||||
private static readonly Dictionary<string, Action<GObject>> TweenMap =
|
||||
new()
|
||||
{
|
||||
["Fade"] = o => o.TweenFadeShow(),
|
||||
["Scale"] = o => o.TweenScaleShow(),
|
||||
["Pop"] = o => o.TweenPopShow(),
|
||||
["SlideInL"] = o => o.TweenSlideInLeft(),
|
||||
["SlideInR"] = o => o.TweenSlideInRight(),
|
||||
["SlideInT"] = o => o.TweenSlideInTop(),
|
||||
["SlideInB"] = o => o.TweenSlideInBottom(),
|
||||
["Bounce"] = o => o.TweenBounceShow(),
|
||||
["Rotate"] = o => o.TweenRotateShow(),
|
||||
["Shake"] = o => o.TweenShake()
|
||||
};
|
||||
|
||||
private void PlayTween(GObject target, string tweenName)
|
||||
{
|
||||
if (target == null || string.IsNullOrEmpty(tweenName)) return;
|
||||
if (TweenMap.TryGetValue(tweenName, out var act))
|
||||
act(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7cd2e8cf13594c1fbef585689b1fbffa
|
||||
timeCreated: 1770173219
|
||||
266
Assets/Scripts/NBC/UI/Runtime/UITween/UIPanelAnimation.cs
Normal file
266
Assets/Scripts/NBC/UI/Runtime/UITween/UIPanelAnimation.cs
Normal file
@@ -0,0 +1,266 @@
|
||||
using FairyGUI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
/// <summary>
|
||||
/// ui界面默认动画
|
||||
/// </summary>
|
||||
public class PanelAnimationDef : UIAnimTask
|
||||
{
|
||||
public enum AnimType
|
||||
{
|
||||
CenterScaleBig = 0,
|
||||
|
||||
/// <summary>上往中滑动--</summary>
|
||||
UpToSlide = 1,
|
||||
|
||||
/// <summary>//下往中滑动</summary>
|
||||
DownToSlide = 2,
|
||||
|
||||
/// <summary>左往中--</summary>
|
||||
LeftToSlide = 3,
|
||||
|
||||
/// <summary>右往中--</summary>
|
||||
RightToSlide = 4,
|
||||
|
||||
/// <summary>透明度</summary>
|
||||
Fade = 5,
|
||||
|
||||
//
|
||||
CenterPopScaleFade = 6,
|
||||
UpToSlideFade = 7,
|
||||
DownToSlideFade = 8,
|
||||
LeftToSlideFade = 9,
|
||||
RightToSlideFade = 10,
|
||||
BounceVertical = 11,
|
||||
Rotate = 12,
|
||||
Shake = 13,
|
||||
}
|
||||
|
||||
private bool _isClose;
|
||||
private GComponent _node;
|
||||
private AnimType _animType;
|
||||
private float _animTime;
|
||||
|
||||
|
||||
public PanelAnimationDef(GComponent node, AnimType animType = AnimType.CenterScaleBig, bool close = false,
|
||||
float animTime = 0.5F)
|
||||
{
|
||||
_node = node;
|
||||
_isClose = close;
|
||||
_animType = animType;
|
||||
_animTime = animTime;
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
if (_node == null)
|
||||
{
|
||||
Finish();
|
||||
return;
|
||||
}
|
||||
|
||||
// 直接使用 UITweenDynamic 扩展方法处理新增复合效果
|
||||
switch (_animType)
|
||||
{
|
||||
case AnimType.CenterPopScaleFade:
|
||||
if (!_isClose)
|
||||
_node.TweenPopShow(callback: Finish);
|
||||
else
|
||||
_node.TweenPopHide(callback: Finish);
|
||||
return;
|
||||
case AnimType.UpToSlideFade:
|
||||
if (!_isClose)
|
||||
_node.TweenSlideInTop(callback: Finish);
|
||||
else
|
||||
_node.TweenSlideOutTop(callback: Finish);
|
||||
return;
|
||||
case AnimType.DownToSlideFade:
|
||||
if (!_isClose)
|
||||
_node.TweenSlideInBottom(callback: Finish);
|
||||
else
|
||||
_node.TweenSlideOutBottom(callback: Finish);
|
||||
return;
|
||||
case AnimType.LeftToSlideFade:
|
||||
if (!_isClose)
|
||||
_node.TweenSlideInLeft(callback: Finish);
|
||||
else
|
||||
_node.TweenSlideOutLeft(callback: Finish);
|
||||
return;
|
||||
case AnimType.RightToSlideFade:
|
||||
if (!_isClose)
|
||||
_node.TweenSlideInRight(callback: Finish);
|
||||
else
|
||||
_node.TweenSlideOutRight(callback: Finish);
|
||||
return;
|
||||
case AnimType.BounceVertical:
|
||||
if (!_isClose)
|
||||
_node.TweenBounceShow(callback: Finish); // 向上偏移进入
|
||||
else
|
||||
_node.TweenBounceHide(callback: Finish);
|
||||
return;
|
||||
case AnimType.Rotate:
|
||||
if (!_isClose)
|
||||
_node.TweenRotateShow(callback: Finish);
|
||||
else
|
||||
_node.TweenRotateHide(callback: Finish);
|
||||
return;
|
||||
case AnimType.Shake:
|
||||
// shake 只在打开时使用,关闭直接结束
|
||||
if (_isClose)
|
||||
{
|
||||
Finish();
|
||||
return;
|
||||
}
|
||||
|
||||
_node.TweenShakeShow(callback: Finish);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (_animType == AnimType.CenterScaleBig)
|
||||
{
|
||||
var strat = _isClose ? Vector3.one : Vector3.zero;
|
||||
var end = _isClose ? Vector3.zero : Vector3.one;
|
||||
var easeType = _isClose ? EaseType.BackIn : EaseType.BackOut;
|
||||
GTween.To(strat, end, _animTime)
|
||||
.SetEase(easeType)
|
||||
.SetTarget(_node, TweenPropType.Scale)
|
||||
.OnComplete(Finish);
|
||||
}
|
||||
else if (_animType == AnimType.UpToSlide || _animType == AnimType.DownToSlide)
|
||||
{
|
||||
var safeAreaY = UI.Inst.GetSafeArea().y;
|
||||
var hight = GRoot.inst.viewHeight;
|
||||
var y = _animType == AnimType.UpToSlide ? -hight : hight;
|
||||
var strat = _isClose ? 0 : y;
|
||||
var end = _isClose ? y : safeAreaY;
|
||||
GTween.To(strat, end, _animTime)
|
||||
.SetEase(EaseType.CubicOut)
|
||||
.SetTarget(_node, TweenPropType.Y)
|
||||
.OnComplete(Finish);
|
||||
}
|
||||
else if (_animType == AnimType.LeftToSlide || _animType == AnimType.RightToSlide)
|
||||
{
|
||||
var width = GRoot.inst.viewWidth;
|
||||
var x = _animType == AnimType.LeftToSlide ? -width : width;
|
||||
var strat = _isClose ? 0 : x;
|
||||
var end = _isClose ? x : 0;
|
||||
GTween.To(strat, end, _animTime)
|
||||
.SetEase(EaseType.CubicOut)
|
||||
.SetTarget(_node, TweenPropType.X)
|
||||
.OnComplete(Finish);
|
||||
}
|
||||
else if (_animType == AnimType.Fade)
|
||||
{
|
||||
var s = _isClose ? 1 : 0;
|
||||
var end = _isClose ? 0 : 1;
|
||||
_node.alpha = s;
|
||||
GTween.To(s, end, _animTime)
|
||||
.SetEase(EaseType.Linear)
|
||||
.SetTarget(_node, TweenPropType.Alpha)
|
||||
.OnComplete(Finish);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置默认的状态
|
||||
/// </summary>
|
||||
public override void SetDefaultInfo()
|
||||
{
|
||||
switch (_animType)
|
||||
{
|
||||
case AnimType.CenterScaleBig:
|
||||
_node.scale = _isClose ? Vector2.one : Vector2.zero;
|
||||
break;
|
||||
case AnimType.UpToSlide:
|
||||
case AnimType.DownToSlide:
|
||||
var hight = GRoot.inst.viewHeight;
|
||||
var y = _animType == AnimType.UpToSlide ? -hight : hight;
|
||||
_node.y = _isClose ? 0 : y;
|
||||
break;
|
||||
case AnimType.LeftToSlide:
|
||||
case AnimType.RightToSlide:
|
||||
var width = GRoot.inst.viewWidth;
|
||||
var x = _animType == AnimType.LeftToSlide ? -width : width;
|
||||
_node.x = _isClose ? 0 : x;
|
||||
break;
|
||||
case AnimType.Fade:
|
||||
_node.alpha = _isClose ? 1 : 0;
|
||||
break;
|
||||
case AnimType.CenterPopScaleFade:
|
||||
_node.scale = _isClose ? Vector2.one : new Vector2(0.8f, 0.8f);
|
||||
_node.alpha = _isClose ? 1 : 0;
|
||||
break;
|
||||
case AnimType.UpToSlideFade:
|
||||
|
||||
break;
|
||||
case AnimType.DownToSlideFade:
|
||||
|
||||
break;
|
||||
case AnimType.LeftToSlideFade:
|
||||
|
||||
break;
|
||||
case AnimType.RightToSlideFade:
|
||||
|
||||
break;
|
||||
case AnimType.BounceVertical:
|
||||
|
||||
break;
|
||||
case AnimType.Rotate:
|
||||
|
||||
break;
|
||||
case AnimType.Shake:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class UIPanelAnimation
|
||||
{
|
||||
public static UIAnimTask GetCenterScaleBig(IUIPanel panel, bool close = false, float animTime = 0.5F)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.CenterScaleBig, close, animTime);
|
||||
|
||||
public static UIAnimTask GetUpToSlide(IUIPanel panel, bool close = false, float animTime = 0.5F)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.UpToSlide, close, animTime);
|
||||
|
||||
public static UIAnimTask GetDownToSlide(IUIPanel panel, bool close = false, float animTime = 0.5F)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.DownToSlide, close, animTime);
|
||||
|
||||
public static UIAnimTask GetLeftToSlide(IUIPanel panel, bool close = false, float animTime = 0.5F)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.LeftToSlide, close, animTime);
|
||||
|
||||
public static UIAnimTask GetRightToSlide(IUIPanel panel, bool close = false, float animTime = 0.5F)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.RightToSlide, close, animTime);
|
||||
|
||||
public static UIAnimTask GetFade(IUIPanel panel, bool close = false, float animTime = 0.5F)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.Fade, close, animTime);
|
||||
|
||||
// 新增复合动效获取方法
|
||||
public static UIAnimTask GetCenterPopScaleFade(IUIPanel panel, bool close = false)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.CenterPopScaleFade, close);
|
||||
|
||||
public static UIAnimTask GetUpToSlideFade(IUIPanel panel, bool close = false)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.UpToSlideFade, close);
|
||||
|
||||
public static UIAnimTask GetDownToSlideFade(IUIPanel panel, bool close = false)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.DownToSlideFade, close);
|
||||
|
||||
public static UIAnimTask GetLeftToSlideFade(IUIPanel panel, bool close = false)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.LeftToSlideFade, close);
|
||||
|
||||
public static UIAnimTask GetRightToSlideFade(IUIPanel panel, bool close = false)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.RightToSlideFade, close);
|
||||
|
||||
public static UIAnimTask GetBounceVertical(IUIPanel panel, bool close = false)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.BounceVertical, close);
|
||||
|
||||
public static UIAnimTask GetRotate(IUIPanel panel, bool close = false)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.Rotate, close);
|
||||
|
||||
public static UIAnimTask GetShake(IUIPanel panel, bool close = false)
|
||||
=> new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.Shake, close);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 506db39b69774ef7bcafb6f744370e81
|
||||
timeCreated: 1607328227
|
||||
840
Assets/Scripts/NBC/UI/Runtime/UITween/UITweenDynamic.cs
Normal file
840
Assets/Scripts/NBC/UI/Runtime/UITween/UITweenDynamic.cs
Normal file
@@ -0,0 +1,840 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FairyGUI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public enum UISlideDirection
|
||||
{
|
||||
Left,
|
||||
Right,
|
||||
Top,
|
||||
Bottom
|
||||
}
|
||||
|
||||
public static class UITweenDynamic
|
||||
{
|
||||
private class TweenContext
|
||||
{
|
||||
public GObject target;
|
||||
public float alpha;
|
||||
public float scaleX;
|
||||
public float scaleY;
|
||||
public Vector3 position;
|
||||
public float rotation;
|
||||
public bool visible;
|
||||
public Action callback;
|
||||
}
|
||||
|
||||
private static readonly Dictionary<GObject, TweenContext> _contexts = new Dictionary<GObject, TweenContext>();
|
||||
|
||||
private static TweenContext Capture(GObject target, Action callback)
|
||||
{
|
||||
return new TweenContext
|
||||
{
|
||||
target = target,
|
||||
alpha = target.alpha,
|
||||
scaleX = target.scaleX,
|
||||
scaleY = target.scaleY,
|
||||
position = target.position,
|
||||
rotation = target.rotation,
|
||||
visible = target.visible,
|
||||
callback = callback
|
||||
};
|
||||
}
|
||||
|
||||
// 启动新动画:如存在旧动画,先还原并调用旧回调,再杀死旧 tweens,注册新上下文
|
||||
private static TweenContext StartNewAnimation(GObject target, Action newCallback)
|
||||
{
|
||||
if (target == null) return null;
|
||||
if (_contexts.TryGetValue(target, out var oldCtx))
|
||||
{
|
||||
// 还原旧动画状态
|
||||
if (oldCtx.target != null)
|
||||
{
|
||||
oldCtx.target.alpha = oldCtx.alpha;
|
||||
oldCtx.target.SetScale(oldCtx.scaleX, oldCtx.scaleY);
|
||||
oldCtx.target.position = oldCtx.position;
|
||||
oldCtx.target.rotation = oldCtx.rotation;
|
||||
oldCtx.target.visible = oldCtx.visible;
|
||||
}
|
||||
|
||||
// 调用旧动画的回调
|
||||
oldCtx.callback?.Invoke();
|
||||
_contexts.Remove(target);
|
||||
}
|
||||
|
||||
GTween.Kill(target);
|
||||
var ctx = Capture(target, newCallback);
|
||||
_contexts[target] = ctx;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
private static void FinishAnimation(GObject target)
|
||||
{
|
||||
if (target == null) return;
|
||||
if (_contexts.TryGetValue(target, out var ctx))
|
||||
{
|
||||
_contexts.Remove(target);
|
||||
ctx.callback?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
#region UIPanel UI动效 (wrappers)
|
||||
|
||||
public static void TweenFadeShow<T>(this T self, float duration = 0.45f, Action callback = null)
|
||||
where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenFadeShow(duration, callback);
|
||||
}
|
||||
|
||||
public static void TweenFadeHide<T>(this T self, float duration = 0.3f, Action callback = null)
|
||||
where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenFadeHide(duration, callback);
|
||||
}
|
||||
|
||||
public static void TweenScaleShow<T>(this T self, float duration = 0.3f,
|
||||
float fromScale = 0.8f, EaseType ease = EaseType.BackOut, Action callback = null) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
// GComponent.TweenScaleShow signature: (duration, callback, fromScale, ease)
|
||||
pane.TweenScaleShow(duration, callback, fromScale, ease);
|
||||
}
|
||||
|
||||
public static void TweenScaleHide<T>(this T self, float duration = 0.2f,
|
||||
float toScale = 0.8f, EaseType ease = EaseType.QuadIn, bool resetAfter = true, bool setInvisible = true,
|
||||
Action callback = null)
|
||||
where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
// GComponent.TweenScaleHide signature: (duration, callback, toScale, ease, resetAfter, setInvisible)
|
||||
pane.TweenScaleHide(duration, callback, toScale, ease, resetAfter, setInvisible);
|
||||
}
|
||||
|
||||
public static void TweenPopShow<T>(this T self, float duration = 0.2f,
|
||||
float fromScale = 0.8f, EaseType ease = EaseType.BackOut, Action callback = null) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenPopShow(duration, callback, fromScale, ease);
|
||||
}
|
||||
|
||||
public static void TweenPopHide<T>(this T self, float duration = 0.2f, Action callback = null,
|
||||
float toScale = 0.8f, EaseType ease = EaseType.QuadIn, bool setInvisible = true) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenPopHide(duration, callback, toScale, ease, setInvisible);
|
||||
}
|
||||
|
||||
public static void TweenSlideInLeft<T>(this T self, float moveTime = 0.5f, float startFadeTimeRate = 0.42f,
|
||||
float startAlpha = 0, float alphaTime = 0.1f, float extraOffset = 0f, EaseType ease = EaseType.CubicOut,
|
||||
Action callback = null) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenSlideInLeft(moveTime, startFadeTimeRate, startAlpha, alphaTime, extraOffset, ease, callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideOutLeft<T>(this T self, float moveTime = 0.3f, float startFadeTimeRate = 0,
|
||||
float alphaTime = 0.08f, float extraOffset = 0f, EaseType ease = EaseType.QuadIn,
|
||||
bool resetAfter = true, bool setInvisible = true, Action callback = null) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenSlideOutLeft(moveTime, startFadeTimeRate, alphaTime, extraOffset, ease, resetAfter, setInvisible,
|
||||
callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideInRight<T>(this T self, float moveTime = 0.5f, float startFadeTimeRate = 0.42f,
|
||||
float startAlpha = 0, float alphaTime = 0.1f, float extraOffset = 0f, EaseType ease = EaseType.CubicOut,
|
||||
Action callback = null) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenSlideInRight(moveTime, startFadeTimeRate, startAlpha, alphaTime, extraOffset, ease, callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideOutRight<T>(this T self, float moveTime = 0.3f, float startFadeTimeRate = 0,
|
||||
float alphaTime = 0.08f, float extraOffset = 0f, EaseType ease = EaseType.QuadIn,
|
||||
bool resetAfter = true, bool setInvisible = true, Action callback = null) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenSlideOutRight(moveTime, startFadeTimeRate, alphaTime, extraOffset, ease, resetAfter, setInvisible,
|
||||
callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideInTop<T>(this T self, float moveTime = 0.35f, float startFadeTimeRate = 0.3f,
|
||||
float startAlpha = 0, float alphaTime = 0.1f, float extraOffset = 0f, EaseType ease = EaseType.CubicOut,
|
||||
Action callback = null) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenSlideInTop(moveTime, startFadeTimeRate, startAlpha, alphaTime, extraOffset, ease, callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideOutTop<T>(this T self, float moveTime = 0.3f, float startFadeTimeRate = 0,
|
||||
float alphaTime = 0.1f, float extraOffset = 0f, EaseType ease = EaseType.QuadIn,
|
||||
bool resetAfter = true, bool setInvisible = true, Action callback = null) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenSlideOutTop(moveTime, startFadeTimeRate, alphaTime, extraOffset, ease, resetAfter, setInvisible,
|
||||
callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideInBottom<T>(this T self, float moveTime = 0.35f, float startFadeTimeRate = 0.3f,
|
||||
float startAlpha = 0, float alphaTime = 0.1f, float extraOffset = 0f, EaseType ease = EaseType.CubicOut,
|
||||
Action callback = null) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenSlideInBottom(moveTime, startFadeTimeRate, startAlpha, alphaTime, extraOffset, ease, callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideOutBottom<T>(this T self, float moveTime = 0.3f, float startFadeTimeRate = 0,
|
||||
float alphaTime = 0.1f, float extraOffset = 0f, EaseType ease = EaseType.QuadIn, bool resetAfter = true,
|
||||
bool setInvisible = true, Action callback = null) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenSlideOutBottom(moveTime, startFadeTimeRate, alphaTime, extraOffset, ease, resetAfter,
|
||||
setInvisible, callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideIn<T>(this T self, UISlideDirection direction, float moveTime = 0.35f,
|
||||
float startFadeTimeRate = 0.1f,
|
||||
float startAlpha = 0, float alphaTime = 0.2f, float extraOffset = 0f, EaseType ease = EaseType.QuadOut,
|
||||
Action callback = null) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenSlideIn(direction, moveTime, startFadeTimeRate, startAlpha, alphaTime, extraOffset, ease,
|
||||
callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideOut<T>(this T self, UISlideDirection direction, float moveTime = 0.35f,
|
||||
float startFadeTimeRate = 0.1f,
|
||||
float alphaTime = 0.2f, float extraOffset = 0f, EaseType ease = EaseType.QuadIn, bool resetAfter = true,
|
||||
bool setInvisible = true, Action callback = null) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenSlideOut(direction, moveTime, startFadeTimeRate, alphaTime, extraOffset, ease, resetAfter,
|
||||
setInvisible, callback);
|
||||
}
|
||||
|
||||
public static void TweenBounceShow<T>(this T self, float duration = 0.4f, Action callback = null,
|
||||
float fromYOffset = -100f) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenBounceShow(duration, callback, fromYOffset);
|
||||
}
|
||||
|
||||
public static void TweenBounceHide<T>(this T self, float duration = 0.25f, Action callback = null,
|
||||
float toYOffset = 100f, bool resetAfter = true, bool setInvisible = true) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenBounceHide(duration, callback, toYOffset, resetAfter, setInvisible);
|
||||
}
|
||||
|
||||
public static void TweenRotateShow<T>(this T self, float duration = 0.2f, Action callback = null,
|
||||
float fromRotation = -90f, EaseType ease = EaseType.BackOut) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenRotateShow(duration, callback, fromRotation, ease);
|
||||
}
|
||||
|
||||
public static void TweenRotateHide<T>(this T self, float duration = 0.2f, Action callback = null,
|
||||
float toRotation = -90f, EaseType ease = EaseType.QuadIn, bool resetAfter = true, bool setInvisible = true)
|
||||
where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenRotateHide(duration, callback, toRotation, ease, resetAfter, setInvisible);
|
||||
}
|
||||
|
||||
public static void TweenShake<T>(this T self, float duration = 0.4f, Action callback = null,
|
||||
float amplitude = 12f, bool horizontal = true, int vibrato = 6) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenShake(duration, callback, amplitude, horizontal, vibrato);
|
||||
}
|
||||
|
||||
public static void TweenShakeShow<T>(this T self, float durationScale = 0.2f, float ScaleStart = 0.3f,
|
||||
float ScaleEnd = 1f, int shake = 4,
|
||||
float shakeRotation = 18f, float duration = 1, Action callback = null) where T : IUIPanel
|
||||
{
|
||||
var pane = self?.ContentPane;
|
||||
if (pane == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
pane.TweenShakeShow(durationScale, ScaleStart, ScaleEnd, shake, shakeRotation, duration, callback);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GComponent UI动效
|
||||
|
||||
public static void TweenFadeShow(this GObject self, float duration = 0.45f, Action callback = null)
|
||||
{
|
||||
if (self == null || duration <= 0f)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
self.alpha = 0f;
|
||||
self.TweenFade(1f, duration).OnComplete(() => { FinishAnimation(self); });
|
||||
}
|
||||
|
||||
public static void TweenFadeHide(this GObject self, float duration = 0.3f, Action callback = null)
|
||||
{
|
||||
if (self == null || duration <= 0f)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
self.alpha = 1f;
|
||||
self.TweenFade(0f, duration).OnComplete(() => { FinishAnimation(self); });
|
||||
}
|
||||
|
||||
public static void TweenScaleShow(this GObject self, float duration = 0.3f, Action callback = null,
|
||||
float fromScale = 0f, EaseType ease = EaseType.BackOut)
|
||||
{
|
||||
if (self == null || duration <= 0f)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
self.SetPivot(0.5f, 0.5f, false);
|
||||
self.SetScale(0, 0);
|
||||
var ox = self.scaleX;
|
||||
var oy = self.scaleY;
|
||||
self.visible = true;
|
||||
self.SetScale(fromScale, fromScale);
|
||||
self.TweenScale(new Vector2(ox, oy), duration).SetEase(ease).OnComplete(() => { FinishAnimation(self); });
|
||||
}
|
||||
|
||||
public static void TweenScaleHide(this GObject self, float duration = 0.2f, Action callback = null,
|
||||
float toScale = 0.8f, EaseType ease = EaseType.QuadIn, bool resetAfter = true, bool setInvisible = true)
|
||||
{
|
||||
if (self == null || duration <= 0f)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
self.SetPivot(0.5f, 0.5f, false);
|
||||
self.SetScale(1, 1);
|
||||
var ox = self.scaleX;
|
||||
var oy = self.scaleY;
|
||||
self.TweenScale(new Vector2(toScale, toScale), duration).SetEase(ease).OnComplete(() =>
|
||||
{
|
||||
if (resetAfter) self.SetScale(ox, oy);
|
||||
if (setInvisible) self.visible = false;
|
||||
FinishAnimation(self);
|
||||
});
|
||||
}
|
||||
|
||||
public static void TweenPopShow(this GObject self, float duration = 0.2f, Action callback = null,
|
||||
float fromScale = 0.8f, EaseType ease = EaseType.BackOut)
|
||||
{
|
||||
if (self == null || duration <= 0f)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
var ox = self.scaleX;
|
||||
var oy = self.scaleY;
|
||||
self.visible = true;
|
||||
self.SetScale(fromScale, fromScale);
|
||||
self.alpha = 0f;
|
||||
int remain = 2;
|
||||
|
||||
void Done()
|
||||
{
|
||||
if (--remain == 0) FinishAnimation(self);
|
||||
}
|
||||
|
||||
self.TweenScale(new Vector2(ox, oy), duration).SetEase(ease).OnComplete(Done);
|
||||
self.TweenFade(1f, duration * 0.9f).SetEase(EaseType.QuadOut).OnComplete(Done);
|
||||
}
|
||||
|
||||
public static void TweenPopHide(this GObject self, float duration = 0.2f, Action callback = null,
|
||||
float toScale = 0.8f, EaseType ease = EaseType.QuadIn, bool setInvisible = true)
|
||||
{
|
||||
if (self == null || duration <= 0f)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
var ox = self.scaleX;
|
||||
var oy = self.scaleY;
|
||||
int remain = 2;
|
||||
|
||||
void Done()
|
||||
{
|
||||
if (--remain == 0)
|
||||
{
|
||||
self.SetScale(ox, oy);
|
||||
if (setInvisible) self.visible = false;
|
||||
FinishAnimation(self);
|
||||
}
|
||||
}
|
||||
|
||||
self.TweenScale(new Vector2(toScale, toScale), duration).SetEase(ease).OnComplete(Done);
|
||||
self.TweenFade(0f, duration * 0.9f).SetEase(EaseType.QuadIn).OnComplete(Done);
|
||||
}
|
||||
|
||||
public static void TweenSlideInLeft(this GObject self, float moveTime = 0.5f, float startFadeTimeRate = 0.42f
|
||||
, float startAlpha = 0, float alphaTime = 0.1f
|
||||
, float extraOffset = 0f, EaseType ease = EaseType.CubicOut,
|
||||
Action callback = null)
|
||||
{
|
||||
TweenSlideIn(self, UISlideDirection.Left, moveTime, startFadeTimeRate, startAlpha, alphaTime, extraOffset,
|
||||
ease, callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideOutLeft(this GObject self, float moveTime = 0.3f, float startFadeTimeRate = 0
|
||||
, float alphaTime = 0.08f,
|
||||
float extraOffset = 0f, EaseType ease = EaseType.QuadIn,
|
||||
bool resetAfter = true, bool setInvisible = true,
|
||||
Action callback = null)
|
||||
{
|
||||
TweenSlideOut(self, UISlideDirection.Left, moveTime, startFadeTimeRate, alphaTime, extraOffset, ease,
|
||||
resetAfter, setInvisible, callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideInRight(this GObject self, float moveTime = 0.5f, float startFadeTimeRate = 0.42f
|
||||
, float startAlpha = 0, float alphaTime = 0.1f
|
||||
, float extraOffset = 0f, EaseType ease = EaseType.CubicOut,
|
||||
Action callback = null)
|
||||
{
|
||||
TweenSlideIn(self, UISlideDirection.Right, moveTime, startFadeTimeRate, startAlpha, alphaTime, extraOffset,
|
||||
ease, callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideOutRight(this GObject self, float moveTime = 0.3f, float startFadeTimeRate = 0
|
||||
, float alphaTime = 0.08f,
|
||||
float extraOffset = 0f, EaseType ease = EaseType.QuadIn,
|
||||
bool resetAfter = true, bool setInvisible = true,
|
||||
Action callback = null)
|
||||
{
|
||||
TweenSlideOut(self, UISlideDirection.Right, moveTime, startFadeTimeRate, alphaTime, extraOffset, ease,
|
||||
resetAfter, setInvisible, callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideInTop(this GObject self, float moveTime = 0.35f, float startFadeTimeRate = 0.3f
|
||||
, float startAlpha = 0, float alphaTime = 0.1f
|
||||
, float extraOffset = 0f, EaseType ease = EaseType.CubicOut,
|
||||
Action callback = null)
|
||||
{
|
||||
TweenSlideIn(self, UISlideDirection.Top, moveTime, startFadeTimeRate, startAlpha, alphaTime, extraOffset,
|
||||
ease, callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideOutTop(this GObject self, float moveTime = 0.3f, float startFadeTimeRate = 0
|
||||
, float alphaTime = 0.1f,
|
||||
float extraOffset = 0f, EaseType ease = EaseType.QuadIn,
|
||||
bool resetAfter = true, bool setInvisible = true,
|
||||
Action callback = null)
|
||||
{
|
||||
TweenSlideOut(self, UISlideDirection.Top, moveTime, startFadeTimeRate, alphaTime, extraOffset, ease,
|
||||
resetAfter, setInvisible, callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideInBottom(this GObject self, float moveTime = 0.35f, float startFadeTimeRate = 0.3f
|
||||
, float startAlpha = 0, float alphaTime = 0.1f
|
||||
, float extraOffset = 0f, EaseType ease = EaseType.CubicOut,
|
||||
Action callback = null)
|
||||
{
|
||||
TweenSlideIn(self, UISlideDirection.Bottom, moveTime, startFadeTimeRate, startAlpha, alphaTime, extraOffset,
|
||||
ease, callback);
|
||||
}
|
||||
|
||||
public static void TweenSlideOutBottom(this GObject self, float moveTime = 0.3f, float startFadeTimeRate = 0
|
||||
, float alphaTime = 0.1f,
|
||||
float extraOffset = 0f, EaseType ease = EaseType.QuadIn,
|
||||
bool resetAfter = true, bool setInvisible = true,
|
||||
Action callback = null)
|
||||
{
|
||||
TweenSlideOut(self, UISlideDirection.Bottom, moveTime, startFadeTimeRate, alphaTime, extraOffset, ease,
|
||||
resetAfter, setInvisible, callback);
|
||||
}
|
||||
|
||||
|
||||
public static void TweenSlideIn(this GObject self, UISlideDirection direction, float moveTime = 0.35f,
|
||||
float startFadeTimeRate = 0.1f
|
||||
, float startAlpha = 0, float alphaTime = 0.2f
|
||||
, float extraOffset = 0f, EaseType ease = EaseType.QuadOut,
|
||||
Action callback = null)
|
||||
{
|
||||
if (self == null || moveTime <= 0f)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
var ori = self.position;
|
||||
float startX = ori.x;
|
||||
float startY = ori.y;
|
||||
switch (direction)
|
||||
{
|
||||
case UISlideDirection.Left: startX = startX + (-self.width / 2) - Math.Max(0f, extraOffset); break;
|
||||
case UISlideDirection.Right: startX = startX + (self.width / 2) + Math.Max(0f, extraOffset); break;
|
||||
case UISlideDirection.Top: startY = startY + (-self.height / 2) - Math.Max(0f, extraOffset); break;
|
||||
case UISlideDirection.Bottom: startY = startY + (self.height / 2) + Math.Max(0f, extraOffset); break;
|
||||
}
|
||||
|
||||
self.visible = true;
|
||||
self.alpha = startAlpha;
|
||||
self.position = new Vector3(startX, startY, ori.z);
|
||||
float startFadeTime = moveTime * startFadeTimeRate;
|
||||
int remain = 3;
|
||||
|
||||
void Done()
|
||||
{
|
||||
if (--remain == 0) FinishAnimation(self);
|
||||
}
|
||||
|
||||
GTweener moveTweener = (direction == UISlideDirection.Left || direction == UISlideDirection.Right)
|
||||
? self.TweenMoveX(ori.x, moveTime)
|
||||
: self.TweenMoveY(ori.y, moveTime);
|
||||
moveTweener.SetEase(ease).OnComplete(Done);
|
||||
self.TweenFade(startAlpha, startFadeTime).OnComplete(() =>
|
||||
{
|
||||
Done();
|
||||
self.TweenFade(1, alphaTime).SetEase(EaseType.QuadOut).OnComplete(Done);
|
||||
});
|
||||
}
|
||||
|
||||
public static void TweenSlideOut(this GObject self, UISlideDirection direction, float moveTime = 0.35f,
|
||||
float startFadeTimeRate = 0.1f
|
||||
, float alphaTime = 0.2f,
|
||||
float extraOffset = 0f, EaseType ease = EaseType.QuadIn,
|
||||
bool resetAfter = true, bool setInvisible = true,
|
||||
Action callback = null)
|
||||
{
|
||||
if (self == null || moveTime <= 0f)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
var ori = self.position;
|
||||
float endX = ori.x;
|
||||
float endY = ori.y;
|
||||
switch (direction)
|
||||
{
|
||||
case UISlideDirection.Left: endX = endX + (-self.width / 2) - Math.Max(0f, extraOffset); break;
|
||||
case UISlideDirection.Right: endX = endX + (self.width / 2) + Math.Max(0f, extraOffset); break;
|
||||
case UISlideDirection.Top: endY = endX + (-self.height / 2) - Math.Max(0f, extraOffset); break;
|
||||
case UISlideDirection.Bottom: endY = endX + (self.height / 2) + Math.Max(0f, extraOffset); break;
|
||||
}
|
||||
|
||||
float startAlpha = self.alpha;
|
||||
float startFadeTime = moveTime * startFadeTimeRate;
|
||||
int remain = 3;
|
||||
|
||||
void Done()
|
||||
{
|
||||
if (--remain == 0)
|
||||
{
|
||||
if (resetAfter) self.position = ori;
|
||||
if (setInvisible) self.visible = false;
|
||||
FinishAnimation(self);
|
||||
}
|
||||
}
|
||||
|
||||
GTweener moveTweener = (direction == UISlideDirection.Left || direction == UISlideDirection.Right)
|
||||
? self.TweenMoveX(endX, moveTime)
|
||||
: self.TweenMoveY(endY, moveTime);
|
||||
moveTweener.SetEase(ease).OnComplete(Done);
|
||||
|
||||
self.TweenFade(startAlpha, startFadeTime).OnComplete(() =>
|
||||
{
|
||||
Done();
|
||||
self.TweenFade(0, alphaTime).SetEase(EaseType.QuadOut).OnComplete(Done);
|
||||
});
|
||||
}
|
||||
|
||||
public static void TweenBounceShow(this GObject self, float duration = 0.4f, Action callback = null,
|
||||
float fromYOffset = -100f)
|
||||
{
|
||||
if (self == null || duration <= 0f)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
var ori = self.position;
|
||||
self.visible = true;
|
||||
self.position = new Vector3(ori.x, ori.y + fromYOffset, ori.z);
|
||||
self.TweenMoveY(ori.y, duration).SetEase(EaseType.BounceOut).OnComplete(() => { FinishAnimation(self); });
|
||||
}
|
||||
|
||||
public static void TweenBounceHide(this GObject self, float duration = 0.25f, Action callback = null,
|
||||
float toYOffset = 100f, bool resetAfter = true, bool setInvisible = true)
|
||||
{
|
||||
if (self == null || duration <= 0f)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
var ori = self.position;
|
||||
self.TweenMoveY(ori.y + toYOffset, duration).SetEase(EaseType.QuadIn).OnComplete(() =>
|
||||
{
|
||||
if (resetAfter) self.position = ori;
|
||||
if (setInvisible) self.visible = false;
|
||||
FinishAnimation(self);
|
||||
});
|
||||
}
|
||||
|
||||
public static void TweenRotateShow(this GObject self, float duration = 0.2f, Action callback = null,
|
||||
float fromRotation = -90f, EaseType ease = EaseType.BackOut)
|
||||
{
|
||||
if (self == null || duration <= 0f)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
float ori = self.rotation;
|
||||
self.visible = true;
|
||||
self.rotation = fromRotation;
|
||||
self.TweenRotate(ori, duration).SetEase(ease).OnComplete(() => { FinishAnimation(self); });
|
||||
}
|
||||
|
||||
public static void TweenRotateHide(this GObject self, float duration = 0.2f, Action callback = null,
|
||||
float toRotation = -90f, EaseType ease = EaseType.QuadIn, bool resetAfter = true, bool setInvisible = true)
|
||||
{
|
||||
if (self == null || duration <= 0f)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
float ori = self.rotation;
|
||||
self.TweenRotate(toRotation, duration).SetEase(ease).OnComplete(() =>
|
||||
{
|
||||
if (resetAfter) self.rotation = ori;
|
||||
if (setInvisible) self.visible = false;
|
||||
FinishAnimation(self);
|
||||
});
|
||||
}
|
||||
|
||||
public static void TweenShake(this GObject self, float duration = 0.4f, Action callback = null,
|
||||
float amplitude = 12f, bool horizontal = true, int vibrato = 6)
|
||||
{
|
||||
if (self == null || vibrato <= 0 || amplitude <= 0f || duration <= 0f)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
var ori = self.position;
|
||||
float single = duration / (vibrato * 2f);
|
||||
var end = horizontal
|
||||
? new Vector3(ori.x + amplitude, ori.y, ori.z)
|
||||
: new Vector3(ori.x, ori.y + amplitude, ori.z);
|
||||
self.TweenMove(end, single).SetEase(EaseType.Linear).SetRepeat(vibrato * 2, true).OnComplete(() =>
|
||||
{
|
||||
self.position = ori;
|
||||
FinishAnimation(self);
|
||||
});
|
||||
}
|
||||
|
||||
public static void TweenShakeShow(this GObject self, float durationScale = 0.2f, float ScaleStart = 0.3f,
|
||||
float ScaleEnd = 1f, int shake = 4,
|
||||
float shakeRotation = 18f, float duration = 1, Action callback = null)
|
||||
{
|
||||
if (self == null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
StartNewAnimation(self, callback);
|
||||
|
||||
int remain = 4;
|
||||
|
||||
void Done()
|
||||
{
|
||||
if (--remain == 0)
|
||||
{
|
||||
FinishAnimation(self);
|
||||
}
|
||||
}
|
||||
|
||||
self.scale = Vector2.one * ScaleStart;
|
||||
self.rotation = -shakeRotation;
|
||||
|
||||
float scaleEndTime = 0.2f;
|
||||
float rotaEndTime = 0.1f;
|
||||
float allIns = durationScale + scaleEndTime + rotaEndTime;
|
||||
duration = allIns > duration ? allIns : duration;
|
||||
|
||||
float rotaTime = (duration - durationScale - scaleEndTime - rotaEndTime) / shake;
|
||||
self.TweenScale(Vector2.one * ScaleEnd * 1.1f, durationScale)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
FinishAnimation(self);
|
||||
self.TweenRotate(shakeRotation, rotaTime).SetRepeat(shake, true)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
FinishAnimation(self);
|
||||
self.TweenRotate(0, rotaEndTime).OnComplete(() =>
|
||||
{
|
||||
FinishAnimation(self);
|
||||
self.TweenScale(Vector2.one * ScaleEnd, scaleEndTime).OnComplete(() =>
|
||||
{
|
||||
FinishAnimation(self);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0b1d4565de947b99f0a88d7753e8897
|
||||
timeCreated: 1770172925
|
||||
3
Assets/Scripts/NBC/UI/Runtime/Utils.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/Utils.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 553ce3a74f9346a2967b868fc9dec118
|
||||
timeCreated: 1683269938
|
||||
16
Assets/Scripts/NBC/UI/Runtime/Utils/UIRunner.cs
Normal file
16
Assets/Scripts/NBC/UI/Runtime/Utils/UIRunner.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace NBC
|
||||
{
|
||||
internal static class UIRunner
|
||||
{
|
||||
#region Static
|
||||
|
||||
public static readonly Runner Def = new Runner();
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
Def.Process();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/UI/Runtime/Utils/UIRunner.cs.meta
Normal file
3
Assets/Scripts/NBC/UI/Runtime/Utils/UIRunner.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43f3556ed98c4f62bcb1711410d01868
|
||||
timeCreated: 1683269953
|
||||
Reference in New Issue
Block a user