Foreword:
Translated according to the fate, the content is described according to my own understanding of the effect, if there are any mistakes or omissions, please correct me.
DOTween
before the start
What is Tween (tween)
Tweening, generally refers to tweening animation, such as the Animation window of unity, when inserting two pictures or transforming an object, unity will create a corresponding animation according to the frame between the two states, which is tweening.
1. Download and install DOTween in the resource store: Import DOTween
into the project to be used in PackageManager.
After the installation is complete, click Setup DOTween to automatically import/re-import some internal files according to the version of unity, and activate or deactivate some modules.
If you accidentally close it or close it and want to open it again , you can open the panel in the Tools/Demigiant/DOTween Utility Panel of the unity toolbar.
2. When using DOTween, you need to introduce the corresponding namespace:
using DG.Tweening;
3. Initialize DOTween and set some global settings.
If you do not call this method to initialize each time you create a DOTween script, DOTween will also automatically perform initialization settings according to the default settings. If you perform initialization, you must call this method before each use, otherwise there will be no effect. The default settings can be changed in Preferences in the initial panel.
DOTween.Init();
parameter | Function |
---|---|
recycleAllByDefault | bool type, if true, all animation tweens will be recycled and put into an object pool after the call, instead of being destroyed directly. |
useSafeMode | bool type, if true, the tween will be slower, but it will be safer, allowing the tween to take care of some things, when an object is destroyed, the tween is still executed. |
logBehaviour | Depending on the selected mode, DOTween will only log errors (ErrorsOnly) or errors and warnings (Default), or everything plus other information (Verbose) |
nomenclature
- Tweener: Tween, manipulate and animate values.
- Sequence: A sequence that controls how multiple tweens are processed as a group.
- Tween: Generic word, generic word means tween and sequence.
- Nested tween: Nested tween, the tween contained in the sequence.
prefix
- DO: All prefixes that quickly implement some tweening effects (such as transform Transform).
- Set: Set the current effect.
- On: A series of column callbacks.
basic method
DO prefix
Transform
Move
transform.DOMove(new Vector3(10, 0, 0), 10, false);
作用:移动到某一指定点。(世界坐标)
参数:
Vector3 to 要移动到的位置
float duration 所需要花费的时间
bool snapping 为true时平滑地将所有值变为整数。(每次移动整数值)默认为false
transform.DOMoveX()/DOMoveY()/DOMoveZ(10, 10f,false);
作用:沿着某一轴移动到指定位置。
参数:
float to 要移动到的轴的坐标
float duration 所需要花费的时间
bool snapping 为true时平滑地将所有值变为整数。(每次移动整数值)默认为false
transform.DOLocalMove(new Vector3(10,0.5f,0),10f,false);
作用:移动自身坐标到指定位置。
参数:
Vector3 to 要移动到的位置
float duration 所需要花费的时间
bool snapping 为true时平滑地将所有值变为整数。(每次移动整数值)默认为false
transform.DOLocalMoveX()/DOLocalMoveY()/DOLocalMoveZ();
作用:移动自身坐标到指定轴的指定位置。
参数:
float to 要移动到的轴的坐标
float duration 所需要花费的时间
bool snapping 为true时平滑地将所有值变为整数。(每次移动整数值)默认为false
transform.DOJump(new Vector3(10, 0, 0),10,3,10,false);
作用:实现跳跃到指定位置。
参数:
Vector3 endValue 最终要跳跃到的位置
float jumpPower 跳跃的强度,决定跳跃的高度(当前位置Y加上该值)
int numJumps 跳跃的次数
float duration 总持续时间
bool snapping 为true时平滑地将所有值变为整数。(每次移动整数值)默认为false
transform.DOLocalJump(new Vector3(10, 0, 0),10,3,10,false);
作用:实现跳跃到指定位置(自身坐标)。
参数:
Vector3 endValue 最终要跳跃到的位置
float jumpPower 跳跃的强度,决定跳跃的高度(当前位置Y加上该值)
int numJumps 跳跃的次数
float duration 总持续时间
bool snapping 为true时平滑地将所有值变为整数。(每次移动整数值)默认为false
Rotate
transform.DORotate(Rote, 0.1f, RotateMode.Fast);
作用:旋转到指定的值(根据欧拉角)。
参数:
Vector3 to 旋转目标值
float duration 总旋转用时
RotateMode
Fast 旋转采用最短路线,切旋转不会超过360°
FastBeyond360 旋转将超过360°
WorldAxisAdd 类似于使用transform.Rotate(new Vector3(20, 0, 0),Space.World),最终值始终被视为相对值
LocalAxisAdd 类似于使用transform.Rotate(new Vector3(20, 0, 0),Space.Self),最终值始终被视为相对值
transform.DORotateQuaternion();
作用:旋转到指定的值(四元数)。
参数:
Quaternion to 要旋转到的四元数值
float duration 旋转用时
transform.DOLocalRotate();
作用:自身坐标旋转。
transform.DOLocalRotateQuaternion();
作用:自身坐标旋转。
transform.DOLookAt();
作用:旋转目标,使其朝向给定位置。
参数:
Vector3 towards 旋转目标值
float duration 旋转总用时
AxisConstraint axisConstraint 旋转最终轴约束,只旋转此轴
Vector3 up 定义向上方向的矢量
transform.DODynamicLookAt();
作用:旋转目标,使其朝向给定位置,每帧更新 lookAt 位置(与此相反,当补间开始时,只计算一次 lookAt 旋转)
参数:
Vector3 towards 旋转目标值
float duration 旋转总用时
AxisConstraint axisConstraint 旋转最终轴约束,只旋转此轴
Vector3 up 定义向上方向的矢量
Scale
DOScale();
作用:将物体放大/缩小到指定大小
参数:
float/Vector3 to 浮点数为倍数,向量为指定大小
float duration 放大/缩小总消耗时间
DOScaleX/DOScaleY/DOScaleZ();
作用:对某一轴方向进行放大缩小
float to 放大到的倍数
float duration 放大/缩小总消耗时间
Punch
DOPunchPosition();
作用:受到冲击后的回弹效果
参数:
Vector3 punch 要被击打到的最远位置(相对值,相对于局部坐标)
float duration 总持续时间
int vibrato 物体振动频率
float elasticity 值一般在0到1之间,0表示起点到冲击方向的震荡,1表示为一个完整的震荡,可能会超过起点,个人感觉后者效果更好。
bool snapping 是否进行平滑插值
DOPunchRotation()
作用:受到冲击后旋转效果
参数:
Vector3 punch 要被击打到的角度(相对值,相对于局部坐标)
float duration 总持续时间
int vibrato 物体旋转频率
float elasticity 值一般在0到1之间,0表示最初角度到最大角度的旋转,1表示为一个完整的旋转,可能会超过最远角度。
DOPunchScale()
作用:实现一个弹性效果,反复弹,最终复原。
参数
Vector3 punch 弹到的大小
float duration 总持续时间
int vibrato 物体放缩频率
float elasticity 值一般在0到1之间,0表示最初角度到目标大小的放缩,1会产生负值,出现警告。