UIComponentSystem.cs 868 B

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