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.
 
 
 

108 lines
1.8 KiB

  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. namespace SUISSEngine
  5. {
  6. [Obsolete]
  7. public class UnityCoroutineTask<T> : ICoroutineTask<T>, ICoroutineTask
  8. {
  9. public UnityCoroutineTask(IEnumerator coroutine, MonoBehaviour runner)
  10. {
  11. this._coroutine = coroutine;
  12. this._return = default(T);
  13. this._isDone = false;
  14. this._running = true;
  15. this._unityCoroutine = runner.StartCoroutine(this.InternalRoutine());
  16. }
  17. public T Value
  18. {
  19. get
  20. {
  21. this.CheckForException();
  22. return this._return;
  23. }
  24. }
  25. public void Stop()
  26. {
  27. this._running = false;
  28. }
  29. public bool Running
  30. {
  31. get
  32. {
  33. return this._running;
  34. }
  35. }
  36. public bool IsDone
  37. {
  38. get
  39. {
  40. return this._isDone;
  41. }
  42. }
  43. public void CheckForException()
  44. {
  45. if (this._exception != null)
  46. {
  47. throw this._exception;
  48. }
  49. }
  50. public object YieldUntilDone()
  51. {
  52. return this._unityCoroutine;
  53. }
  54. private IEnumerator InternalRoutine()
  55. {
  56. while (this._running)
  57. {
  58. try
  59. {
  60. if (!this._coroutine.MoveNext())
  61. {
  62. this._running = false;
  63. this._isDone = true;
  64. yield break;
  65. }
  66. }
  67. catch (Exception exception)
  68. {
  69. this._exception = exception;
  70. this._running = false;
  71. this._isDone = true;
  72. yield break;
  73. }
  74. object yielded = this._coroutine.Current;
  75. if (yielded != null && yielded.GetType() == typeof(T))
  76. {
  77. this._return = (T)((object)yielded);
  78. this._running = false;
  79. this._isDone = true;
  80. yield break;
  81. }
  82. yield return this._coroutine.Current;
  83. }
  84. yield break;
  85. }
  86. private T _return;
  87. private bool _running;
  88. private Exception _exception;
  89. private IEnumerator _coroutine;
  90. private Coroutine _unityCoroutine;
  91. private bool _isDone;
  92. }
  93. }