因为NGUI中已经有UITween了,可是UGUI中是没有这样的Tween的。因为在做游戏暂停的时候通常会使用Time.Scale =0 ,
可是暂停的时候UI如果需要继续有动画怎么办呢?
在DoTween中只需要设置 tweener.SetUpdate(true); 即可。
意思就是这个Tween是忽略TimeScale,如果不写的话 tweener.SetUpdate 是 false。
例子
using DG.Tweening; //不能少了这个命名空间。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | void Start () { //让TimeScale = 0 Time.timeScale = 0;
Image image = transform.Find("Image").GetComponent<Image>(); //调用DOmove方法来让图片移动 Tweener tweener = image.rectTransform.DOMove(Vector3.zero,1f); //设置这个Tween不受Time.scale影响 tweener.SetUpdate(true); //设置移动类型 tweener.SetEase(Ease.Linear); tweener.onComplete = delegate() { Debug.Log("移动完毕事件"); }; image.material.DOFade(0,1f).onComplete = delegate() { Debug.Log("褪色完毕事件"); }; } |
Tween的移动类型有很多种,比如匀速运动、加速运动、减速运动,等等。如果你拿捏不准你需要用什么移动类形式。
http://www.robertpenner.com/easing/easing_demo.html 你可以在这里预览一下那种移动类型更佳适合你。
代码中我们设置了图片的移动 和 褪色,因为移动的Tween设置了忽略Time.Scale,所以代码中Time.Scale =0时,图片的Tween响应了位移操作,然后褪色的Tween却没有。
部分文档
DoTween UnityUI
Dotween已为新的GUI系统做好准备,包括CanvasGroup,Graphic,Image,LayoutElement,Outline,RectTransform,ScrollRect,Slider,Text。
利用它你肯定可以定制出强大的动画系统。
Dotween TextMesh Pro/2D Tookit
Dotween同样为2D Tookit的Tk2dBaseSprite,tk2dSliceSprite等做好准备
Dotween同样为TextMeshPro+TextMeshProUGUI做好准备,包括DOFontSize,DOText,DOFaceFade等
dotwwen pro包含路径动画,路径可视化编辑,强大的属性面板
Dotween Pro :https://www.assetstore.unity3d.com/en/#!/content/32416
Dotween Free:https://www.assetstore.unity3d.com/en/#!/content/27676
一个tween控制value和animates
一个特殊的tween,并不是控制value,和其它的tween一起成为一个动画组
一个普通词,既可以表示 Tweener 也可以表示 序列
一个tween,包含序列
前缀在智能感知里是非常重要的,所以尽可能要记住这些:
DO 前缀是所有的tween的快捷方式(可以直接操作已知 object,比如transform或material),也是DOTween 类主要的前缀
transform.DOMoveX(100, 1);
transform.DORestart();
DOTween.Play();
Set 前缀,所有的tween设置
myTween.SetLoops(4, LoopType.Yoyo).SetSpeedBased();
On 前缀, 所有的tween回调
myTween.OnStart(myStartFunction).OnComplete(myCompleteFunction);
当你第一次创建 tween,DOTween将会使用默认值自动初始化。
如果你喜欢自己初始化(推荐),在创建任何tween之前(创建之后将不会有任何效果),调用这些方法一次。
想想看,你可以使用DOTween的 global settting 改变所有的初始化设置。
或者,你可以 通过链 SetCapacity 初始化方法,它可以设置 Tweeners最大值/FPS的初始容量(在高版本中可以调用 DOTween.SetTweensCapacity)
static DOTween.Init(bool recycleAllByDefault = false, bool useSafeMode = true, LogBehaviour logBehaviour = default)
比如:
DOTween.Init(true, true, LogBehaviour.Verbose).SetCapacity(200, 10);
Tweener好似为DOTween工作的一只蚂蚁,它采用 属性/字段对给定值进行动画处理。
截止目前 DOTween可以处理这些类型的值:
float,int,uint,Vector2/3/4,Quaternion,Rect,RectOffset,string
有三种方式创建 Tweener
DOTween包括一些已知的unity object,比如 Transform,Rigidbody和Material,你可以直接对这些object进行tween(这也会自动设置对象自己为target)比如:
transform.DOMove(new Vector3(2,3,4), 1);
rigidbody.DOMove(new Vector3(2,3,4), 1);
material.DOColor(Color.green, 1);
所有这些快速方式也有From,除了特殊说明,只需在方法名称后添加From
transform.DOMoveFrom(new Vector3(2,3,4), 1);
rigidbody.DOMoveFrom(new Vector3(2,3,4), 1);
material.DOColorFrom(Color.green, 1);
DOColor(Color to, float duration)
DOShakePosition(float duration, float strength, int vibrato, float randomness)
DOShakeRotation(float duration, float strength, int vibrato, float randomness)
详细的文档请参考官方:http://dotween.demigiant.com/documentation.php
DOMove(Vector3 to, float duration, bool snapping)
DOMoveX/DOMoveY/DOMoveZ(float to, float duration, bool snapping)
DOLocalMove(Vector3 to, float duration, bool snapping)
DOLocalMoveX/DOLocalMoveY/DOLocalMoveZ(float to, float duration, bool snapping)
DORotate(Vector3 to, float duration, bool useShortest360Route = true)
DOLocalRotate(Vector3 to, float duration, bool useShortest360Route = true)
DOLocalAxisRotate(Vector3 to, float duration)
DOScale(Vector3 to, float duration)
DOScaleX/DOScaleY/DOScaleZ(float to, float duration)
DOPunchPosition(Vector3 punch, float duration, int vibrato, float elasticity, bool snapping)
DOPunchRotation(Vector3 punch, float duration, int vibrato, float elasticity)
DOPunchScale(Vector3 punch, float duration, int vibrato, float elasticity)
DOShakePosition(Vector3 punch, float duration, float strength, int vibrato, float randomness, bool snapping)
DOShakeRotation(Vector3 punch, float duration, int vibrato, float elasticity)
DOShakeScale(Vector3 punch, float duration, int vibrato, float elasticity)
WaitForCompletion()
WaitForElapsedLoops(int elapsedLoops)
WaitForKill()
WaitForPosition(float position)
WaitForStart()
后面大多比较简单就不再一一翻译了,附上官方英文文档:http://dotween.demigiant.com/documentation.php