http://blog.csdn.net/ynnmnm/article/details/46866347

最近在调战斗时的动画与特效,Unity3D对加/减速提供了Time.timeScale支持。但是,timeScale提供的是全局的时间缩放,而我们有些动作或动画是不希望被timeScale加减速的。比如,《刀塔传奇》中播放大招时,除了大招特效,所有别的动作/动画都暂停。

下面分别是Animation、Animator和粒子特效的ignoreTimeScale方法。

Animation

Time.realtimeSinceStartup记录是不受timeScale影响的真实时间,利用它来在每一帧采样播放Animation。代码片段如下:

<code class="hljs glsl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">AnimationState animState = animation[clipName]; <span class="hljs-comment" style="margin: 0px; padding: 0px; color: rgb(136, 0, 0); box-sizing: border-box;">// 当前动画状态</span>

curTime = Time.realtimeSinceStartup; <span class="hljs-comment" style="margin: 0px; padding: 0px; color: rgb(136, 0, 0); box-sizing: border-box;">// 当前真实时间</span>
deltaTime = curTime - lastFrameTime; <span class="hljs-comment" style="margin: 0px; padding: 0px; color: rgb(136, 0, 0); box-sizing: border-box;">// 此帧与上一帧的时间间隔</span>
lastFrameTime = curTime; <span class="hljs-comment" style="margin: 0px; padding: 0px; color: rgb(136, 0, 0); box-sizing: border-box;">// 记录此帧时间,下一帧用</span>
progressTime += deltaTime; <span class="hljs-comment" style="margin: 0px; padding: 0px; color: rgb(136, 0, 0); box-sizing: border-box;">// 动画已播放时间</span>
animState.normalizedTime = progressTime / currState.<span class="hljs-built_in" style="margin: 0px; padding: 0px; color: rgb(102, 0, 102); box-sizing: border-box;">length</span>; <span class="hljs-comment" style="margin: 0px; padding: 0px; color: rgb(136, 0, 0); box-sizing: border-box;">// 动画规范化时间[0-1]</span>
animation.Sample(); <span class="hljs-comment" style="margin: 0px; padding: 0px; color: rgb(136, 0, 0); box-sizing: border-box;">// 在当前状态对动画进行采样,当你想显式设置动画状态并且对它取样的时候使用</span></code><ul class="pre-numbering" style="margin: 0px; padding: 6px 0px 40px; box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">1</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">2</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">3</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">4</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">5</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">6</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">7</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">8</li></ul><ul class="pre-numbering" style="margin: 0px; padding: 6px 0px 40px; box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">1</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">2</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">3</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">4</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">5</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">6</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">7</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">8</li></ul>

Animator

<code class="hljs r has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">Animator _animator = <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 136); box-sizing: border-box;">...</span>;
public void Update() {
_animator.updateMode = AnimatorUpdateMode.UnscaledTime; // 指定该Animator更新模式为不受scale影响
}</code><ul class="pre-numbering" style="margin: 0px; padding: 6px 0px 40px; box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">1</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">2</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">3</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">4</li></ul><ul class="pre-numbering" style="margin: 0px; padding: 6px 0px 40px; box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">1</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">2</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">3</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">4</li></ul>

粒子特效

对于ParticleEmitter

<code class="hljs r has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">ParticleEmitter _emitter = <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 136); box-sizing: border-box;">...</span>;
public void Update() {
_emitter.Simulate(Time.unscaledDeltaTime);
}</code><ul class="pre-numbering" style="margin: 0px; padding: 6px 0px 40px; box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">1</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">2</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">3</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">4</li></ul><ul class="pre-numbering" style="margin: 0px; padding: 6px 0px 40px; box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">1</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">2</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">3</li><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">4</li></ul>

对于ParticleSystem

<code class="hljs r has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">ParticleSystem _particleSystem = <span class="hljs-keyword" style="margin: 0px; padding: 0px; color: rgb(0, 0, 136); box-sizing: border-box;">...</span>;
public void Update() {
_particleSystem.Simulate(Time.unscaledDeltaTime, true, false);
}</code>

