Created
June 5, 2015 16:05
-
-
Save peroon/218b35c3232d236f04d3 to your computer and use it in GitHub Desktop.
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
using UnityEngine; | |
using UnityEngine.UI; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
public static class GameObjectExtensions | |
{ | |
// 直下の子供のみからコンポネント含むObjectのリストを取得 | |
public static T[] GetComponentsInChildrenBeneath<T>(this GameObject self) where T : Component | |
{ | |
var list = new List<T> (); | |
// 直下の子供 all | |
foreach (Transform trans in self.transform) { | |
var component = trans.gameObject.GetComponent<T>(); | |
if(component != null){ | |
list.Add(component); | |
} | |
} | |
return list.ToArray (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment