UIComponent.cs 928 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace ET
  5. {
  6. [ObjectSystem]
  7. public class UIComponentAwakeSystem : AwakeSystem<UIComponent>
  8. {
  9. public override void Awake(UIComponent self)
  10. {
  11. self.Camera = Entity.Global.transform.Find("UICamera").gameObject;
  12. }
  13. }
  14. /// <summary>
  15. /// 管理所有UI
  16. /// </summary>
  17. public class UIComponent: Entity
  18. {
  19. public GameObject Camera;
  20. public Dictionary<string, UI> uis = new Dictionary<string, UI>();
  21. public void Add(UI ui)
  22. {
  23. ui.ViewGO.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. public UI Get(string name)
  37. {
  38. UI ui = null;
  39. this.uis.TryGetValue(name, out ui);
  40. return ui;
  41. }
  42. }
  43. }