SceneChangeComponentSystem.cs 1.4 KB

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