原文地址:
https://blog.csdn.net/jebe7282/article/details/7521067/

原因是因为现在在Unity里用曲线,要不就自己AnimationCurve自己扭一个曲线出来。要不就下载插件。然鹅,插件都封装了DLL, 我只用曲线,也不需要其他功能,买个插件岂不是浪费(不喜欢用盗版)。 找到一篇不是C#的tween算法,于是进行一波翻译。

public class Tween
{public static float GetTime(float time, float nDuration){return time > nDuration ? nDuration : time;}public static float Linear(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return nChange * time / nDuration + nBegin;}public class Quad{public static float easeIn(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return nChange * (time /= nDuration) * time + nBegin;}public static float easeOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return -nChange * (time /= nDuration) * (time - 2) + nBegin;}public static float easeInOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);if ((time /= nDuration / 2) < 1){return nChange / 2 * time * time + nBegin;}return -nChange / 2 * (--time * (time - 2) - 1) + nBegin;}}public class Cubic{public static float easeIn(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return nChange * (time /= nDuration) * time * time + nBegin;}public static float easeOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return nChange * ((time = time / nDuration - 1) * time * time + 1) + nBegin;}public static float easeInOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);if ((time /= nDuration / 2) < 1) return nChange / 2 * time * time * time + nBegin;return nChange / 2 * ((time -= 2) * time * time + 2) + nBegin;}}public class Quart{public static float easeIn(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return nChange * (time /= nDuration) * time * time * time + nBegin;}public static float easeOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return -nChange * ((time = time / nDuration - 1) * time * time * time - 1) + nBegin;}public static float easeInOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);if ((time /= nDuration / 2) < 1) return nChange / 2 * time * time * time * time + nBegin;return -nChange / 2 * ((time -= 2) * time * time * time - 2) + nBegin;}}public class Quint{public static float easeIn(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return nChange * (time /= nDuration) * time * time * time * time + nBegin;}public static float easeOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return nChange * ((time = time / nDuration - 1) * time * time * time * time + 1) + nBegin;}public static float easeInOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);if ((time /= nDuration / 2) < 1)return nChange / 2 * time * time * time * time * time + nBegin;return nChange / 2 * ((time -= 2) * time * time * time * time + 2) + nBegin;}}public class Sine{public static float easeIn(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return -nChange * Mathf.Cos(time / nDuration * (Mathf.PI / 2)) + nChange + nBegin;}public static float easeOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return nChange * Mathf.Sin(time / nDuration * (Mathf.PI / 2)) + nBegin;}public static float easeInOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return -nChange / 2 * (Mathf.Cos(Mathf.PI * time / nDuration) - 1) + nBegin;}}public class Expo{public static float easeIn(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);if (time == 0){return nBegin;}else{return nChange * Mathf.Pow(2, 10 * (time / nDuration - 1)) + nBegin;}}public static float easeOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);if (time == nDuration){return nBegin + nChange;}else{return nChange * (-Mathf.Pow(2, -10 * time / nDuration) + 1) + nBegin;}}public static float easeInOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);if (time == 0)return nBegin;if (time == nDuration)return nBegin + nChange;if ((time /= nDuration / 2) < 1)return nChange / 2 * Mathf.Pow(2, 10 * (time - 1)) + nBegin;return nChange / 2 * (-Mathf.Pow(2, -10 * --time) + 2) + nBegin;}}public class Circ{public static float easeIn(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return -nChange * (Mathf.Sqrt(1 - (time /= nDuration) * time) - 1) + nBegin;}public static float easeOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return nChange * Mathf.Sqrt(1 - (time = time / nDuration - 1) * time) + nBegin;}public static float easeInOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);if ((time /= nDuration / 2) < 1)return -nChange / 2 * (Mathf.Sqrt(1 - time * time) - 1) + nBegin;return nChange / 2 * (Mathf.Sqrt(1 - (time -= 2) * time) + 1) + nBegin;}}public class Elastic{public static float easeIn(float time, float nBegin, float nChange, float nDuration, float a = 0, float p = 0){time = GetTime(time, nDuration);if (time == 0)return nBegin;if ((time /= nDuration) == 1)return nBegin + nChange;if (p == 0)p = nDuration * 0.3f;float s = 0;if (a == 0 || a < Mathf.Abs(nChange)){a = nChange;s = p / 4;}elses = p / (2 * Mathf.PI) * Mathf.Asin(nChange / a);return -(a * Mathf.Pow(2, 10 * (time -= 1)) * Mathf.Sin((time * nDuration - s) * (2 * Mathf.PI) / p)) + nBegin;}public static float easeOut(float time, float nBegin, float nChange, float nDuration, float a = 0, float p = 0){time = GetTime(time, nDuration);if (time == 0)return nBegin;if ((time /= nDuration) == 1)return nBegin + nChange;if (p == 0)p = nDuration * 0.3f;float s = 0;if (a == 0 || a < Mathf.Abs(nChange)){a = nChange;s = p / 4;}elses = p / (2 * Mathf.PI) * Mathf.Asin(nChange / a);return (a * Mathf.Pow(2, -10 * time) * Mathf.Sin((time * nDuration - s) * (2 * Mathf.PI) / p) + nChange + nBegin);}public static float easeInOut(float time, float nBegin, float nChange, float nDuration, float a = 0, float p = 0){time = GetTime(time, nDuration);if (time == 0)return nBegin;if ((time /= nDuration / 2) == 2)return nBegin + nChange;if (p == 0)p = nDuration * (0.3f * 1.5f);float s = 0;if (a == 0 || a < Mathf.Abs(nChange)){a = nChange;s = p / 4;}elses = p / (2 * Mathf.PI) * Mathf.Asin(nChange / a);if (time < 1)return -0.5f * (a * Mathf.Pow(2, 10 * (time -= 1)) * Mathf.Sin((time * nDuration - s) * (2 * Mathf.PI) / p)) + nBegin;return a * Mathf.Pow(2, -10 * (time -= 1)) * Mathf.Sin((time * nDuration - s) * (2 * Mathf.PI) / p) * 0.5f + nChange + nBegin;}}public class Back{public static float easeIn(float time, float nBegin, float nChange, float nDuration, float s = 0){time = GetTime(time, nDuration);if (s == 0)s = 1.70158f;return nChange * (time /= nDuration) * time * ((s + 1) * time - s) + nBegin;}public static float easeOut(float time, float nBegin, float nChange, float nDuration, float s = 0){time = GetTime(time, nDuration);if (s == 0)s = 1.70158f;return nChange * ((time = time / nDuration - 1) * time * ((s + 1) * time + s) + 1) + nBegin;}public static float easeInOut(float time, float nBegin, float nChange, float nDuration, float s = 0){time = GetTime(time, nDuration);if (s == 0)s = 1.70158f;if ((time /= nDuration / 2) < 1)return nChange / 2 * (time * time * (((s *= (1.525f)) + 1) * time - s)) + nBegin;return nChange / 2 * ((time -= 2) * time * (((s *= (1.525f)) + 1) * time + s) + 2) + nBegin;}}public class Bounce{public static float easeIn(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);return nChange - easeOut(nDuration - time, 0, nChange, nDuration) + nBegin;}public static float easeOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);if ((time /= nDuration) < (1 / 2.75f)){return nChange * (7.5625f * time * time) + nBegin;}else if (time < (2 / 2.75f)){return nChange * (7.5625f * (time -= (1.5f / 2.75f)) * time + 0.75f) + nBegin;}else if (time < (2.5 / 2.75f)){return nChange * (7.5625f * (time -= (2.25f / 2.75f)) * time + 0.9375f) + nBegin;}else{return nChange * (7.5625f * (time -= (2.625f / 2.75f)) * time + 0.984375f) + nBegin;}}public static float easeInOut(float time, float nBegin, float nChange, float nDuration){time = GetTime(time, nDuration);if (time < nDuration / 2)return easeIn(time * 2, 0, nChange, nDuration) * 0.5f + nBegin;else return easeOut(time * 2 - nDuration, 0, nChange, nDuration) * 0.5f + nChange * 0.5f + nBegin;}}
}

