| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using System.Collections.Generic;
- using ETModel;
- using UnityEngine;
- namespace ETHotfix
- {
- [ObjectSystem]
- public class UiAwakeSystem : AwakeSystem<UI, string, GameObject>
- {
- public override void Awake(UI self, string name, GameObject gameObject)
- {
- self.Awake(name, gameObject);
- }
- }
-
- [HideInHierarchy]
- public sealed class UI: Entity
- {
- public string Name { get; private set; }
- public Dictionary<string, UI> children = new Dictionary<string, UI>();
-
- public void Awake(string name, GameObject gameObject)
- {
- this.children.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.children.Values)
- {
- ui.Dispose();
- }
-
- UnityEngine.Object.Destroy(GameObject);
- children.Clear();
- }
- public void SetAsFirstSibling()
- {
- this.GameObject.transform.SetAsFirstSibling();
- }
- public void Add(UI ui)
- {
- this.children.Add(ui.Name, ui);
- ui.Parent = this;
- }
- public void Remove(string name)
- {
- UI ui;
- if (!this.children.TryGetValue(name, out ui))
- {
- return;
- }
- this.children.Remove(name);
- ui.Dispose();
- }
- public UI Get(string name)
- {
- UI child;
- if (this.children.TryGetValue(name, out child))
- {
- return child;
- }
- GameObject childGameObject = this.GameObject.transform.Find(name)?.gameObject;
- if (childGameObject == null)
- {
- return null;
- }
- child = ComponentFactory.Create<UI, GameObject>(childGameObject);
- this.Add(child);
- return child;
- }
- }
- }
|