SceneChangeComponent.cs 1.5 KB

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