UIComponentSystem.cs 767 B

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