SceneChangeComponent.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. namespace ET
  4. {
  5. public class SceneChangeComponentUpdateSystem: UpdateSystem<SceneChangeComponent>
  6. {
  7. public override void Update(SceneChangeComponent self)
  8. {
  9. if (self.loadMapOperation.isDone)
  10. {
  11. self.tcs.SetResult();
  12. }
  13. }
  14. }
  15. public class SceneChangeComponentDestroySystem: DestroySystem<SceneChangeComponent>
  16. {
  17. public override void Destroy(SceneChangeComponent self)
  18. {
  19. self.loadMapOperation = null;
  20. self.tcs = null;
  21. }
  22. }
  23. public class SceneChangeComponent: Entity
  24. {
  25. public AsyncOperation loadMapOperation;
  26. public ETTaskCompletionSource tcs;
  27. public async ETTask ChangeSceneAsync(string sceneName)
  28. {
  29. this.tcs = new ETTaskCompletionSource();
  30. // 加载map
  31. this.loadMapOperation = SceneManager.LoadSceneAsync(sceneName);
  32. //this.loadMapOperation.allowSceneActivation = false;
  33. await this.tcs.Task;
  34. }
  35. public int Process
  36. {
  37. get
  38. {
  39. if (this.loadMapOperation == null)
  40. {
  41. return 0;
  42. }
  43. return (int)(this.loadMapOperation.progress * 100);
  44. }
  45. }
  46. public void Finish()
  47. {
  48. this.tcs.SetResult();
  49. }
  50. }
  51. }