1、DoTween.To()
效果展示
代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class Test01 : MonoBehaviour
{
public Vector3 myValue = new Vector3(1000, 0, 0);
public RectTransform taskPanelTransform;
void Start()
{
DOTween.To(() => myValue, x => myValue = x, new Vector3(0, 0, 0), 3);
}
void Update()
{
taskPanelTransform.localPosition = myValue;
}
}
2、动画前放和倒放
效果展示
代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class Test02 : MonoBehaviour
{
public RectTransform panelTransform;
private bool isIn = false;
private void Start()
{
Tweener tweener = panelTransform.DOLocalMove(new Vector3(0, 0, 0), 1);
tweener.SetAutoKill(false);
tweener.Pause();
}
public void OnButtonClick()
{
if(isIn==false)
{
panelTransform.DOPlayForward();
isIn = true;
}
else
{
panelTransform.DOPlayBackwards();
isIn = false;
}
}
}
3、From Tweens用法
效果展示
代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class Test03 : MonoBehaviour
{
void Start()
{
transform.DOMoveX(5, 3).From(true);
}
}
4、动画属性设置
效果展示
代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class Test04 : MonoBehaviour
{
void Start()
{
Tweener tweener = transform.DOLocalMoveX(0, 3);
tweener.SetEase(Ease.OutBack);
tweener.SetLoops(2);
tweener.OnComplete(OnTweenComplete);
}
private void OnTweenComplete()
{
Debug.Log("动画播放完毕!");
}
}
5、文字动画
效果展示
代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using UnityEngine.UI;
public class Test05 : MonoBehaviour
{
private Text text;
void Start()
{
text = this.GetComponent<Text>();
text.DOText("允许到达目的地的路途有一些坎坷 允许自己偶尔不开心不聪明 也允许偶尔做得不够好 但不会轻易放弃 时间在走 很多事都会过去都会慢慢变好", 10);
text.DOColor(Color.red, 10);
text.DOFade(1, 3);
}
}
6、屏幕震动
效果展示
代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class Test06 : MonoBehaviour
{
void Start()
{
transform.DOShakePosition(1, new Vector3(3, 3, 0));
}
}
7、官方文档
http://dotween.demigiant.com/documentation.php