Last active
March 12, 2024 13:09
Revisions
-
dmitry1100 revised this gist
Nov 14, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ public static IEnumerable<Transform> AllChildren ( this Transform t ) private class DeepEnumerator : IEnumerator<Transform>, IEnumerable<Transform> { private readonly Transform _root; private Transform _current; private Stack<Transform> _stack; -
dmitry1100 revised this gist
Nov 14, 2019 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,6 @@ using System.Collections.Generic; using UnityEngine; namespace Fiftytwo { public static class TransformAllChildren -
dmitry1100 revised this gist
Nov 14, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ namespace Fiftytwo { public class TransformAllChildrenTest : MonoBehaviour { // Will be called just after component attached to GameObject private void Reset () { foreach ( var child in transform.AllChildren() ) -
dmitry1100 renamed this gist
Nov 14, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
dmitry1100 renamed this gist
Nov 14, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ namespace Fiftytwo { public class TransformAllChildrenTest : MonoBehaviour { private void Reset () { -
dmitry1100 created this gist
Nov 14, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ using UnityEngine; namespace Fiftytwo { public class TestTransformAllChildren : MonoBehaviour { private void Reset () { foreach ( var child in transform.AllChildren() ) { Debug.Log( child.name ); } } } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Fiftytwo { public static class TransformAllChildren { public static IEnumerable<Transform> AllChildren ( this Transform t ) { return new DeepEnumerator( t ); } private class DeepEnumerator : IEnumerator<Transform>, IEnumerable<Transform> { private Transform _root; private Transform _current; private Stack<Transform> _stack; internal DeepEnumerator ( Transform root ) { _root = root; _current = root; _stack = new Stack<Transform>(); } public Transform Current { get { return _current; } } object IEnumerator.Current { get { return _current; } } void IDisposable.Dispose () { } public bool MoveNext () { for( var i = _current.childCount; --i >= 0; ) _stack.Push( _current.GetChild( i ) ); if( _stack.Count == 0 ) return false; _current = _stack.Pop(); return true; } public void Reset () { _current = _root; _stack.Clear(); } public IEnumerator<Transform> GetEnumerator () { Reset(); return this; } IEnumerator IEnumerable.GetEnumerator () { return GetEnumerator(); } } } }