Version: 2017.2
Experimental: this API is experimental and might be changed or removed in the future.

GameObjectRecorder.BindComponent

切换到手册
public void BindComponent (GameObject target, bool recursive);
public void BindComponent (GameObject target, Type componentType, bool recursive);

参数

target root 或其任何子项。
recursive 当设置为 true 时,也要绑定 target 子项的变换组件属性。
componentType 组件类型。

描述

target 中的首个 T 类型组件的所有属性添加绑定;如果 recursivetrue ,也要为 target 子项的所有属性添加绑定。

using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Animations;

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

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

您也可以使用非通用方法,在这种情况下,typeof() 将获得组件的类型属性。

此示例获得的结果与上面的示例完全相同:

using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Animations;

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

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