Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MyEnumerator : IEnumerator {
- Func<bool> predicate;
- IEnumerator routine;
- public bool MoveNext() {
- return predicate() && routine.MoveNext();
- }
- public void Reset() {
- routine.Reset();
- }
- public object Current {
- get {
- return routine.Current;
- }
- }
- public MyEnumerator(Func<bool> predicate, IEnumerator routine) {
- this.predicate = predicate;
- this.routine = routine;
- }
- }
- public static class MyEnumeratorExtension {
- public static IEnumerator While(this IEnumerator routine, Func<bool> predicate) {
- return new MyEnumerator(predicate, routine);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement