SceneChangeComponent.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. namespace ETModel
  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. public class SceneChangeComponent: Component
  17. {
  18. public AsyncOperation loadMapOperation;
  19. public ETTaskCompletionSource tcs;
  20. public float deltaTime;
  21. public int lastProgress = 0;
  22. public ETTask ChangeSceneAsync(string sceneName)
  23. {
  24. this.tcs = new ETTaskCompletionSource();
  25. // 加载map
  26. this.loadMapOperation = SceneManager.LoadSceneAsync(sceneName);
  27. return this.tcs.Task;
  28. }
  29. public int Process
  30. {
  31. get
  32. {
  33. if (this.loadMapOperation == null)
  34. {
  35. return 0;
  36. }
  37. return (int)(this.loadMapOperation.progress * 100);
  38. }
  39. }
  40. public void Finish()
  41. {
  42. this.tcs.SetResult();
  43. }
  44. public override void Dispose()
  45. {
  46. if (this.IsDisposed)
  47. {
  48. return;
  49. }
  50. if (this.Entity.IsDisposed)
  51. {
  52. return;
  53. }
  54. base.Dispose();
  55. this.Entity.RemoveComponent<SceneChangeComponent>();
  56. }
  57. }
  58. }