EditorCoroutine.cs 800 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEditor;
  5. using UnityEngine;
  6. using Object = UnityEngine.Object;
  7. namespace Funly.SkyStudio {
  8. public class EditorCoroutine
  9. {
  10. public static EditorCoroutine start(IEnumerator _routine)
  11. {
  12. EditorCoroutine coroutine = new EditorCoroutine(_routine);
  13. coroutine.start();
  14. return coroutine;
  15. }
  16. readonly IEnumerator routine;
  17. EditorCoroutine(IEnumerator _routine)
  18. {
  19. routine = _routine;
  20. }
  21. void start()
  22. {
  23. EditorApplication.update += update;
  24. }
  25. public void stop()
  26. {
  27. EditorApplication.update -= update;
  28. }
  29. void update()
  30. {
  31. if (!routine.MoveNext()) {
  32. stop();
  33. }
  34. }
  35. }
  36. }