UIComponent.cs 802 B

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