以下の内容はhttps://baba-s.hatenablog.com/entry/2014/11/17/100849より取得しました。


【Unity】孫オブジェクトを除くすべての子オブジェクトを取得する拡張メソッド

ソースコード

using System.Collections.Generic;
using UnityEngine;

public static class GameObjectExtensions
{
    /// <summary>
    /// 孫オブジェクトを除くすべての子オブジェクトを返します
    /// </summary>
    public static GameObject[] GetChildrenWithoutGrandchild( 
        this GameObject self 
    )
    {
        var result = new List<GameObject>();
        foreach ( Transform n in self.transform )
        {
            result.Add( n.gameObject );
        }
        return result.ToArray();
    }
}

使い方

var children = gameObject.GetChildrenWithoutGrandchild();

関連記事




以上の内容はhttps://baba-s.hatenablog.com/entry/2014/11/17/100849より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14