UILoadingComponent.cs 938 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace Model
  4. {
  5. [ObjectEvent]
  6. public class UILoadingComponentEvent : ObjectEvent<UILoadingComponent>, IAwake, IStart
  7. {
  8. public void Awake()
  9. {
  10. UILoadingComponent self = this.Get();
  11. self.text = self.GetParent<UI>().GameObject.Get<GameObject>("Text").GetComponent<Text>();
  12. }
  13. public async void Start()
  14. {
  15. UILoadingComponent self = this.Get();
  16. TimerComponent timerComponent = Game.Scene.GetComponent<TimerComponent>();
  17. while (true)
  18. {
  19. await timerComponent.WaitAsync(1000);
  20. if (self.Id == 0)
  21. {
  22. return;
  23. }
  24. BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent<BundleDownloaderComponent>();
  25. if (bundleDownloaderComponent == null)
  26. {
  27. continue;
  28. }
  29. self.text.text = $"{bundleDownloaderComponent.Progress}%";
  30. }
  31. }
  32. }
  33. public class UILoadingComponent : Component
  34. {
  35. public Text text;
  36. }
  37. }