Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peroon/218b35c3232d236f04d3 to your computer and use it in GitHub Desktop.
Save peroon/218b35c3232d236f04d3 to your computer and use it in GitHub Desktop.
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