UIComponentSystem.cs 807 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Collections.Generic;
  2. namespace ET.Client
  3. {
  4. /// <summary>
  5. /// 管理Scene上的UI
  6. /// </summary>
  7. [FriendOf(typeof(UIComponent))]
  8. public static class UIComponentSystem
  9. {
  10. public static async ETTask<UI> Create(this UIComponent self, string uiType, UILayer uiLayer)
  11. {
  12. UI ui = await UIEventComponent.Instance.OnCreate(self, uiType, uiLayer);
  13. self.UIs.Add(uiType, ui);
  14. return ui;
  15. }
  16. public static void Remove(this UIComponent self, string uiType)
  17. {
  18. if (!self.UIs.TryGetValue(uiType, out UI ui))
  19. {
  20. return;
  21. }
  22. UIEventComponent.Instance.OnRemove(self, uiType);
  23. self.UIs.Remove(uiType);
  24. ui.Dispose();
  25. }
  26. public static UI Get(this UIComponent self, string name)
  27. {
  28. UI ui = null;
  29. self.UIs.TryGetValue(name, out ui);
  30. return ui;
  31. }
  32. }
  33. }