Version: 5.4

GameObject.GetComponentsInChildren

Switch to Manual
public Component[] GetComponentsInChildren (Type type, bool includeInactive= false);

Parameters

type @param type Тип возвращаемого компонента.
includeInactive @param includeInactive Следует ли включать неактивные компоненты в список найденных?

Description

Возвращает все компоненты типа type из GameObject'а или из любого его потомка.

Поиск компонентов осуществляется рекурсивно по дочерним объектам, поэтому поиск включает детей, внуков и т.д.

using UnityEngine;

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

hingeJoints = GetComponentsInChildren( typeof(HingeJoint) );

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

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

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

Parameters

includeInactive @param includeInactive Следует ли включать неактивные компоненты в список найденных?

Returns

T[] A list of all found components matching the specified type.

Description

Дженерик функции. Для получения дополнительной информации смотрите страницу, посвященную Дженерик функциям.

using UnityEngine;

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

hingeJoints = GetComponentsInChildren<HingeJoint>( );

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

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

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

Parameters

results List to receive found Components.
includeInactive @param includeInactive Следует ли включать неактивные компоненты в список найденных?

Description

Return all found Components into List results.

using UnityEngine;
using System.Collections.Generic;

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

GetComponentsInChildren<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>();

GetComponentsInChildren<HingeJoint>( true, hingesInactive );

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