NBC修改
This commit is contained in:
154
Assets/Scripts/NBC/Runtime/UI/Extension/UIAnimExtension.cs
Normal file
154
Assets/Scripts/NBC/Runtime/UI/Extension/UIAnimExtension.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using System.Threading.Tasks;
|
||||
using FairyGUI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public static class UIAnimExtension
|
||||
{
|
||||
public static FTask ShowCenterScaleBig(this UIPanel panel)
|
||||
{
|
||||
return CenterScaleBigAnim(panel, false);
|
||||
}
|
||||
|
||||
public static FTask HideCenterScaleBig(this UIPanel panel)
|
||||
{
|
||||
return CenterScaleBigAnim(panel, true);
|
||||
}
|
||||
|
||||
public static FTask ShowUpToSlide(this UIPanel panel)
|
||||
{
|
||||
return GetUpToSlide(panel, false);
|
||||
}
|
||||
|
||||
public static FTask HideUpToSlide(this UIPanel panel)
|
||||
{
|
||||
return GetUpToSlide(panel, true);
|
||||
}
|
||||
|
||||
public static FTask ShowDownToSlide(this UIPanel panel)
|
||||
{
|
||||
return GetDownToSlide(panel, false);
|
||||
}
|
||||
|
||||
public static FTask HideDownToSlide(this UIPanel panel)
|
||||
{
|
||||
return GetDownToSlide(panel, true);
|
||||
}
|
||||
|
||||
public static FTask ShowLeftToSlide(this UIPanel panel)
|
||||
{
|
||||
return GetLeftToSlide(panel, false);
|
||||
}
|
||||
|
||||
public static FTask HideLeftToSlide(this UIPanel panel)
|
||||
{
|
||||
return GetLeftToSlide(panel, true);
|
||||
}
|
||||
|
||||
|
||||
public static FTask ShowRightToSlide(this UIPanel panel)
|
||||
{
|
||||
return GetRightToSlide(panel, false);
|
||||
}
|
||||
|
||||
public static FTask HideRightToSlide(this UIPanel panel)
|
||||
{
|
||||
return GetRightToSlide(panel, true);
|
||||
}
|
||||
|
||||
public static FTask ShowFade(this UIPanel panel)
|
||||
{
|
||||
return GetFade(panel, false);
|
||||
}
|
||||
|
||||
public static FTask HideFade(this UIPanel panel)
|
||||
{
|
||||
return GetFade(panel, true);
|
||||
}
|
||||
|
||||
private static async FTask CenterScaleBigAnim(UIPanel panel, bool close = false)
|
||||
{
|
||||
var strat = close ? Vector3.one : Vector3.zero;
|
||||
var end = close ? Vector3.zero : Vector3.one;
|
||||
var easeType = close ? EaseType.BackIn : EaseType.BackOut;
|
||||
|
||||
|
||||
GTween.To(strat, end, 0.5f)
|
||||
.SetEase(easeType)
|
||||
.SetTarget(panel.ContentPane, TweenPropType.Scale);
|
||||
await Task.Delay(500);
|
||||
}
|
||||
|
||||
public static async FTask GetUpToSlide(UIPanel panel, bool close = false)
|
||||
{
|
||||
var hight = GRoot.inst.viewHeight;
|
||||
var y = -hight;
|
||||
var strat = close ? 0 : y;
|
||||
var end = close ? y : 0;
|
||||
|
||||
GTween.To(strat, end, 0.5f)
|
||||
.SetEase(EaseType.CubicOut)
|
||||
.SetTarget(panel.ContentPane, TweenPropType.Y);
|
||||
await Task.Delay(500);
|
||||
}
|
||||
|
||||
public static async FTask GetDownToSlide(UIPanel panel, bool close = false)
|
||||
{
|
||||
var hight = GRoot.inst.viewHeight;
|
||||
var y = hight;
|
||||
var strat = close ? 0 : y;
|
||||
var end = close ? y : 0;
|
||||
|
||||
GTween.To(strat, end, 0.5f)
|
||||
.SetEase(EaseType.CubicOut)
|
||||
.SetTarget(panel.ContentPane, TweenPropType.Y);
|
||||
// await App.Main.TimerComponent.Net.WaitAsync(500);
|
||||
await Task.Delay(500);
|
||||
}
|
||||
|
||||
public static async FTask GetLeftToSlide(UIPanel panel, bool close = false)
|
||||
{
|
||||
var width = GRoot.inst.viewWidth;
|
||||
|
||||
var x = -width;
|
||||
|
||||
var strat = close ? 0 : x;
|
||||
var end = close ? x : 0;
|
||||
|
||||
GTween.To(strat, end, 0.5f)
|
||||
.SetEase(EaseType.CubicOut)
|
||||
.SetTarget(panel.ContentPane, TweenPropType.X);
|
||||
// await App.Main.TimerComponent.Net.WaitAsync(500);
|
||||
await Task.Delay(500);
|
||||
}
|
||||
|
||||
public static async FTask GetRightToSlide(UIPanel panel, bool close = false)
|
||||
{
|
||||
var width = GRoot.inst.viewWidth;
|
||||
|
||||
var x = width;
|
||||
|
||||
var strat = close ? 0 : x;
|
||||
var end = close ? x : 0;
|
||||
|
||||
GTween.To(strat, end, 0.5f)
|
||||
.SetEase(EaseType.CubicOut)
|
||||
.SetTarget(panel.ContentPane, TweenPropType.X);
|
||||
// await App.Main.TimerComponent.Net.WaitAsync(500);
|
||||
await Task.Delay(500);
|
||||
}
|
||||
|
||||
public static async FTask GetFade(UIPanel panel, bool close = false)
|
||||
{
|
||||
var s = close ? 1 : 0;
|
||||
var end = close ? 0 : 1;
|
||||
panel.ContentPane.alpha = s;
|
||||
GTween.To(s, end, 0.5f)
|
||||
.SetEase(EaseType.Linear)
|
||||
.SetTarget(panel, TweenPropType.Alpha);
|
||||
// await App.Main.TimerComponent.Net.WaitAsync(500);
|
||||
await Task.Delay(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d68bf7e0471c4863857235883fdd933e
|
||||
timeCreated: 1751445462
|
||||
122
Assets/Scripts/NBC/Runtime/UI/Extension/UIExtension.cs
Normal file
122
Assets/Scripts/NBC/Runtime/UI/Extension/UIExtension.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6e1faca2d324be59996ac7b326ac9a7
|
||||
timeCreated: 1607073126
|
||||
Reference in New Issue
Block a user