Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class MyEnumerator : IEnumerator {
  7. Func<bool> predicate;
  8. IEnumerator routine;
  9.  
  10. public bool MoveNext() {
  11. return predicate() && routine.MoveNext();
  12. }
  13.  
  14. public void Reset() {
  15. routine.Reset();
  16. }
  17.  
  18. public object Current {
  19. get {
  20. return routine.Current;
  21. }
  22. }
  23.  
  24. public MyEnumerator(Func<bool> predicate, IEnumerator routine) {
  25. this.predicate = predicate;
  26. this.routine = routine;
  27. }
  28. }
  29.  
  30. public static class MyEnumeratorExtension {
  31. public static IEnumerator While(this IEnumerator routine, Func<bool> predicate) {
  32. return new MyEnumerator(predicate, routine);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement