UILoadingComponentSystem.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace ET
  4. {
  5. public class UiLoadingComponentAwakeSystem : AwakeSystem<UILoadingComponent>
  6. {
  7. public override void Awake(UILoadingComponent self)
  8. {
  9. self.text = self.GetParent<UI>().GameObject.Get<GameObject>("Text").GetComponent<Text>();
  10. }
  11. }
  12. public class UiLoadingComponentStartSystem : StartSystem<UILoadingComponent>
  13. {
  14. public override void Start(UILoadingComponent self)
  15. {
  16. StartAsync(self).Coroutine();
  17. }
  18. public async ETVoid StartAsync(UILoadingComponent self)
  19. {
  20. TimerComponent timerComponent = Game.Scene.GetComponent<TimerComponent>();
  21. long instanceId = self.InstanceId;
  22. while (true)
  23. {
  24. await timerComponent.WaitAsync(1000);
  25. if (self.InstanceId != instanceId)
  26. {
  27. return;
  28. }
  29. BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent<BundleDownloaderComponent>();
  30. if (bundleDownloaderComponent == null)
  31. {
  32. continue;
  33. }
  34. self.text.text = $"{bundleDownloaderComponent.Progress}%";
  35. }
  36. }
  37. }
  38. }