SceneChangeComponent.cs 876 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.Threading.Tasks;
  2. using UnityEngine;
  3. using UnityEngine.SceneManagement;
  4. namespace Model
  5. {
  6. public class SceneChangeComponent: Component
  7. {
  8. public AsyncOperation loadMapOperation;
  9. public TaskCompletionSource<bool> tcs;
  10. public float deltaTime;
  11. public int lastProgress = 0;
  12. public Task<bool> ChangeSceneAsync(SceneType sceneEnum)
  13. {
  14. this.tcs = new TaskCompletionSource<bool>();
  15. // 加载map
  16. this.loadMapOperation = SceneManager.LoadSceneAsync(sceneEnum.ToString());
  17. return this.tcs.Task;
  18. }
  19. public int Process
  20. {
  21. get
  22. {
  23. if (this.loadMapOperation == null)
  24. {
  25. return 0;
  26. }
  27. return (int)(this.loadMapOperation.progress * 100);
  28. }
  29. }
  30. public void Finish()
  31. {
  32. this.tcs.SetResult(true);
  33. }
  34. public override void Dispose()
  35. {
  36. if (this.IsDisposed)
  37. {
  38. return;
  39. }
  40. base.Dispose();
  41. }
  42. }
  43. }