multiple xr toolkit package
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EditorCoroutine.cs 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEditor;
  5. using UnityEngine;
  6. using Object = UnityEngine.Object;
  7. public class EditorCoroutine
  8. {
  9. public static EditorCoroutine Start( IEnumerator _routine )
  10. {
  11. EditorCoroutine coroutine = new EditorCoroutine(_routine);
  12. coroutine.start();
  13. return coroutine;
  14. }
  15. public static EditorCoroutine Start(System.Action _action)
  16. {
  17. EditorCoroutine coroutine = new EditorCoroutine(_action);
  18. coroutine.start();
  19. return coroutine;
  20. }
  21. readonly IEnumerator routine;
  22. EditorCoroutine( IEnumerator _routine )
  23. {
  24. routine = _routine;
  25. }
  26. readonly System.Action action;
  27. EditorCoroutine(System.Action _action)
  28. {
  29. action = _action;
  30. }
  31. void start()
  32. {
  33. EditorApplication.update += update;
  34. }
  35. public void stop()
  36. {
  37. EditorApplication.update -= update;
  38. }
  39. void update()
  40. {
  41. if (routine != null)
  42. {
  43. if (!routine.MoveNext())
  44. stop();
  45. }
  46. else if (action != null)
  47. {
  48. action();
  49. stop();
  50. }
  51. else
  52. stop();
  53. }
  54. }