SceneChangeComponentSystem.cs 1.6 KB

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