UI.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Collections.Generic;
  2. using Model;
  3. using UnityEngine;
  4. namespace Hotfix
  5. {
  6. public sealed class UI: Entity
  7. {
  8. public Scene Scene { get; set; }
  9. public UIType UIType { get; }
  10. public string Name
  11. {
  12. get
  13. {
  14. return this.GameObject.name;
  15. }
  16. }
  17. public GameObject GameObject { get; }
  18. public Dictionary<string, UI> children = new Dictionary<string, UI>();
  19. public override void Dispose()
  20. {
  21. if (this.Id == 0)
  22. {
  23. return;
  24. }
  25. base.Dispose();
  26. }
  27. public void SetAsFirstSibling()
  28. {
  29. this.GameObject.transform.SetAsFirstSibling();
  30. }
  31. public UI(Scene scene, UIType uiType, UI parent, GameObject gameObject): base(EntityType.UI)
  32. {
  33. this.Scene = scene;
  34. this.UIType = uiType;
  35. if (parent != null)
  36. {
  37. gameObject.transform.SetParent(parent.GameObject.transform, false);
  38. }
  39. this.GameObject = gameObject;
  40. }
  41. public void Add(UI ui)
  42. {
  43. this.children.Add(ui.Name, ui);
  44. }
  45. public void Remove(string name)
  46. {
  47. if (!this.children.TryGetValue(name, out UI ui))
  48. {
  49. return;
  50. }
  51. this.children.Remove(name);
  52. ui.Dispose();
  53. }
  54. }
  55. }