| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using System.Collections.Generic;
- using UnityEngine;
- namespace Hotfix
- {
- [Model.ObjectSystem]
- public class UiAwakeSystem : AwakeSystem<UI, GameObject>
- {
- public override void Awake(UI self, GameObject gameObject)
- {
- self.Awake(gameObject);
- }
- }
-
- public sealed class UI: Entity
- {
- public string Name
- {
- get
- {
- return this.GameObject.name;
- }
- }
- public GameObject GameObject { get; private set; }
- public Dictionary<string, UI> children = new Dictionary<string, UI>();
-
- public void Awake(GameObject gameObject)
- {
- this.children.Clear();
- 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;
- }
- }
- }
|