ソースコード
using UnityEngine; public static class GameObjectExt { public static Component[] GetComponentsInChildren( this GameObject self, string type, bool includeInactive ) { return self .GetComponentsInChildren<Transform>( includeInactive ) .Select( c => c.gameObject.GetComponent( type ) ) .Concat( new []{ self.GetComponent( type ) } ) .Where( c => c != null ) .ToArray(); ; } }
使い方
var list = gameObject.GetComponentsInChildren( "BoxCollider" );