Unity3D - 动作动画忽略timeScale的更多相关文章

  1. (转)Unity3D - 动作动画忽略timeScale

    转自:http://blog.csdn.net/ynnmnm/article/details/46866347 最近在调战斗时的动画与特效,Unity3D对加/减速提供了Time.timeScale支 ...

  2. Unity学习疑问记录之 动作动画忽略timeScale

    http://www.bubuko.com/infodetail-968864.html

  3. Unity3D 骨骼动画原理学习笔记

    最近研究了一下游戏中模型的骨骼动画的原理,做一个学习笔记,便于大家共同学习探讨. ps:最近改bug改的要死要活,博客写的吭哧吭哧的~ 首先列出学习参考的前人的文章,本文较多的参考了其中的表述: 1. ...

  4. 浅谈Unity3D 骨骼动画

    转载请标明出处http://www.cnblogs.com/zblade/ 最近研究了一下游戏中模型的骨骼动画的原理,做一个学习笔记,便于大家共同学习探讨. ps:最近改bug改的要死要活,博客写的吭 ...

  5. Unity3d Mecanim动画系统Animator学习笔记

    1. unity3d Mecanim学习  Unity3d新版动画系统网上的介绍很多,但多是流水笔记,外人很难看明白,后来我 终于找到介绍的比较明白的两个作者,特别感谢.一个是58开发网的乐天老师,课 ...

  6. Unity3D Mecanim 动画系统骨骼动画问题解决方法

    http://7dot9.com/2014/08/16/unity3d-mecanim%E5%8A%A8%E7%94%BB%E7%B3%BB%E7%BB%9F%E9%AA%A8%E9%AA%BC%E5 ...

  7. Unity3D骨骼动画的分解(CleanData.Ani详解)

    CleanData是什么 CleanData以前没有特定的名字,(在easydown这个开源项目中,作为一个GameObjParser模块存在).在某三国项目中,我们使用GameObjParser将N ...

  8. unity3d 纹理动画

    不知道大家有没有玩过赛车游戏 赛车游戏的跑道有路标,如下图 玩过赛车游戏的都知道,大多数赛车游戏的路标是会动的,如上图,它会从右往左运动 不会发动态图,大家脑补一下吧 没有玩过赛车游戏的也不要紧,大家 ...

  9. unity3d 射线扫描 忽略图层

    原地址:http://blog.csdn.net/w88193363/article/details/38331205 函数说明 static RaycastHit2D[] RaycastAll(Ve ...

随机推荐

  1. 面向对象基础——String类

    String类的两种实例化方法  A:直接赋值 public class StringDemo01{ public static void main(String args[]){ String na ...

  2. 线程中调用Updatedata的问题

    随便发个自定义消息,然后在 CMyDialog的自定义消息处理函数中 UpdateDate().因为 UpdateDate用到了线程本地存储.不能跨线程的 UpdateData只能在主线程中使用,将U ...

  3. java object monitor

    1 什么是java object monitor 每个java对象头中都有锁状态位标记.java中在使用synchronize同步的时候,肯定是涉及到某个对象的锁.因此,在考虑同步的时候,首先要想到是 ...

  4. 杭电 2553 N皇后问题

    http://acm.hdu.edu.cn/showproblem.php?pid=2553 N皇后问题 Time Limit: 2000/1000 MS (Java/Others)    Memor ...

  5. Javascript学习之三元运算符详解

    本文主要是通过实例为大家介绍javascript三元运算符相关内容,希望对初学者学习这部分内容有所帮助. 实例 <!DOCTYPE html> <html> <head& ...

  6. 修改MySQL的连接数

    实际项目中出现“too many connnections...”错误提示,发现MySQL的最大连接数满了,于是我就查了一下使用的MySQL的最大连接数是多少? 安装好数据库也没有修改过,这应该是默认 ...

  7. 对xml文件的sax解析(增删改查)之二

    先上代码: package com.saxparsetest; //the filename of this file is :saxparse.java import javax.xml.parse ...

  8. Piggy-Bank(复习完全背包)

    传送门 题目大意: 有一个存钱的储存罐,给你它存满钱之前和之后的重量,和几类硬币的面值和重量. 求装满储钱罐时最小能得到多少钱. 题解:完全背包变形. 因为要求最小 一开始赋值大数. code: #i ...

  9. poj 2420 A Star not a Tree? —— 模拟退火

    题目:http://poj.org/problem?id=2420 给出 n 个点的坐标,求费马点: 上模拟退火. 代码如下: #include<iostream> #include< ...

  10. HttpClient入门教程

    HttpClient使用详解与实战一:https://www.jianshu.com/p/375be5929bed