UIComponentSystem.cs 1005 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections.Generic;
  2. namespace ET.Client
  3. {
  4. /// <summary>
  5. /// 管理Scene上的UI
  6. /// </summary>
  7. [EntitySystemOf(typeof(UIComponent))]
  8. public static partial class UIComponentSystem
  9. {
  10. [EntitySystem]
  11. private static void Awake(this UIComponent self)
  12. {
  13. self.UIGlobalComponent = self.Root().GetComponent<UIGlobalComponent>();
  14. }
  15. public static async ETTask<UI> Create(this UIComponent self, string uiType, UILayer uiLayer)
  16. {
  17. UI ui = await self.UIGlobalComponent.OnCreate(self, uiType, uiLayer);
  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 EntityRef<UI> uiRef))
  24. {
  25. return;
  26. }
  27. self.UIGlobalComponent.OnRemove(self, uiType);
  28. self.UIs.Remove(uiType);
  29. UI ui = uiRef;
  30. ui?.Dispose();
  31. }
  32. public static UI Get(this UIComponent self, string name)
  33. {
  34. self.UIs.TryGetValue(name, out EntityRef<UI> uiRef);
  35. return uiRef;
  36. }
  37. }
  38. }