UIComponent.cs 961 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. using ETModel;
  4. using UnityEngine;
  5. namespace ETHotfix
  6. {
  7. [ObjectSystem]
  8. public class UIComponentAwakeSystem : AwakeSystem<UIComponent>
  9. {
  10. public override void Awake(UIComponent self)
  11. {
  12. self.Camera = Component.Global.transform.Find("UICamera").gameObject;
  13. }
  14. }
  15. /// <summary>
  16. /// 管理所有UI
  17. /// </summary>
  18. public class UIComponent: Component
  19. {
  20. public GameObject Camera;
  21. public Dictionary<string, UI> uis = new Dictionary<string, UI>();
  22. public void Add(UI ui)
  23. {
  24. ui.GameObject.GetComponent<Canvas>().worldCamera = this.Camera.GetComponent<Camera>();
  25. this.uis.Add(ui.Name, ui);
  26. ui.Parent = this;
  27. }
  28. public void Remove(string name)
  29. {
  30. if (!this.uis.TryGetValue(name, out UI ui))
  31. {
  32. return;
  33. }
  34. this.uis.Remove(name);
  35. ui.Dispose();
  36. }
  37. public UI Get(string name)
  38. {
  39. UI ui = null;
  40. this.uis.TryGetValue(name, out ui);
  41. return ui;
  42. }
  43. }
  44. }