UILoadingComponent.cs 1.1 KB

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