Animations.GameObjectRecorder.BindComponentsOfType

Unity · Версия 2020.3 LTS · Scripting · GameObjectRecorder

Animations.GameObjectRecorder.BindComponentsOfType

Объявление

public void BindComponentsOfType(GameObject target, bool recursive);

public void BindComponentsOfType(GameObject target, Type componentType, bool recursive);

Параметры

target root or any of its children.
recursive Привязывает также свойства преобразования target дочерних элементов, если установлено значение true.
componentType Тип компонента.

Описание

Добавляет привязки для всех свойств первого компонента типа T, найденного в target, а также для всех дочерних элементов target. если recursive равно true.

using UnityEngine;
using UnityEditor;
using UnityEditor.Animations;

public class BindComponentScript : MonoBehaviour
{
    void Start()
    {
        var recorder = new GameObjectRecorder(gameObject);

        // Add bindings for all the properties of the Transform and BoxCollider components.
        recorder.BindComponentsOfType<Transform>(gameObject, false);
        recorder.BindComponentsOfType<BoxCollider>(gameObject, false);
    }
}

Также можно использовать необобщенный метод, и в этом случае typeof() получит тип компонента.

Этот пример дает точно такой же результат, как и пример выше:

using UnityEngine;
using UnityEditor;
using UnityEditor.Animations;

public class BindComponentNonGenericScript : MonoBehaviour
{
    void Start()
    {
        var recorder = new GameObjectRecorder(gameObject);

        recorder.BindComponentsOfType(gameObject, typeof(Transform), false);
        recorder.BindComponentsOfType(gameObject, typeof(BoxCollider), false);
    }
}

Обновлено 17 ноября 2026 г.