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


【Unity】インターフェイスを指定して子オブジェクトからコンポーネントを取得する拡張メソッド

ソースコード

using UnityEngine;

public static class GameObjectExtensions
{
    /// <summary>
    /// インターフェイスを指定して子オブジェクトからコンポーネントを取得します
    /// </summary>
    public static T GetInterfaceOfComponentInChildren<T>( 
        this GameObject self, 
        bool includeInactive 
    ) where T : class
    {
        foreach ( var n in self.GetComponentsInChildren<Component>( includeInactive ) )
        {
            var component = n as T;
            if( component != null )
            {
                return component;
            }
        }
        return null;
    }
    
    /// <summary>
    /// インターフェイスを指定して子オブジェクトからコンポーネントを取得します
    /// </summary>
    public static T GetInterfaceOfComponentInChildren<T>( this GameObject self ) where T : class
    {
        return self.GetInterfaceOfComponentInChildren<T>( false );
    }
}

関連記事




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

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