适用于 C# 和 Unity 的迭代器库
IEnumerator and LINQand headersClone or download this repository and copy the JacksonDunstanIterator directory somewhere inside your Unity project's Assets directory.
Clone or download this repository and add all the .cs files directly under the JacksonDunstanIterator directory to your C# project.
There are three iterator types:
ArrayIterator for managed arrays (T[])ListIterator for ListNativeArrayIterator for NativeArray (automatically compiled out when Unity 2018.1+ isn't available)They all have the same API. Here's the basics of using ArrayIterator:
// Get an array
int[] array = new [] { 30, 10, 20, 40 };
// Get an iterator to the beginning of the array
ArrayIterator begin = array.Begin();
// Get the value of the iterator
int val = begin.GetCurrent();
// Move to the next element
ArrayIterator second = begin.GetNext();
// Get an iterator to one past the end of the array
ArrayIterator end = array.End();
// Reverse [ 10, 20, 40] so the array is [ 30, 40, 20, 10 ]
second.Reverse(end);
// Search for an element satisfying a condition
ArrayIterator it20 = begin.FindIf(end, e => e < 25);There is much more functionality available. See the source for more.
To read about the making of this library, see the Enumerables Without the Garbage series:
暂无开放 Issues,或尚未同步最近议题。