NBC修改
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e54d4b9d5d9fd9c4bae1cd40f3d9698d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65441e72d19f4334b7d4e9748762839e
|
||||
timeCreated: 1607069598
|
||||
@@ -1,11 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true)]
|
||||
public class AutoFindAttribute : Attribute
|
||||
{
|
||||
public string Name;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 370e0f8ad369463ca826cbb7c3d2cc21
|
||||
timeCreated: 1607069612
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cf70d9f97294cf284d2a538d95c762c
|
||||
timeCreated: 1606991848
|
||||
@@ -1,42 +0,0 @@
|
||||
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; }
|
||||
|
||||
/// <summary>
|
||||
/// 不能返回
|
||||
/// </summary>
|
||||
bool IsDontBack { get; }
|
||||
|
||||
bool IsModal { get; }
|
||||
|
||||
bool IsShowCursor { get; }
|
||||
|
||||
void SetUIManager(UIManager kit);
|
||||
void SetData(object args);
|
||||
object GetData();
|
||||
string[] GetDependPackages();
|
||||
|
||||
void Init();
|
||||
void Show();
|
||||
void Hide();
|
||||
void Update();
|
||||
void HideImmediately();
|
||||
void Refresh();
|
||||
void Dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85e70ef2de904307919fe91865311fc1
|
||||
timeCreated: 1606989126
|
||||
@@ -1,308 +0,0 @@
|
||||
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 bool IsDontBack { 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 NTask ShowAnim = null;
|
||||
|
||||
/// <summary>
|
||||
/// 面板关闭动画
|
||||
/// </summary>
|
||||
public NTask 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);
|
||||
_ui.AdjustModalLayer();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!IsTop) _ui.BringToFront(this);
|
||||
}
|
||||
|
||||
OpenAnimBegin();
|
||||
if (ShowAnim != null)
|
||||
{
|
||||
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.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
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6717340027374964a13049a5b6f18c2f
|
||||
timeCreated: 1606992345
|
||||
@@ -1,139 +0,0 @@
|
||||
using FairyGUI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
/// <summary>
|
||||
/// ui界面默认动画
|
||||
/// </summary>
|
||||
public class PanelAnimationDef : NTask
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
private bool _isClose;
|
||||
private GComponent _node;
|
||||
private AnimType _animType;
|
||||
|
||||
|
||||
public PanelAnimationDef(GComponent node, AnimType animType = AnimType.CenterScaleBig, bool close = false)
|
||||
{
|
||||
_node = node;
|
||||
_isClose = close;
|
||||
_animType = animType;
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
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, 0.5f)
|
||||
.SetEase(easeType)
|
||||
.SetTarget(_node, TweenPropType.Scale)
|
||||
.OnComplete(Finish);
|
||||
}
|
||||
else if (_animType == AnimType.UpToSlide || _animType == AnimType.DownToSlide)
|
||||
{
|
||||
var hight = GRoot.inst.viewHeight;
|
||||
var y = _animType == AnimType.UpToSlide ? -hight : hight;
|
||||
var strat = _isClose ? 0 : y;
|
||||
var end = _isClose ? y : 0;
|
||||
|
||||
GTween.To(strat, end, 0.5f)
|
||||
.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, 0.5f)
|
||||
.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, 0.5f)
|
||||
.SetEase(EaseType.Linear)
|
||||
.SetTarget(_node, TweenPropType.Alpha)
|
||||
.OnStart(() => { })
|
||||
.OnComplete(Finish);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class UIPanelAnimation
|
||||
{
|
||||
public static NTask GetCenterScaleBig(IUIPanel panel, bool close = false)
|
||||
{
|
||||
return new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.CenterScaleBig, close);
|
||||
}
|
||||
|
||||
public static NTask GetUpToSlide(IUIPanel panel, bool close = false)
|
||||
{
|
||||
return new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.UpToSlide, close);
|
||||
}
|
||||
|
||||
public static NTask GetDownToSlide(IUIPanel panel, bool close = false)
|
||||
{
|
||||
return new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.DownToSlide, close);
|
||||
}
|
||||
|
||||
public static NTask GetLeftToSlide(IUIPanel panel, bool close = false)
|
||||
{
|
||||
return new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.LeftToSlide, close);
|
||||
}
|
||||
|
||||
public static NTask GetRightToSlide(IUIPanel panel, bool close = false)
|
||||
{
|
||||
return new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.RightToSlide, close);
|
||||
}
|
||||
|
||||
public static NTask GetFade(IUIPanel panel, bool close = false)
|
||||
{
|
||||
return new PanelAnimationDef(panel.ContentPane, PanelAnimationDef.AnimType.Fade, close);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 506db39b69774ef7bcafb6f744370e81
|
||||
timeCreated: 1607328227
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 324106ae827a4b39a7d306901d9cf61d
|
||||
timeCreated: 1603427397
|
||||
@@ -1,25 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8599513d5235498b9f2cc5894451a3e6
|
||||
timeCreated: 1603427408
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace NBC
|
||||
{
|
||||
public static class UIEvents
|
||||
{
|
||||
public const string UIShow = "UIShow";
|
||||
|
||||
public const string UIHide = "UIHide";
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 398ef2627f5f47c2969f775329e212c0
|
||||
timeCreated: 1658111393
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 301625d0537e4abd8e4d2be119c2d6a8
|
||||
timeCreated: 1607073119
|
||||
@@ -1,181 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6e1faca2d324be59996ac7b326ac9a7
|
||||
timeCreated: 1607073126
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5dc408ef68f470386edde3039dc804b
|
||||
timeCreated: 1603427536
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace NBC
|
||||
{
|
||||
public interface IBind
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0acf981fdc74a7685b9298cbbeb959a
|
||||
timeCreated: 1608000546
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"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
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78a9aa383c5e7074d8c134031782f5b2
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,171 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63138e7895924fc981b6fa6d13ccf184
|
||||
timeCreated: 1664330627
|
||||
@@ -1,21 +0,0 @@
|
||||
namespace NBC
|
||||
{
|
||||
public class UI
|
||||
{
|
||||
private static UIManager _inst;
|
||||
|
||||
public static UIManager Inst
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_inst == null)
|
||||
{
|
||||
_inst = new UIManager();
|
||||
_inst.Start();
|
||||
}
|
||||
|
||||
return _inst;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e31143f2c014a7ba1ef31aaa3c4159c
|
||||
timeCreated: 1630661745
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc014662f0324fc093a0fa05eed3b511
|
||||
timeCreated: 1715247626
|
||||
@@ -1,146 +0,0 @@
|
||||
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;
|
||||
var font = Lan.GetLanFontByCurFont(textFormat.font);
|
||||
if (font == null) return;
|
||||
textFormat.font = font;
|
||||
curField.textFormat = textFormat;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de429c9a72354bac8521f78835cda342
|
||||
timeCreated: 1715247635
|
||||
@@ -1,21 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f212c92129c344f2a73daa0f46b99010
|
||||
timeCreated: 1715247696
|
||||
@@ -1,395 +0,0 @@
|
||||
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;
|
||||
|
||||
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
|
||||
{
|
||||
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
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e062ec5ffbb4339b33d1d75a965f4c2
|
||||
timeCreated: 1607415282
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 553ce3a74f9346a2967b868fc9dec118
|
||||
timeCreated: 1683269938
|
||||
@@ -1,16 +0,0 @@
|
||||
namespace NBC
|
||||
{
|
||||
internal static class UIRunner
|
||||
{
|
||||
#region Static
|
||||
|
||||
public static readonly Runner Def = new Runner();
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
Def.Process();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43f3556ed98c4f62bcb1711410d01868
|
||||
timeCreated: 1683269953
|
||||
Reference in New Issue
Block a user