程序学无止尽。
欢迎大家沟通,有啥不明确的,或者不对的,也可以和我私聊
我的QQ 334524067 神一般的狄狄

Unity,C#版的动画曲线,Tween:EaseIn,EaseOut,EaseInOut(编程语言翻译版本)相关推荐

  1. CSS 过渡与动画:transition 属性 ease-in, ease-out, ease-in-out

    简而言之: ease-in 加速, ease-out 减速, ease-in-out 先加速后减速, linear 匀速, ease 与 ease-in-out 类似. stack overflow ...

  2. Unity 动画曲线-AnimationCurve 实例

    Unity 动画曲线-AnimationCurve 实例 以Unity 自带的动画曲线实现一些简单的动画,如往复运动,曲线运动,不规则运动,掉血飘字等. 下面先上代码 using UnityEngin ...

  3. Unity Dotween插件的运动曲线(Ease)介绍Ease选项Ease效果示例以及C#修改动画曲线功能

    前言 我们在制作动画时经常使用这个Dotween插件,在移动.旋转.透明度等等参数的控制都可以使用该插件,而且在这个插件上的控制动画可以设置曲线,内置的曲线有这些: 内置曲线 以InOutSine的曲 ...

  4. Unity中的Animator动画详解

    Unity中的Animator动画详解 Animator动画导入 Animator动画详解 动画类型选择 Rig面板属性 Mode面板属性 Animation面板属性 动画片段 控制使用 Animat ...

  5. html动画曲线快速结束,CSS3 animation动画

    CSS3 animation动画 1.@keyframes 定义关键帧动画 2.animation-name 动画名称 3.animation-duration 动画时间 4.animation-ti ...

  6. swiftui动画之tab自定义切换动画_Unity动画系统详解1:在Unity中如何制作动画?

    摘要:在场景中加入动态的物体,可以让整个场景更加生动.真实.Unity场景中的物体可以通过制作动画,让物体动起来.简单的动画如物体的移动.旋转(比如旋转的风扇.闪烁不定的灯泡等),复杂的动画如游戏中角 ...

  7. iOS核心动画详解swift版----基础动画

    2019独角兽企业重金招聘Python工程师标准>>> iOS核心动画详解swift版---基础动画 创建工程,添加2个ViewController,通过rootViewContro ...

  8. Unity 3D 动画系统(Mecanim)|| Unity 3D 人形角色动画(Avatar)

    Unity 3D 动画系统(Mecanim) Mecanim 动画系统是 Unity 公司推出的全新动画系统,具有重定向.可融合等诸多新特性,可以帮助程序设计人员通过和美工人员的配合快速设计出角色动画 ...

  9. Unity动画系统详解1:在Unity中如何制作动画?

    摘要:在场景中加入动态的物体,可以让整个场景更加生动.真实.Unity场景中的物体可以通过制作动画,让物体动起来.简单的动画如物体的移动.旋转(比如旋转的风扇.闪烁不定的灯泡等),复杂的动画如游戏中角 ...

  10. Unity 2D教程 | 骨骼动画:创建动画

    转载自:2016-02-13 Unity官方平台 本教程主要讲解Unity引擎自带的2D骨骼动画工具,以及2D动画的基本概念.本篇会添加一些动画,如默认状态.跳动.坠落等. 基础动画理论 制作动画要牢 ...

