回到 Animator深入系列总目录

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();
} [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可以演示具体过程(录制时有些卡顿):

Unity-Animator深入系列---录制与回放的更多相关文章

  1. Fms3和Flex打造在线视频录制和回放

    本博推荐文章快速导航: Sql Server2005 Transact-SQL 新兵器学习MCAD学习 代码阅读总结 ASP.NET状态管理 DB(数据库)WAPWinFormFlex,Fms aie ...

  2. monkeyrunner之录制与回放(七)

    monkeyrunner为我们提供了录制 回放的功能. 录制与回放使用原因:实际项目,需求变更频繁,且测试任务多,我们没有足够时间去写测试脚本,这是就可以进行录制脚本,然后通过回放,跑完需要的流程. ...

  3. Android自动化学习笔记之MonkeyRunner:MonkeyRunner的录制和回放

    ---------------------------------------------------------------------------------------------------- ...

  4. IOS开发之小实例--创建一个简单的用于视频录制和回放的应用程序

    前言:还是看了一下国外的入门IOS文章:<Create a Simple App for Video Recording and Playback>,主要涉及视频录制和回放的功能的基本实现 ...

  5. TinyTask Portable(录制和回放电脑操作过程)

    一直想找个软件,可以回放自己或他人编码的过程.我认为,只有亲眼看到别人是怎么做的,才能更好的了解他人的思路. 虽然找到http://thecodeplayer.com/这个,但它只能回放它上面的代码, ...

  6. ROS_Kinetic_13 ROS数据录制与回放

    ROS_Kinetic_13 ROS数据录制与回放 官网教程:http://wiki.ros.org/cn/ROS/Tutorials/Recording%20and%20playing%20back ...

  7. 【转】Unity Animator卡顿研究

    Unity Animator卡顿研究 发表于2017-07-26  点赞3 评论3 分享 分享到 2.3k浏览 想免费获取内部独家PPT资料库?观看行业大牛直播?点击加入腾讯游戏学院游戏程序行业精英群 ...

  8. Android自动化测试之MonkeyRunner录制和回放脚本

    Android自动化测试之MonkeyRunner录制和回放脚本(十一) 分类: 自动化测试 Android自动化 2013-02-22 10:57 7346人阅读 评论(2) 收藏 举报 andro ...

  9. Linux下利用script命令录制并回放终端会话

    Linux下利用script命令录制并回放终端会话 核心命令 script 和 scriptreplay 录制屏幕 script -t 2>timescript typescript 命令解释: ...

随机推荐

  1. tomcat部署方法总结

    可以参考之前的:http://www.cnblogs.com/youxin/archive/2013/01/18/2865814.html 在Tomcat中部署Java Web应用程序有两种方式:静态 ...

  2. Object-C 入门

    该文章转载自:http://sheng.iteye.com/blog/775588一:Objective-C入门 .Cocoa的组成 苹果公司将Cocoa.Carbon.QuickTime和OpenG ...

  3. sdutoj 2603 Rescue The Princess

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2603 Rescue The Princess ...

  4. acm算法模板(4)

    杂乱小模板 状态压缩dp小技巧 x&-x是取x的最后一个1的位置. x-=x&-x是去掉x的最后一个1. 读入外挂 int nxt_int(){// neg or pos    cha ...

  5. zjuoj 3609 Modular Inverse

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3609 Modular Inverse Time Limit: 2 Seco ...

  6. .NET: C#: 获取当前路径

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...

  7. collection和collections区别

    collection和collections区别 collection-->是集合类的上级接口,继承他的接口主要有set,list collections-->是针对集合类的一个帮助类,提 ...

  8. Android 利用Service BroadcastReceiver实现小例子

    Activity: package com.example.test; import android.app.Activity; import android.content.Context; imp ...

  9. Dr.Kong的艺术品

    题目 Dr.Kong设计了一件艺术品,该艺术品由N个构件堆叠而成,N个构件从高到低按层编号依次为1,2,……,N.艺术品展出后,引起了强烈的反映.Dr.Kong观察到,人们尤其对作品的高端部分评价甚多 ...

  10. 查看在线EBS用户的相关信息

    --查看在线EBS用户的相关信息 SELECT PAP.FULL_NAME, FU.USER_NAME, FAT.APPLICATION_NAME, FRT.RESPONSIBILITY_NAME, ...