UI.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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)
  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. UI ui;
  48. if (!this.children.TryGetValue(name, out ui))
  49. {
  50. return;
  51. }
  52. this.children.Remove(name);
  53. ui.Dispose();
  54. }
  55. }
  56. }