UILoadingComponent.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 async void Start(UILoadingComponent self)
  17. {
  18. TimerComponent timerComponent = Game.Scene.GetComponent<TimerComponent>();
  19. long instanceId = self.InstanceId;
  20. while (true)
  21. {
  22. await timerComponent.WaitAsync(1000);
  23. if (self.InstanceId != instanceId)
  24. {
  25. return;
  26. }
  27. BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent<BundleDownloaderComponent>();
  28. if (bundleDownloaderComponent == null)
  29. {
  30. continue;
  31. }
  32. self.text.text = $"{bundleDownloaderComponent.Progress}%";
  33. }
  34. }
  35. }
  36. public class UILoadingComponent : Component
  37. {
  38. public Text text;
  39. }
  40. }