An object that can be used to signal to a coroutine that it should terminate early.
public class CoroutineInterruptToken
While coroutines can be stopped by calling
UnityEngine.MonoBehaviour.StopAllCoroutines, this has the side effect of also stopping any coroutine that was waiting for the now-stopped coroutine to finish.
Instances of this class may be passed as a parameter to a coroutine that they can periodically poll to see if they should terminate earlier than planned.
To use this class, create an instance of it, and pass it as a parameter to your coroutine. In the coroutine, call Start() to mark that the coroutine is running. During the coroutine's execution, periodically check the WasInterrupted property to determine if the coroutine should exit. If it is
true, the coroutine should exit (via the
yield breakstatement.) At the normal exit of your coroutine, call the Complete() method to mark that the coroutine is no longer running. To make a coroutine stop, call the Interrupt() method.