You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
295 lines
7.7 KiB
295 lines
7.7 KiB
using System; |
|
using FairyGUI; |
|
|
|
namespace ET |
|
{ |
|
public class FUIComponentAwakeSystem : AwakeSystem<FUIComponent> |
|
{ |
|
public override void Awake(FUIComponent self) |
|
{ |
|
self.Awake(); |
|
} |
|
} |
|
|
|
public class FUIComponentDestroySystem : DestroySystem<FUIComponent> |
|
{ |
|
public override void Destroy(FUIComponent self) |
|
{ |
|
self.Destroy(); |
|
} |
|
} |
|
|
|
[Timer(TimerType.ButtonAsyncEventTimer)] |
|
public class ButtonAsyncEventTimer : ATimer<FUIComponent> |
|
{ |
|
public override void Run(FUIComponent self) |
|
{ |
|
try |
|
{ |
|
self.IsButtonClicked = false; |
|
} |
|
catch (Exception e) |
|
{ |
|
Log.Error(e); |
|
} |
|
} |
|
} |
|
|
|
[FriendClass(typeof(FUIComponent))] |
|
public static class FUIComponentSystem |
|
{ |
|
public static void Awake(this FUIComponent self) |
|
{ |
|
FUIComponent.Instance = self; |
|
self.Root = self.Domain.AddChild<FUI, GObject>(GRoot.inst); |
|
|
|
// 设置加载器 |
|
UIObjectFactory.SetLoaderExtension(typeof(FUIGLoader)); |
|
} |
|
|
|
public static void Destroy(this FUIComponent self) |
|
{ |
|
if (self.IsDisposed) |
|
{ |
|
return; |
|
} |
|
|
|
self.Root?.Dispose(); |
|
self.Root = null; |
|
} |
|
|
|
public static void Add(this FUIComponent self, FUI ui, bool asChildGObject) |
|
{ |
|
self.Root?.Add(ui, asChildGObject); |
|
} |
|
|
|
public static void Remove(this FUIComponent self, string name) |
|
{ |
|
self.Root?.Remove(name); |
|
} |
|
|
|
public static FUI Get(this FUIComponent self, string name) |
|
{ |
|
return self.Root?.Get(name); |
|
} |
|
|
|
public static FUI[] GetAll(this FUIComponent self) |
|
{ |
|
return self.Root?.GetAll(); |
|
} |
|
|
|
public static void Clear(this FUIComponent self) |
|
{ |
|
var childrens = self.GetAll(); |
|
|
|
if (childrens != null) |
|
{ |
|
foreach (var fui in childrens) |
|
{ |
|
self.Remove(fui.Name); |
|
} |
|
} |
|
} |
|
|
|
public static void StartButtonEventAsyncTimer(this FUIComponent self) |
|
{ |
|
self.ButtonAsyncEventTimer = TimerComponent.Instance.NewOnceTimer(TimeHelper.ClientNow() + 2000, TimerType.ButtonAsyncEventTimer, self); |
|
} |
|
|
|
public static void StopButtonEventAsyncTimer(this FUIComponent self) |
|
{ |
|
TimerComponent.Instance.Remove(ref self.ButtonAsyncEventTimer); |
|
} |
|
|
|
public static void AddWindow(this FUIComponent self, string name, IFUIWindow window) |
|
{ |
|
self.AvailableWindows.Add(name, window); |
|
} |
|
|
|
public static IFUIWindow GetWindow(this FUIComponent self, string name) |
|
{ |
|
if (self.AvailableWindows.ContainsKey(name)) |
|
{ |
|
return self.AvailableWindows[name]; |
|
} |
|
|
|
return null; |
|
} |
|
|
|
public static void HideWindow(this FUIComponent self, string name) |
|
{ |
|
if (self.AvailableWindows.TryGetValue(name, out IFUIWindow win)) |
|
{ |
|
win.Window?.Hide(); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 异步显示一个UI组件 |
|
/// </summary> |
|
/// <param name="packageBundle">组件所在的ab包</param> |
|
/// <typeparam name="T">FUI组件类型</typeparam> |
|
/// <typeparam name="K">对应的自定义逻辑组件类型</typeparam> |
|
/// <returns>对应的自定义逻辑组件 </returns> |
|
public static async ETTask<K> ShowUIAsync<T, K>(this FUIComponent self, string packageBundle) where T : Entity, IAwake, new() where K : Entity, IAwake, new() |
|
{ |
|
// 对应fairgui中的包内部的资源名 |
|
string uiResName = (string) typeof (T).GetField("UIResName").GetValue(null); |
|
if (self.AvailableUI.TryGetValue(uiResName, out Entity comp)) |
|
{ |
|
FUI fui = comp.GetParent<FUI>(); |
|
fui.Visible = true; |
|
return comp as K; |
|
} |
|
else |
|
{ |
|
var zoneScene = self.ZoneScene(); |
|
await zoneScene.GetComponent<FUIPackageComponent>().AddPackageAsync(packageBundle); |
|
// 对应fairgui中的包名 |
|
string uiPackageName = (string) typeof(T).GetField("UIPackageName").GetValue(null); |
|
|
|
T dataComp = FUIHelper.CreateInstance<T>(zoneScene, uiPackageName, uiResName); |
|
FUI fui = dataComp.GetParent<FUI>(); |
|
fui.Name = uiResName; |
|
fui.MakeFullScreen(); |
|
|
|
var logicComp = fui.AddComponent<K>(); |
|
self.Add(fui, true); |
|
self.AvailableUI.Add(uiResName, logicComp); |
|
return logicComp; |
|
} |
|
|
|
|
|
} |
|
|
|
public static K ShowUI<T, K>(this FUIComponent self, string packageBundle) where T : Entity, IAwake, new() where K : Entity, IAwake, new() |
|
{ |
|
string uiResName = (string) typeof (T).GetField("UIResName").GetValue(null); |
|
if (self.AvailableUI.TryGetValue(uiResName, out Entity comp)) |
|
{ |
|
FUI fui = comp.GetParent<FUI>(); |
|
fui.Visible = true; |
|
return comp as K; |
|
} |
|
else |
|
{ |
|
var zoneScene = self.ZoneScene(); |
|
zoneScene.GetComponent<FUIPackageComponent>().AddPackage(packageBundle); |
|
// 对应fairgui中的包名 |
|
string uiPackageName = (string) typeof(T).GetField("UIPackageName").GetValue(null); |
|
// 对应fairgui中的包内部的资源名 |
|
|
|
T dataComp = FUIHelper.CreateInstance<T>(zoneScene, uiPackageName, uiResName); |
|
FUI fui = dataComp.GetParent<FUI>(); |
|
fui.Name = uiResName; |
|
fui.MakeFullScreen(); |
|
|
|
|
|
var logicComp = fui.AddComponent<K>(); |
|
self.Add(fui, true); |
|
self.AvailableUI.Add(uiResName, logicComp); |
|
return logicComp; |
|
} |
|
} |
|
|
|
public static Entity GetUI(this FUIComponent self, string name) |
|
{ |
|
if (self.AvailableUI.TryGetValue(name, out Entity comp)) |
|
{ |
|
return comp; |
|
} |
|
|
|
return null; |
|
} |
|
|
|
public static void HideUI(this FUIComponent self, string name) |
|
{ |
|
if (self.AvailableUI.TryGetValue(name, out Entity comp)) |
|
{ |
|
FUI fui = comp.GetParent<FUI>(); |
|
fui.Visible = false; |
|
} |
|
} |
|
|
|
public static void RemoveUI(this FUIComponent self, string name) |
|
{ |
|
self.AvailableUI.Remove(name); |
|
self.Remove(name); |
|
} |
|
|
|
public static K ShowWindow<T, K>(this FUIComponent self, string packageBundle = null) where T : Entity, IAwake, new() |
|
where K : Entity, IAwake, IFUIWindow, new() |
|
{ |
|
var zoneScene = self.ZoneScene(); |
|
|
|
var type = typeof (T); |
|
|
|
// 对应fairgui中的包内部的资源名 |
|
string uiResName = (string) type.GetField("UIResName").GetValue(null); |
|
var win = self.GetWindow(uiResName); |
|
if (win != null) |
|
{ |
|
win.Window?.Show(); |
|
return win as K; |
|
} |
|
else |
|
{ |
|
// 对应fairgui中的包名 |
|
string uiPackageName = (string) type.GetField("UIPackageName").GetValue(null); |
|
if (packageBundle == null) |
|
{ |
|
// 默认使用fui提供的包名 |
|
packageBundle = uiPackageName; |
|
} |
|
zoneScene.GetComponent<FUIPackageComponent>().AddPackage(packageBundle); |
|
T dataComp = FUIHelper.CreateInstance<T>(zoneScene, uiPackageName, uiResName); |
|
FUI fui = dataComp.GetParent<FUI>(); |
|
fui.Name = uiResName; |
|
fui.MakeFullScreen(); |
|
|
|
var logicComp = fui.AddComponent<K>(); |
|
self.AddWindow(uiResName, logicComp); |
|
logicComp.Window?.Show(); |
|
return logicComp; |
|
} |
|
} |
|
|
|
public static async ETTask<K> ShowWindowAsync<T, K>(this FUIComponent self, string packageBundle = null) where T : Entity, IAwake, new() |
|
where K : Entity, IAwake, IFUIWindow, new() |
|
{ |
|
var zoneScene = self.ZoneScene(); |
|
|
|
var type = typeof (T); |
|
|
|
// 对应fairgui中的包内部的资源名 |
|
string uiResName = (string) type.GetField("UIResName").GetValue(null); |
|
var win = self.GetWindow(uiResName); |
|
if (win != null) |
|
{ |
|
win.Window?.Show(); |
|
return win as K; |
|
} |
|
else |
|
{ |
|
// 对应fairgui中的包名 |
|
string uiPackageName = (string) type.GetField("UIPackageName").GetValue(null); |
|
|
|
if (packageBundle == null) |
|
{ |
|
// 默认使用fui提供的包名 |
|
packageBundle = uiPackageName; |
|
} |
|
await zoneScene.GetComponent<FUIPackageComponent>().AddPackageAsync(packageBundle); |
|
T dataComp = FUIHelper.CreateInstance<T>(zoneScene, uiPackageName, uiResName); |
|
FUI fui = dataComp.GetParent<FUI>(); |
|
fui.Name = uiResName; |
|
fui.MakeFullScreen(); |
|
|
|
var logicComp = fui.AddComponent<K>(); |
|
self.AddWindow(uiResName, logicComp); |
|
logicComp.Window?.Show(); |
|
return logicComp; |
|
} |
|
} |
|
} |
|
}
|
|
|