导出:
//DoTween typeof(DG.Tweening.AutoPlay), typeof(DG.Tweening.AxisConstraint), typeof(DG.Tweening.Ease), typeof(DG.Tweening.LogBehaviour), typeof(DG.Tweening.LoopType), typeof(DG.Tweening.PathMode), typeof(DG.Tweening.PathType), typeof(DG.Tweening.RotateMode), typeof(DG.Tweening.ScrambleMode), typeof(DG.Tweening.TweenType), typeof(DG.Tweening.UpdateType), typeof(DG.Tweening.DOTween), typeof(DG.Tweening.DOVirtual), typeof(DG.Tweening.EaseFactory), typeof(DG.Tweening.Tweener), typeof(DG.Tweening.Tween), typeof(DG.Tweening.Sequence), typeof(DG.Tweening.TweenParams), typeof(DG.Tweening.Core.ABSSequentiable), typeof(DG.Tweening.Core.TweenerCore<Vector3, Vector3, DG.Tweening.Plugins.Options.VectorOptions>), typeof(DG.Tweening.TweenCallback), typeof(DG.Tweening.TweenExtensions), typeof(DG.Tweening.TweenSettingsExtensions), typeof(DG.Tweening.ShortcutExtensions), typeof(DG.Tweening.DOTweenModuleUI), //dotween pro 的功能 typeof(DG.Tweening.DOTweenPath), typeof(DG.Tweening.DOTweenVisualManager),
使用:
--基本使用 rectTransform:DOAnchorPos(Vector2.New(end_pos_x, end_pos_y), 0.3) transform:DOLocalMove(Vector3.New(x,y,0),0.15) transform:DOLocalRotate(Vector3.New(0,0,0), time) unity_uiimage:DOFade(0.8, 1) --移除 transform:DOKill() --设置缓动 rectTransform:DOAnchorPos(Vector2(0,0), 1):SetEase(CS.DG.Tweening.Ease.OutBack) --设置完成回调 rectTransform:DOAnchorPos(Vector2(0,0), 1):OnComplete(function () end) --队列queue local queue = CS.DG.Tweening.DOTween.Sequence() queue:Append(rectTransform:DOAnchorPos(Vector2(0,0), 1)) queue:AppendCallback(function() end) queue:AppendInterval(2) queue:Kill()
有时候,我们需要暂停游戏,都会将时间缩放改为0,DoTween可以设置为不受它的影响,从而继续播放
using UnityEngine;
using DG.Tweening;
public class TweenScal : MonoBehaviour {
void Start () {
Time.timeScale = 0;
RectTransform rect = this.GetComponent<RectTransform>();
Tweener t = rect.DOMove(new Vector3(10, 10, 10), 10f);
//设置这个动画不受时间缩放的影响,继续播放
t.SetUpdate(true);
}
}
只要在需要添加路径的物体上添加组件DOTweenPath,在场景上按Shift+Ctrl添加点,Shift+Alt删除点,编辑好路径
在去设置好属性,可以是线性的,平滑曲线的,循环播放等,还有朝向

添加组件DOTweenAnimation,元素看意思,能看懂的

text.DOColor (Color.red, 2);//两秒渐变到红色 text.DOFade (0, 2);//两秒变成透明
震屏效果其实是对相机的随机震动
transform.DOShakePosition (10f,new Vector3(1,2,3));
transform就是相机
DOShakePosition的第一个参数是时间,第二个是个方向的强度
using UnityEngine.UI;
using DG.Tweening;
public Text text;
// Use this for initialization
void Start () {
text.DOText ("我是个大傻逼", 10);
}如果本来text没有文字,DOText()这段文字会在10秒慢慢显示出来
如果本来就有文字,会从头慢慢替换到结束。
void Start () {
Tweener t = transform.DOLocalMoveX (0, 2);
t.SetEase (Ease.OutBounce);//设置动画曲线
t.OnComplete(Complete);//设置完成回调
}
void Complete(){
Debug.Log ("动画完成了");
}Ease是一个枚举类型,里面有很多内置好的动画曲线
每一个动画Tweener都有一个From()方法,表示的是倒过来放,从目标点到起点
transform.DOMoveX (3, 2).From (true);
参数true表示的是为参考坐标,就是说如果原来的起点x为2,那么目标值为5
默认是false,也就是目标值就是3
public RectTransform rect;
private bool isOn = false;
// Use this for initialization
void Start () {
Tweener t = rect.DOLocalMove (new Vector3 (0, 0, 0), 1);
t.SetAutoKill (false);//Do创建的动画会自动销毁的
t.Pause ();//创建完就会播放,这里不需要所以暂停
}
public void OnButtonClick(){
if (!isOn) {
rect.DOPlayForward ();//正播放
isOn = true;
} else {
rect.DOPlayBackwards ();//逆播放
isOn = false;
}
}不单单是RectTransfrom,DoTween对很多的内置的类都做了Do方法的扩展
Tweener是Do类型的方法创建的动画对象