UGUI_使用DoTween

 

因为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等

Dotween 路径动画

dotwwen pro包含路径动画,路径可视化编辑,强大的属性面板

Dotween Pro :https://www.assetstore.unity3d.com/en/#!/content/32416

Dotween Free:https://www.assetstore.unity3d.com/en/#!/content/27676

一、术语

Tweener

一个tween控制value和animates

Sequence

一个特殊的tween,并不是控制value,和其它的tween一起成为一个动画组

Tween

一个普通词,既可以表示  Tweener 也可以表示 序列

Nested tween

一个tween,包含序列

DoTween前缀

前缀在智能感知里是非常重要的,所以尽可能要记住这些:

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);

二、DOTween.Init

当你第一次创建 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);

三、Creating a Tweener

Tweener好似为DOTween工作的一只蚂蚁,它采用 属性/字段对给定值进行动画处理。

截止目前 DOTween可以处理这些类型的值:

float,int,uint,Vector2/3/4,Quaternion,Rect,RectOffset,string

有三种方式创建 Tweener

A.便捷方式

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);

Camera

DOColor(Color to, float duration)

DOShakePosition(float duration, float strength, int vibrato, float randomness)

DOShakeRotation(float duration, float strength, int vibrato, float randomness)

Light

Material

Rigidbody

Move

SpriteRenderer

详细的文档请参考官方:http://dotween.demigiant.com/documentation.php

Transform

Move

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)

Rotate

DORotate(Vector3 to, float duration, bool useShortest360Route = true)

DOLocalRotate(Vector3 to, float duration, bool useShortest360Route = true)

DOLocalAxisRotate(Vector3 to, float duration)

Scale

DOScale(Vector3 to, float duration)

DOScaleX/DOScaleY/DOScaleZ(float to, float duration)

Punch – no FROM

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)

Shake – no FROM

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)

WaitFor coroutines

WaitForCompletion()

WaitForElapsedLoops(int elapsedLoops)

WaitForKill()

WaitForPosition(float position)

WaitForStart()

官方英文API

后面大多比较简单就不再一一翻译了,附上官方英文文档:http://dotween.demigiant.com/documentation.php

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LetsonH

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值