Last active
June 29, 2016 07:32
-
-
Save JakubNei/c6cbb6895d8d98fbe583 to your computer and use it in GitHub Desktop.
What needs to be changed in Unity's Transform to implement IEnumerable<Transform> plus IList<Transform> GetChildren() method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class Transform : IEnumerable, IEnumerable<Transform> | |
{ | |
private sealed class Enumerator : IEnumerator, IEnumerator<Transform> | |
{ | |
private Transform outer; | |
private int currentIndex = -1; | |
object IEnumerator.Current | |
{ | |
get | |
{ | |
return this.outer.GetChild(this.currentIndex); | |
} | |
} | |
Transform IEnumerator<Transform>.Current | |
{ | |
get | |
{ | |
return this.outer.GetChild(this.currentIndex); | |
} | |
} | |
internal Enumerator(Transform outer) | |
{ | |
this.outer = outer; | |
} | |
public bool MoveNext() | |
{ | |
int childCount = this.outer.childCount; | |
return ++this.currentIndex < childCount; | |
} | |
public void Reset() | |
{ | |
this.currentIndex = -1; | |
} | |
public void Dispose() | |
{ | |
} | |
} | |
IEnumerator<Transform> IEnumerable<Transform>.GetEnumerator() | |
{ | |
return new Enumerator(this); | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return new Enumerator(this); | |
} | |
public IList<Transform> GetChildren() | |
{ | |
var childs = new Transform[childCount]; | |
for (int i = 0; i < childs.Length; i++) | |
{ | |
childs[i] = GetChild(i); | |
} | |
return childs; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment