NeoCollections

NeoCollections is a simple class library which allows AOT-safe iterations in Unity3D

View the Project on GitHub jnbt/NeoCollections

NeoCollections: A class library for (AOT-safe) collections for Unity3D


03/25/2015: Unity now supports the new IL2CPP compiler for iOS the bug regarding the AOT compilation of generic interfaces went away. Just update NeoCollections to get rid of the overhead introduced to circumvent the AOT-bug.


NeoCollections is a legacy class library which allowed AOT-safe iterations in Unity3D. This may sound strange as Mono / C# supports standard collection classes and the famous foreach loop, but these feature sometime break on iOS. (Further information about this can be found here and here).

Installation

If you don't have access to Microsoft VisualStudio you can just use Unity3D and its compiler. Or use your VisualStudio installation in combination with Visual Studio Tools for Unity to compile a DLL-file, which can be included into your project.

Using Unity3D

Using VisualStudio

Usage

Array Extensions

For convenience the default Array classes are extended to directly iterate over them:

var someStrings = new string[]{"Here", "are", "some", "strings"};

// Without NeoCollections
foreach(var s in someStrings){
  UnityEngine.Debug.Log(s);
}

// With NeoCollections
someStrings.ForEach(s => UnityEngine.Debug.Log(s));

// or even shorter as you can provide the called function
// as a reference
someStrings.ForEach(UnityEngine.Debug.Log);

Standard collection classes

The library contains improved subclasses of the most common standard generic collection classes:

// Without NeoCollections
using System.Collections.Generic;

var someStrings = new List<string>(){"Here", "are", "some", "strings"};

foreach(var s in someStrings){
  UnityEngine.Debug.Log(s);
}

// With NeoCollections
using Neo.Collections;

var someStrings = new List<string>(){"Here", "are", "some", "strings"};

someStrings.ForEach(s => UnityEngine.Debug.Log(s));

Testing

You can run the tests using the offical Unity Testing Tools. Just install the Unity package and use the Unit Test Runner.