Unity 缓动 DoTween Pro

http://dotween.demigiant.com/pro.php

1.安装

下载:http://dotween.demigiant.com/download
解压缩到Assets目录下任意目录,不要放到Editor,Plugins,Resources下

2.初始化

安装好后tools下可以找到此菜单“ Tools/Demigiant”


image.png

点击“ Setup DOTween”


3.代码配置

引用

using DG.Tweening;

初始化配置

DOTween.Init(autoKillMode, useSafeMode, logBehaviour);

可选,如果不设置就按照默认进行,要在第一次DoTween调用前使用

4. 使用

A 直接使用

DOTween.To(()=>myValue, x=>myValue=x, 100, 1);

这句意思是将属性变量名myValue配置为缓动曲线,执行使用的是lamda表达式,100为目标值,1为时间长度1秒


B transform调用

你可以直接使用transfrom的扩展api


image.png

C 倒退

DOTween.RewindAll();
DOTween.Rewind(myId);
myTween.Rewind();
transform.DORewind();

D from方法

从给定的值移动到当前位置点,带true是相对位置
transform.DOMoveX(2, 1).From();
transform.DOMoveX(2, 1).From(true);

E 事件

// Callback without parameters
transform.DOMoveX(4, 1).OnComplete(MyCallback);
// Callback with parameters
transform.DOMoveX(4, 1).OnComplete(()=>MyCallback(someParam, someOtherParam));

F 参数

设置循环和缓动曲线

TweenParams tParms = new TweenParams().SetLoops(-1).SetEase(Ease.OutElastic);
// Apply them to a couple of tweens
transformA.DOMoveX(15, 1).SetAs(tParms);
transformB.DOMoveY(10, 1).SetAs(tParms);

这样做可以节省对每个分别设置相同的值

G 暂停 Pause

// Pauses all tweens
DOTween.PauseAll();
// Pauses all tweens that have "badoom" as an id
DOTween.Pause("badoom");
// Pauses all tweens that have someTransform as a target
DOTween.Pause(someTransform);

myTween.Pause();
transform.DOPause();

H 数值浮动

对数值进行缓动

DOVirtual.Float(float from, float to, float duration, TweenCallback<float> onVirtualUpdate)

根据参数给出某一时刻的值

DOVirtual.EasedValue(float from, float to, float lifetimePercentage, Ease easeType \ AnimationCurve animCurve)

延迟函数

DOVirtual.DelayedCall(float delay, TweenCallback callback, bool ignoreTimeScale = true) 
// Example 1: calling another method after 1 second
DOVirtual.DelayedCall(1, MyOtherMethodName);
// Example 2: using a lambda to throw a log after 1 second
DOVirtual.DelayedCall(1, ()=> Debug.Log("Hello world"));

其他

http://dotween.demigiant.com/documentation.php#globalSettings

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容