AbortableEnumerator

From Unify Community Wiki
Jump to: navigation, search

Provides an abort mechanism to a coroutine. Wrap the call to the coroutine with this AbortableEnumerator, and call Abort() when you want to abort it.

See this answer for usage example.

public class AbortableEnumerator : IEnumerator
{
	protected IEnumerator enumerator;
	protected bool isAborted;
 
	public AbortableEnumerator(IEnumerator enumerator)
	{
		this.enumerator = enumerator;
	}
 
	public void Abort()
	{
		isAborted = true;
	}
 
	bool IEnumerator.MoveNext ()
	{
		if (isAborted)
			return false;
		else
			return enumerator.MoveNext ();
	}
 
	void IEnumerator.Reset ()
	{
		isAborted = false;
		enumerator.Reset ();
	}
 
	object IEnumerator.Current 
	{
		get { return enumerator.Current; }
	}
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox