Last active
September 29, 2015 09:22
-
-
Save FreyaHolmer/7d7e920b95723f89fc3b to your computer and use it in GitHub Desktop.
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 characters
using UnityEngine; | |
using System.Collections.Generic; | |
public static class GameObjectExtensions { | |
public static T[] GetComponentsInChildrenOfAsset<T>( this GameObject go ) where T : Component { | |
List<Transform> tfs = new List<Transform>(); | |
CollectChildren( tfs, go.transform ); | |
List<T> all = new List<T>(); | |
for (int i = 0; i < tfs.Count; i++) | |
all.AddRange( tfs[i].gameObject.GetComponents<T>() ); | |
return all.ToArray(); | |
} | |
static void CollectChildren( List<Transform> transforms, Transform tf){ | |
transforms.Add(tf); | |
foreach(Transform child in tf){ | |
CollectChildren(transforms, child); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment