Version: 5.4
public Component[] GetComponentsInParent (Type type, bool includeInactive= false);

パラメーター

type 取得するコンポーネントの型
includeInactive 非アクティブのコンポーネントも含めるかどうか

説明

ゲームオブジェクトまたはその親たちから type のすべてのコンポーネントを返します

コンポーネントの検索は親オブジェクトを再帰的に事項されるので親の親、さらに親 ... というように含むことになります。

using UnityEngine;

public class GetComponentsInParentExample : MonoBehaviour { void Start( ) { Component[] hingeJoints;

hingeJoints = GetComponentsInParent( typeof(HingeJoint) );

if( hingeJoints != null ) { foreach( HingeJoint joint in hingeJoints ) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects Component[] hingesInactive = GetComponentsInParent( typeof(HingeJoint), true );

foreach( HingeJoint joint in hingesInactive ) joint.useSpring = false; }

}

}

public T[] GetComponentsInParent ();
public T[] GetComponentsInParent (bool includeInactive);

パラメーター

includeInactive 非アクティブのコンポーネントも含めるかどうか

説明

ジェネリック版。詳細については Generic Functions を参照してください。

using UnityEngine;

public class GetComponentsInParentExample : MonoBehaviour { void Start( ) { HingeJoint[] hingeJoints;

hingeJoints = GetComponentsInParent<HingeJoint>( );

if( hingeJoints != null ) { foreach( HingeJoint joint in hingeJoints ) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects HingeJoint[] hingesInactive = GetComponentsInParent<HingeJoint>( true );

foreach( HingeJoint joint in hingesInactive ) joint.useSpring = false; } } }

public void GetComponentsInParent (bool includeInactive, List<T> results);

パラメーター

includeInactive 非アクティブのコンポーネントも含めるかどうか
results 見つかったコンポーネントを受け取るリスト

説明

ゲームオブジェクトや親のコンポーネントを見つけ、リスト results に返します。

using UnityEngine;
using System.Collections.Generic;

public class GetComponentsInParentExample : MonoBehaviour { void Start( ) { List<HingeJoint> hingeJoints = new List<HingeJoint>();

GetComponentsInParent<HingeJoint>( false, hingeJoints );

if( hingeJoints != null ) { foreach( HingeJoint joint in hingeJoints ) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects List<HingeJoint> hingesInactive = new List<HingeJoint>();

GetComponentsInParent<HingeJoint>( true, hingesInactive );

foreach( HingeJoint joint in hingesInactive ) joint.useSpring = false; } } }