UIComponent.cs 825 B

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