UI.cs 1.1 KB

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