在场景运行时记录 GameObject 的变化属性,并将信息保存到 AnimationClip 中。
此类绑定 GameObject 属性,记录它们在运行场景中发生变化时的值,并将结果保存到 AnimationClip 中。记录的 GameObject 在类中称为 root,您还可以绑定 root 的任何子对象的属性。
请参阅以下代码示例,了解如何实现此类以及设置记录的内容。
using UnityEngine; using UnityEditor.Animations;
public class RecordTransformHierarchy : MonoBehaviour { public AnimationClip clip;
private GameObjectRecorder m_Recorder;
void Start() { // Create recorder and record the script GameObject. m_Recorder = new GameObjectRecorder(gameObject);
// Bind all the Transforms on the GameObject and all its children. m_Recorder.BindComponentsOfType<Transform>(gameObject, true); }
void LateUpdate() { if (clip == null) return;
// Take a snapshot and record all the bindings values for this frame. m_Recorder.TakeSnapshot(Time.deltaTime); }
void OnDisable() { if (clip == null) return;
if (m_Recorder.isRecording) { // Save the recorded session to the clip. m_Recorder.SaveToClip(clip); } } }
| currentTime | 返回录制当前时间。(只读) | 
| isRecording | 当录制器正在录制时返回 true。(只读) | 
| root | 动画层次结构的 GameObject 根。(只读) | 
| GameObjectRecorder | 创建一个新的 GameObjectRecorder。 | 
| Bind | 根据 EditorCurveBinding 绑定 GameObject 的属性。 | 
| BindAll | 为目标的所有属性添加绑定,如果 recursive 为 true,则还为目标的所有子级添加绑定。 | 
| BindComponent | 为组件的所有属性添加绑定。 | 
| BindComponentsOfType | 为目标中找到的第一个类型为 T 的组件的所有属性添加绑定,如果 recursive 为 true,则还为目标的所有子级添加绑定。 | 
| GetBindings | 返回添加到录制器的所有绑定的数组。 | 
| ResetRecording | 重置录制。 | 
| SaveToClip | 将录制好的动画保存到目标剪辑中。 | 
| TakeSnapshot | 将动画向前推进 dt 秒,然后记录添加的绑定的值。 | 
| GetInstanceID | 获取对象的实例 ID。 | 
| ToString | 返回对象的名称。 | 
| Destroy | 移除 GameObject、组件或资源。 | 
| DestroyImmediate | 立即销毁对象 obj。强烈建议使用 Destroy 代替。 | 
| DontDestroyOnLoad | 加载新场景时不要销毁目标对象。 | 
| FindAnyObjectByType | 检索类型为 type 的任何活动加载对象。 | 
| FindFirstObjectByType | 检索类型为 type 的第一个活动加载对象。 | 
| FindObjectsByType | 检索类型为 type 的所有加载对象的列表。 | 
| Instantiate | 克隆对象 original 并返回克隆。 | 
| InstantiateAsync | 捕获原始对象(必须与某个 GameObject 相关)的快照,并返回 AsyncInstantiateOperation。 | 
| bool | 对象是否存在? | 
| operator != | 比较两个对象是否引用不同的对象。 | 
| operator == | 比较两个对象引用,查看它们是否引用同一个对象。 |