UIGlobalComponentSystem.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using UnityEngine;
  3. namespace ET.Client
  4. {
  5. [EntitySystemOf(typeof(UIGlobalComponent))]
  6. public static partial class UIGlobalComponentSystem
  7. {
  8. [EntitySystem]
  9. public static void Awake(this UIGlobalComponent self)
  10. {
  11. GameObject uiRoot = GameObject.Find("/Global/UI");
  12. ReferenceCollector referenceCollector = uiRoot.GetComponent<ReferenceCollector>();
  13. self.UILayers.Add((int)UILayer.Hidden, referenceCollector.Get<GameObject>(UILayer.Hidden.ToString()).transform);
  14. self.UILayers.Add((int)UILayer.Low, referenceCollector.Get<GameObject>(UILayer.Low.ToString()).transform);
  15. self.UILayers.Add((int)UILayer.Mid, referenceCollector.Get<GameObject>(UILayer.Mid.ToString()).transform);
  16. self.UILayers.Add((int)UILayer.High, referenceCollector.Get<GameObject>(UILayer.High.ToString()).transform);
  17. }
  18. public static async ETTask<UI> OnCreate(this UIGlobalComponent self, UIComponent uiComponent, string uiType, UILayer uiLayer)
  19. {
  20. try
  21. {
  22. UI ui = await UIEventComponent.Instance.UIEvents[uiType].OnCreate(uiComponent, uiLayer);
  23. return ui;
  24. }
  25. catch (Exception e)
  26. {
  27. throw new Exception($"on create ui error: {uiType}", e);
  28. }
  29. }
  30. public static Transform GetLayer(this UIGlobalComponent self, int layer)
  31. {
  32. return self.UILayers[layer];
  33. }
  34. public static void OnRemove(this UIGlobalComponent self, UIComponent uiComponent, string uiType)
  35. {
  36. try
  37. {
  38. UIEventComponent.Instance.UIEvents[uiType].OnRemove(uiComponent);
  39. }
  40. catch (Exception e)
  41. {
  42. throw new Exception($"on remove ui error: {uiType}", e);
  43. }
  44. }
  45. }
  46. }