zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Unity/Assets/HotfixView/Model/FGUI/FUIComponent.cs

102 lines
1.9 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using ET;
using ET;
using FairyGUI;
using System.Collections.Generic;
namespace ET
{
public class FUIComponentAwakeSystem : AwakeSystem<FUIComponent>
{
public override void Awake(FUIComponent self)
{
self.Root = EntityFactory.CreateWithParent<FUI, GObject>(self.Domain, GRoot.inst);
FUIComponent.Instance = self;
}
}
/// <summary>
/// 管理所有顶层UI, 顶层UI都是GRoot的孩子
/// </summary>
public class FUIComponent: Entity
{
public static FUIComponent Instance { get; set; }
public FUI Root;
public override void Dispose()
{
if (IsDisposed)
{
return;
}
base.Dispose();
Root.Dispose();
Root = null;
}
public async ETTask<FUI> Create(string uiType)
{
FUI ui = await UIEventComponent.Instance.OnCreate(this, uiType);
//self.UIs.Add(uiType, ui);
//Root.Add(ui);
Root?.Add(ui, true);
return ui;
}
public void Add(FUI ui, bool asChildGObject)
{
Root?.Add(ui, asChildGObject);
}
public void Remove(string name)
{
Root?.Remove(name);
}
/// <summary>
/// 通过名字获得FUI
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public FUI Get(string name)
{
return Root?.Get(name);
}
2022-07-26 00:51:17 +08:00
public T Get<T>(string name) where T: FUI
{
return Root?.Get(name).As<T>();
}
2021-04-08 20:09:59 +08:00
/// <summary>
/// 通过ID获得FUI
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public FUI Get(long id)
{
return Root?.Get(id.ToString());
}
public IEnumerable<FUI> GetAll()
{
return Root?.GetAll();
}
public void Clear()
{
var childrens = GetAll();
if(childrens != null)
{
2021-04-11 19:50:39 +08:00
foreach (FUI fui in childrens)
2021-04-08 20:09:59 +08:00
{
Remove(fui.Name);
}
}
}
}
}