/// <summary> /// Waits for coroutine to finish and calls a callback. /// Callback is invoked with "true" if no exception was thrown /// </summary> /// <param name="coroutine"></param> /// <param name="callback"></param> /// <param name="usePermanentRunner"> /// If true, will run coroutine on an object /// which is not destroyed on scene change /// </param> public static void WaitAndCatchException(IEnumerator coroutine, InvokeCallbackHandler callback, bool usePermanentRunner = false) { var runner = usePermanentRunner ? PermanentRunner : Runner; runner.StartCoroutine(WaitCoroutine(coroutine, callback, runner)); }
private static IEnumerator WaitCoroutine(IEnumerator coroutine, InvokeCallbackHandler callback, MonoBehaviour runner) { var safeCoroutine = runner.StartSafeCoroutine(coroutine); yield return(safeCoroutine.WaitCoroutine); callback.Invoke(safeCoroutine.Exception); }