Skip to content

Instantly share code, notes, and snippets.

@jnbt
Created November 12, 2013 14:38
Show Gist options
  • Save jnbt/7431843 to your computer and use it in GitHub Desktop.
Save jnbt/7431843 to your computer and use it in GitHub Desktop.
private class FrameQueueWorker<T>{
private List<T> items;
private Action<T,int> block;
private int i, imax;
public FrameQueueWorker(List<T> items, Action<T,int> block){
this.items = items; this.block = block;
i = 0; imax = items.Count;
}
public void Play(){
if(i < imax) nextItem();
}
private void nextItem(){
Utils.CoroutineStarter.Instance.Add(processNextItem());
}
private IEnumerator deferedNextItem(){
yield return new WaitForEndOfFrame();
nextItem();
}
private IEnumerator processNextItem(){
yield return new WaitForEndOfFrame();
block(items[i], i);
i++;
if(i < imax) Utils.CoroutineStarter.Instance.Add(deferedNextItem());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment