UI.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. foreach (UI ui in this.children.Values)
  27. {
  28. ui.Dispose();
  29. }
  30. UnityEngine.Object.Destroy(this.GameObject);
  31. }
  32. public void SetAsFirstSibling()
  33. {
  34. this.GameObject.transform.SetAsFirstSibling();
  35. }
  36. public UI(Scene scene, UIType uiType, UI parent, GameObject gameObject)
  37. {
  38. this.Scene = scene;
  39. this.UIType = uiType;
  40. if (parent != null)
  41. {
  42. gameObject.transform.SetParent(parent.GameObject.transform, false);
  43. }
  44. this.GameObject = gameObject;
  45. }
  46. public void Add(UI ui)
  47. {
  48. this.children.Add(ui.Name, ui);
  49. }
  50. public void Remove(string name)
  51. {
  52. UI ui;
  53. if (!this.children.TryGetValue(name, out ui))
  54. {
  55. return;
  56. }
  57. this.children.Remove(name);
  58. ui.Dispose();
  59. }
  60. }
  61. }