| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using System.Collections.Generic;
- using UnityEngine;
- namespace ET
- {
-
- public class UIAwakeSystem : AwakeSystem<UI, string, GameObject>
- {
- public override void Awake(UI self, string name, GameObject gameObject)
- {
- self.Awake(name, gameObject);
- }
- }
-
- public sealed class UI: Entity
- {
- public GameObject GameObject;
-
- public string Name { get; private set; }
- public Dictionary<string, UI> nameChildren = new Dictionary<string, UI>();
-
- public void Awake(string name, GameObject gameObject)
- {
- this.nameChildren.Clear();
- gameObject.AddComponent<ComponentView>().Component = this;
- gameObject.layer = LayerMask.NameToLayer(LayerNames.UI);
- this.Name = name;
- this.GameObject = gameObject;
- }
- public override void Dispose()
- {
- if (this.IsDisposed)
- {
- return;
- }
-
- base.Dispose();
- foreach (UI ui in this.nameChildren.Values)
- {
- ui.Dispose();
- }
-
- UnityEngine.Object.Destroy(this.GameObject);
- this.nameChildren.Clear();
- }
- public void SetAsFirstSibling()
- {
- this.GameObject.transform.SetAsFirstSibling();
- }
- public void Add(UI ui)
- {
- this.nameChildren.Add(ui.Name, ui);
- }
- public void Remove(string name)
- {
- UI ui;
- if (!this.nameChildren.TryGetValue(name, out ui))
- {
- return;
- }
- this.nameChildren.Remove(name);
- ui.Dispose();
- }
- public UI Get(string name)
- {
- UI child;
- if (this.nameChildren.TryGetValue(name, out child))
- {
- return child;
- }
- GameObject childGameObject = this.GameObject.transform.Find(name)?.gameObject;
- if (childGameObject == null)
- {
- return null;
- }
- child = Entity.Create<UI, string, GameObject>(this, name, childGameObject);
- this.Add(child);
- return child;
- }
- }
- }
|