Unity-Animator深入系列---录制与回放
2016-01-02 20:50
465 查看
回到 Animator深入系列总目录
Animator自带了简单的动画录制,回放功能。但可惜的是不支持持久化的数据输出。因而不能作为录像保存
不过这种可以作为竞速,格斗类游戏在结束时经常出现的游戏回放,还是比较有用的
测试所用脚本
AnimatorRecordingExample
调用方式:
写了一个比较简单的脚本测试录制功能
大致逻辑是先调用StartRecording进行录制,结束时调用StopRecording
然后再需要时进行回放,需要注意调用StartPlayback开始回放之后,回放的时间需要手动更新
每一帧的更新值可以使用DeltaTime,而开始值可以用animator.recorderStartTime
这时,还需要判断playback的时间是否大于录制结束时间,否则会有警告:
还需要注意两点
1.animator.StartRecording(...)的参数如果小于1,会被判定为不限时间录制。
2.非Animator驱动的位移,都会被录制进去。由于Animator的更新时间是在Update之后,LateUpdate之前。
所以移动控制写在LateUpdate里的时候,在回播时会有操作冲突
下面这个gif可以演示具体过程(录制时有些卡顿):
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; } }
AnimatorRecordingExample
调用方式:
写了一个比较简单的脚本测试录制功能
大致逻辑是先调用StartRecording进行录制,结束时调用StopRecording
然后再需要时进行回放,需要注意调用StartPlayback开始回放之后,回放的时间需要手动更新
每一帧的更新值可以使用DeltaTime,而开始值可以用animator.recorderStartTime
这时,还需要判断playback的时间是否大于录制结束时间,否则会有警告:
Animator Recorder does not have recorded data at given time, Animator will update based on current AnimatorParameters
还需要注意两点
1.animator.StartRecording(...)的参数如果小于1,会被判定为不限时间录制。
2.非Animator驱动的位移,都会被录制进去。由于Animator的更新时间是在Update之后,LateUpdate之前。
所以移动控制写在LateUpdate里的时候,在回播时会有操作冲突
下面这个gif可以演示具体过程(录制时有些卡顿):
相关文章推荐
- 借助TinyXml,C++实现Unity的PlayerPrefs 功能
- unity与3DMax的单位问题
- Unity3D之坐标变化
- Unity3D之float Input.GetAxis(string axisname)
- Unity5脚本事件函数及其执行顺序
- Unity3D 经常使用库
- [转]How to translate WORLD coordinates to TERRAIN coordinates in Unity3d
- Unity-Animator深入系列---StateMachineBehaviour状态机脚本学习
- Unity+NGUI性能优化方法总结
- unity 2D总结(转发 忘记源地址了)
- unity4.6_摄像机跟随模式、观察模式融合(平滑)
- Unity3D教程:动画融合、动画层、动画混合、附加动画、程序动画、动画重放和取样
- Unity3D与Android,iOS交互
- 使用VS调试Unity脚本
- Unity 官方 Demo: 2DPlatformer 的 SLua 版本。
- unity中特殊文件夹
- Unity3D研究院之两种方式播放游戏视频
- Unity3d Fast Indirect illumination Using Two Virtual Spherical Gaussian Lights-Square Enix论文 ver 2
- unity3d游戏开发之UV贴图教程
- 【学习笔记】 Unity中在点击UI时屏蔽游戏内点击事件