Skip to content

Instantly share code, notes, and snippets.

@frarees
Last active August 29, 2015 14:08
Show Gist options
  • Save frarees/e3eb9dff9a9dcedbb28f to your computer and use it in GitHub Desktop.
Save frarees/e3eb9dff9a9dcedbb28f to your computer and use it in GitHub Desktop.
Unity Serialization & Interfaces
// I'd like to serialize the GetComponents result straight away when getting components via interface
// That would avoid allocating more memory for another list that can be serialized
// signature: void GetComponents<T, K> (List<T> result) where T : Component;
public class MyBehaviour : MonoBehaviour, ICustom {
List<MonoBehaviour> behaviours = new List<MonoBehaviour> ();
void Awake () {
GetComponents<MonoBehaviour, ICustom> (behaviours);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment