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.
179 lines
4.2 KiB
179 lines
4.2 KiB
3 years ago
|
using FairyGUI;
|
||
|
using System;
|
||
|
using System.Linq;
|
||
|
|
||
|
namespace ET
|
||
|
{
|
||
|
public class FUIAwakeSystem : AwakeSystem<FUI, GObject>
|
||
|
{
|
||
|
public override void Awake(FUI self, GObject gObject)
|
||
|
{
|
||
|
self.Awake(gObject);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public class FUIDestroySystem : DestroySystem<FUI>
|
||
|
{
|
||
|
public override void Destroy(FUI self)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[FriendClass(typeof(FUI))]
|
||
|
public static class FUISystem
|
||
|
{
|
||
|
public static void Awake(this FUI self, GObject gObject)
|
||
|
{
|
||
|
self.GObject = gObject;
|
||
|
|
||
|
if (string.IsNullOrWhiteSpace(self.Name))
|
||
|
{
|
||
|
self.Name = self.Id.ToString();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
public static void Add(this FUI self,FUI ui, bool asChildGObject)
|
||
|
{
|
||
|
if (ui == null || ui.IsEmpty)
|
||
|
{
|
||
|
throw new Exception($"ui can not be empty");
|
||
|
}
|
||
|
|
||
|
if (string.IsNullOrWhiteSpace(ui.Name))
|
||
|
{
|
||
|
throw new Exception($"ui.Name can not be empty");
|
||
|
}
|
||
|
|
||
|
if (self.FUIChildren.ContainsKey(ui.Name))
|
||
|
{
|
||
|
throw new Exception($"ui.Name({ui.Name}) already exist");
|
||
|
}
|
||
|
|
||
|
self.FUIChildren.Add(ui.Name, ui);
|
||
|
|
||
|
if (self.IsComponent && asChildGObject)
|
||
|
{
|
||
|
self.GObject.asCom.AddChild(ui.GObject);
|
||
|
}
|
||
|
|
||
|
self.AddChild(ui);
|
||
|
}
|
||
|
|
||
|
public static void MakeFullScreen(this FUI self)
|
||
|
{
|
||
|
self.GObject?.asCom?.MakeFullScreen();
|
||
|
}
|
||
|
|
||
|
public static void Remove(this FUI self, string name)
|
||
|
{
|
||
|
if (self.IsDisposed)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
FUI ui;
|
||
|
|
||
|
if (self.FUIChildren.TryGetValue(name, out ui))
|
||
|
{
|
||
|
self.FUIChildren.Remove(name);
|
||
|
|
||
|
if (ui != null)
|
||
|
{
|
||
|
if (self.IsComponent)
|
||
|
{
|
||
|
self.GObject.asCom.RemoveChild(ui.GObject, false);
|
||
|
}
|
||
|
|
||
|
ui.Dispose();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void RemoveChildren(this FUI self)
|
||
|
{
|
||
|
foreach (var child in self.FUIChildren.Values.ToArray())
|
||
|
{
|
||
|
child.Dispose();
|
||
|
}
|
||
|
|
||
|
self.FUIChildren.Clear();
|
||
|
}
|
||
|
|
||
|
public static FUI Get(this FUI self, string name)
|
||
|
{
|
||
|
FUI child;
|
||
|
|
||
|
if (self.FUIChildren.TryGetValue(name, out child))
|
||
|
{
|
||
|
return child;
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
public static FUI[] GetAll(this FUI self)
|
||
|
{
|
||
|
return self.FUIChildren.Values.ToArray();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 一般情况不要使用此方法,如需使用,需要自行管理返回值的FUI的释放。
|
||
|
/// </summary>
|
||
|
public static FUI RemoveNoDispose(this FUI self, string name)
|
||
|
{
|
||
|
if (self.IsDisposed)
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
FUI ui;
|
||
|
|
||
|
if (self.FUIChildren.TryGetValue(name, out ui))
|
||
|
{
|
||
|
self.FUIChildren.Remove(name);
|
||
|
|
||
|
if (ui != null)
|
||
|
{
|
||
|
if (self.IsComponent)
|
||
|
{
|
||
|
self.GObject.asCom.RemoveChild(ui.GObject, false);
|
||
|
}
|
||
|
|
||
|
ui.Parent?.RemoveChild(ui);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return ui;
|
||
|
}
|
||
|
|
||
|
public static void Destroy(this FUI self)
|
||
|
{
|
||
|
if (self.IsDisposed)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// 从父亲中删除自己
|
||
|
self.GetParent<FUI>()?.RemoveNoDispose(self.Name);
|
||
|
|
||
|
// 删除所有的孩子
|
||
|
foreach (FUI ui in self.FUIChildren.Values.ToArray())
|
||
|
{
|
||
|
ui.Dispose();
|
||
|
}
|
||
|
|
||
|
self.FUIChildren.Clear();
|
||
|
|
||
|
// 删除自己的UI
|
||
|
if (!self.IsRoot && !self.isFromFGUIPool)
|
||
|
{
|
||
|
self.GObject.Dispose();
|
||
|
}
|
||
|
|
||
|
self.GObject = null;
|
||
|
self.isFromFGUIPool = false;
|
||
|
}
|
||
|
}
|
||
|
}
|