using System.Collections;using System.Collections.Generic;using UnityEngine;using DG.Tweening;/*
* Unity Dotween插件的学习脚本
* 2020/3/27
* 运动曲线
*/publicclassDotweenLearn04:MonoBehaviour{publicAnimationCurve AniCur;// Start is called before the first frame updatevoidStart(){//Flase曲线//transform.DOMove(Vector3.one * 2, 2).SetEase(Ease.Flash, 10, -1);//AnimationCurve设置运动曲线
transform.DOMove(Vector3.one *2,2).SetEase(AniCur);}}
5、控制方法
using System.Collections;using System.Collections.Generic;using UnityEngine;using DG.Tweening;/*
* Unity Dotween插件的学习脚本
* 2020/3/27
*/publicclassDotweenLearn05:MonoBehaviour{// Start is called before the first frame updatevoidStart(){//回调函数
transform.DOMove(Vector3.one *2,2).OnPlay(()=>{print("动画播放");});
transform.DOMove(Vector3.one *2,2).OnComplete(()=>{print("动画完成");});
transform.DOMove(Vector3.one *2,2).OnKill(()=>{print("动画被杀死");});
transform.DOMove(Vector3.one *2,2).OnPause(()=>{print("动画被暂停");});//......等等//控制方法
transform.DOPause();//动画暂停
transform.DOPlay();//动画播放
transform.DORestart();//动画重播
transform.DORewind();//动画倒播
transform.DOKill();//动画被杀死
transform.DOFlip();//反转动画补间
transform.DOGoto(1,true);//动画跳转到1秒
transform.DOFlip();//反转补间
transform.DOFlip();//反转补间
transform.DOFlip();//反转补间
transform.DOPlayBackwards();//将动画反向播放
transform.DOTogglePause();//播放状态下会暂停,暂停状态下会播放}}
6、获取数据的方法
using System.Collections;using System.Collections.Generic;using UnityEngine;using DG.Tweening;/*
* Unity Dotween插件的学习脚本
* 2020/3/27
* 获取数据的方法
*/publicclassDotweenLearn06:MonoBehaviour{privateTweener tweener;// Start is called before the first frame updatevoidStart(){//1、类方法var List = DOTween.PlayingTweens();//获取播放的动画
DOTween.TweensById("ID");//获取id为ID的动画//其他的类似//2、获取动画的执行时间
tweener = transform.DOMove(Vector3.up,2);print(tweener.fullPosition);
tweener.fullPosition =0;//修改动画执行时间为0//3、获取时间数据print(tweener.Delay());//获取延迟时间print(tweener.Duration());//获取持续时间
tweener.SetLoops(3);//循环3次//已经播放的时间print(tweener.Elapsed(true));//传入true,包含循环时间;传入false,不包含循环时间print(tweener.ElapsedDirectionalPercentage());//获取进度的百分比//4、判断动画状态的方法print(tweener.IsPlaying());//动画是否播放print(tweener.IsBackwards());//是否反向//其他的类似//5、携程-指定循环次数等方法StartCoroutine(Wait());}privateIEnumeratorWait(){yieldreturn tweener.WaitForCompletion();//等待动画播放完成,执行下面逻辑print("动画已播放完毕。");yieldreturn tweener.WaitForElapsedLoops(2);//指定循环次数2次,执行下面逻辑yieldreturn tweener.WaitForPosition(1.5f);//动画播放到1.5秒的位置,执行下面逻辑//等等}}
7、路径动画
using System.Collections;using System.Collections.Generic;using System.Linq;using UnityEngine;using DG.Tweening;/*
* Unity Dotween插件的学习脚本
* 2020/3/27
* 路径动画
*/publicclassDotweenLearn07:MonoBehaviour{public Transform[] pointPosionList;private Vector3[] posions;// Start is called before the first frame updatevoidStart(){
posions =newVector3[pointPosionList.Length];for(int i =0; i < pointPosionList.Length; i++){
posions[i]= pointPosionList[i].position;print(posions[i]);}//SetOptions设置为true为封闭运动,后面为Y轴锁定//SetLookAt后面数值决定运动朝向,0和1为前和后,0.5差不多与路径垂直
transform.DOPath(posions,5, PathType.CatmullRom, PathMode.Full3D,10, Color.green).SetOptions(true, AxisConstraint.Y).SetLookAt(0.5f);}}