最新文章

  1. core identity mysql_Asp.Net Core Identity 4 改成 MySql/MariaDB
  2. 【笔试题】简单的两道笔试题(1、打印杨辉三角;2、三个数排序)
  3. 基于MUI框架的HTML5+的二维码扫描实现
  4. 快手用旺旺瓶子做机器人_100品牌入榜,在快手的品牌运营怎么做?|11月快手品牌新势力榜揭晓...
  5. 呼呗电销机器人_为什么企业销售电销都用电销外呼智能机器人
  6. springcloud 注解 @EnableDiscoveryClient 与 @EnableEurekaClient 的区别
  7. php explore im,浏栏器-explore.class.php
  8. 夜读源码,带你探究 Go 语言的iota
  9. W​o​r​d​P​r​e​ss数据结构分析
  10. 别再用代码开发了!整理了30套精美可视化大屏模板,零套路直接领
  11. Gcc 完全参考手册,参数说明,操作指南-Gcc Complete referene
  12. 能被2、3、4、5、6、7、8、9、10、11、13、25整除的整数的特征是?有趣的21详解
  13. c语言贪吃蛇毕业论文,毕业论文c语言贪吃蛇
  14. java删除表格_Java 删除Word表格/表格内容
  15. nbu备份社区版mysql_mysql数据备份之NBU
  16. 《成都》钢琴谱,带指法和歌词
  17. DataMatrix 数据容量
  18. git撤回上一次push
  19. 前端实现旗帜飘动效果系列 (Ⅰ):dom+css实现
  20. python注册用户名和密码登录_Python_36用户名密码登录注册的例子

热门文章

  1. 陈睿:B站用户用创作展示传统文化之美
  2. 微信支付密码忘了怎么办
  3. 35岁以后你还能干嘛?
  4. 双耳节拍 枕头_枕头2-9-0快用完了
  5. python脚本爬取今日百度热点新闻
  6. 2022.10.23高沿坪易地扶贫 霜降
  7. hdmi线推荐微型计算机,几款高清线对比下来,这款mini dp转HDMI最实用
  8. 10款主流的软件测试工具,你用过吗
  9. 机器学习基础-Lagrange duality
  10. LIS3DH运动检测调试过程