UIComponentSystem.cs 854 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 Create(this UIComponent self, string uiType)
  16. {
  17. UI ui = await UIEventComponent.Instance.OnCreate(self, uiType);
  18. self.UIs.Add(uiType, ui);
  19. }
  20. public static void Remove(this UIComponent self, string uiType)
  21. {
  22. if (!self.UIs.TryGetValue(uiType, out UI ui))
  23. {
  24. return;
  25. }
  26. UIEventComponent.Instance.OnRemove(self, uiType);
  27. self.UIs.Remove(uiType);
  28. ui.Dispose();
  29. }
  30. public static UI Get(this UIComponent self, string name)
  31. {
  32. UI ui = null;
  33. self.UIs.TryGetValue(name, out ui);
  34. return ui;
  35. }
  36. }
  37. }