Animator自带了简单的动画录制,回放功能。但可惜的是不支持持久化的数据输出。因而不能作为录像保存
不过这种可以作为竞速,格斗类游戏在结束时经常出现的游戏回放,还是比较有用的
测试所用脚本
using UnityEngine; public class AnimatorRecordingExample : MonoBehaviour { public Animator animator; bool mIsStartPlayback; float mTime; void Update() { if (mIsStartPlayback) { mTime += Time.deltaTime; if (animator.recorderStopTime > mTime) { animator.playbackTime = mTime; Debug.Log("animator.playbackTime: " + animator.playbackTime); } } else { Debug.Log("animator.recorderStartTime " + animator.recorderStartTime); Debug.Log("animator.recorderStopTime: " + animator.recorderStopTime); } } [ContextMenu("StartRecording")] void StartRecording() { animator.StartRecording(0); } [ContextMenu("StopRecording")] void StopRecording() { animator.StopRecording(); } [ContextMenu("StartPlayback")] void StartPlayback() { animator.StartPlayback(); mTime = animator.recorderStartTime; mIsStartPlayback = true; } [ContextMenu("StopPlayback")] void StopPlayback() { animator.StopPlayback(); mIsStartPlayback = false; } }