using System; using System.Collections; using UnityEngine; namespace SUISSEngine { [Obsolete] public class UnityCoroutineTask : ICoroutineTask, ICoroutineTask { public UnityCoroutineTask(IEnumerator coroutine, MonoBehaviour runner) { this._coroutine = coroutine; this._return = default(T); this._isDone = false; this._running = true; this._unityCoroutine = runner.StartCoroutine(this.InternalRoutine()); } public T Value { get { this.CheckForException(); return this._return; } } public void Stop() { this._running = false; } public bool Running { get { return this._running; } } public bool IsDone { get { return this._isDone; } } public void CheckForException() { if (this._exception != null) { throw this._exception; } } public object YieldUntilDone() { return this._unityCoroutine; } private IEnumerator InternalRoutine() { while (this._running) { try { if (!this._coroutine.MoveNext()) { this._running = false; this._isDone = true; yield break; } } catch (Exception exception) { this._exception = exception; this._running = false; this._isDone = true; yield break; } object yielded = this._coroutine.Current; if (yielded != null && yielded.GetType() == typeof(T)) { this._return = (T)((object)yielded); this._running = false; this._isDone = true; yield break; } yield return this._coroutine.Current; } yield break; } private T _return; private bool _running; private Exception _exception; private IEnumerator _coroutine; private Coroutine _unityCoroutine; private bool _isDone; } }