dotween easeoncomplete为什么只能执行一次

如果你使用了DoTween的时候会发现DoTween动画会默认播放状态,但是我们有很多UI动画并没有一开始就不断播放的功能因此我们需要修改动画播放的状态以及其他属性的时候该怎么办呢?
你可能注意到了DoTween所创建的动画都是默认Play状态以及播放完毕后会自动销毁动画,避免动画占用或者消耗内存。但是很多UI动画都是可以不断重复播放的,如果不断创建和销毁动画这样会消耗很多内存以及资源的,在游戏中这种情况一定要避免,为此DoTween提供了一个类方便我们进行动画状态以及属性等进行管理和修改等,DoTween的动画状态以及属性都可以通过Tweener类进行统一的管理和修改,所以Tweener也可以所示DoTween的核心功能之一,是值得我们去研究和学习的一个函数。
这里我简单的介绍一下Tweener类比较常用的一些函数,以及Tweener的简单的用法。
详细情况我就直接通过注释,代码如下:
using UnityE
using DG.T
public class MyButton : MonoBehaviour {
public RectTransform panelT
private bool isIn =
public LoopType loopT
//循环的模式
void Start()
//panelTranform.DOMove(Vector3.zero, 1);
//这个是修改UGUI的世界坐标
//创建一个简单位移动画,并将动画赋值给一个Tweener进行管理
Tweener paneltweener = panelTranform.DOLocalMove(Vector3.zero, 2f); //这个是修改UGUI的局部坐标,相对与父类的局部坐标
//多次调用DOTween动画会影响性能
//DOTween默认动画播放完毕时会自动销毁动画
//Tweener对象保存这个动画
paneltweener.SetAutoKill(false);
//禁止销毁动画
paneltweener.Pause();
//停止播放动画
//paneltweener.SetDelay(0.5f);
//设置动画延迟播放
//paneltweener.SetEase(Ease.INTERNAL_Zero);
//设置动画运动的模式
//paneltweener.SetLoops(-1);
//设置循环播放 (当参数为-1的时候循环播放;当参数&=0的时候则表示循环的次数;0的时候表示循环一次)
//paneltweener.SetLoops(-1,loopType)
//设置循环播放并且设置动画循环的模式
//paneltweener.PlayForward();
//paneltweener.PlayBackwards();
//paneltweener.OnComplete(OnComplete);
//动画播放完毕后执行,动画倒放时候不执行
//paneltweener.OnStart(OnStart);
//动画第一次播放时执行
//paneltweener.OnUpdate(OnUpdate);
//动画播放时不断执行
//paneltweener.OnPlay(OnPlay);
//动画开始播放时执行
//paneltweener.OnStepComplete(OnStepComplete);//动画播放且倒放都会执行一次,且执行顺序先于OnComplete
//paneltweener.OnKill(OnKill);
//动画删除的时候执行事件
//paneltweener.Kill(true);
//删除动画且组件会直接到达指定位置
private void OnKill()
Debug.Log(&This is OnKill&);
private void OnStepComplete()
Debug.Log(&This is OnStepComplete&);
private void OnPlay()
Debug.Log(&This is OnPlay&);
private void OnUpdate()
Debug.Log(&This is OnUpdate&);
private void OnStart()
Debug.Log(&动画第一次播放&);
public void OnClick()
//注释掉的方法是效果都是一样的
//panelTranform.DOPlay();
//动画只会播放一次
panelTranform.DOPlayForward();
//paneltweener.PlayForward();
//paneltweener.PlayBackwards();
panelTranform.DOPlayBackwards();
void OnComplete()
Debug.Log(&动画播放完毕!&);
本文已收录于以下专栏:
相关文章推荐
DOTween 使用方法
using UnityE
using System.C
using DG.T
using UnityEngin...
DOTween 使用方法using UnityE
using System.C
using DG.T
using UnityEngine.UI;
DOTween是一个快速,高效,完全统一的类型安全的对象属性动画引擎,免费开源,大量的高级特性.DoTween兼容Unity4.5以上的版本,支持的平台: Win, Mac, Unity WebPla...
官方文档链接:/documentation.php#globalSettings普通版下载地址:http://dotween.demigiant...
官方文档链接:/documentation.php#globalSettings
DOTween真的比iTween好很多:
1.编写方面更...
官方网站:/下载地址:/download.php快速开始:http://dotween....
Unity3D 为了游戏的效果或者游戏的美观性,常常需要一些UI的动画来美化游戏的界面。
那么UI常用到的动画制作方法有哪些呢?项目中常用到的ITween、DoTween这两个插件来制作补间动画,也有...
自己在学习过程中看到的一些不错的网站、博客的收集整理,以后发现其他的好网站也会贴到这里http://candycat1992.github.io/
《UNITY shader入门精要》作者冯乐乐的独...
在写代码的时候一定要想着代码的重用和性能,下面是动画在播放完以后不会消失。
using UnityE
using UnityEngine.UI;
using System.Collect...
各种类型 图标 http://easings.net/zh-cn
官网 ./easing/
unity3D 所用C#代码
easing....
他的最新文章
讲师:姜飞俊
讲师:汪木铃
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)弱弱问一下大神,DoTween的执行顺序问题【unity3d吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:76,567贴子:
弱弱问一下大神,DoTween的执行顺序问题收藏
void Start () {Tweener tweener = panelTransform.DOLocalMove(new Vector3(0, 0, 0), 0.3f);tweener.SetAutoKill(false);tweener.Pause();}Tweener tweener = panelTransform.DOLocalMove(new Vector3(0, 0, 0), 0.3f);这一步是异步?开始执行这步同时也开始执行tweener.SetAutoKill(false); ?????tweener.SetAutoKill(false);因为这一步执行很快,所以等同于tweener.SetAutoKill(false);和tweener.Pause();是同时执行的?
登录百度帐号推荐应用28658人阅读
Unity插件(8)
官方文档链接:/documentation.php#globalSettings
普通版下载地址:/download.php
pro版下载地址:/s/1dEzTQkL
(pro版提供DOTween Animation和DOTween Path这两个组件,支持可视化编辑)
移动类型:/easing/easing_demo.html
DOTween真的比iTween好很多:
1.编写方面更加人性化
2.效率高很多,其中有一点是因为iTween使用的是unity内置的SendMessage
DOTween一般的样子是这样滴:
using&DG.T
transform.DOMoveX(45, 1).SetDelay(2).SetEase(Ease.OutQuad).OnComplete(MyCallback);
好了,正式开始!
一些名词:
Tweener:补间动画
Sequence:相当于一个Tweener的链表,可以通过执行一个Sequence来执行一串Tweener
Tween:Tweener +&Sequence
Nested tween:Sequence中的一个Tweener称为一个Nested tween
主要的方法(就是最常用的):
1.以DO开头的方法:就是补间动画的方法。例如:transform.DOMoveX(100,1)
2.以Set开头的方法:设置补间动画的一些属性。例如:myTween.SetLoops(4, LoopType.Yoyo)
3.以On开头的方法:补间动画的回调方法。例如:myTween.OnStart(myStartFunction)
DOTween初始化与全局设置:
当你第一次创建一个Tween时,DOTween就会自动初始化(只初始化一次),使用缺省值。
当然,也可以使用DOTween.Init方法进行自定义,但要在第一次创建一个Tween前。所有创建的Tween都会受DOTween.Init方法的影响。
但之后,你也可以通过DOTween类的一些静态方法或者变量来修改全局设置:
static LogBehaviour DOTween.logBehaviour
static bool DOTween.showUnityEditorReport
static float DOTween.timeScale
static bool DOTween.useSafeMode
static DOTween.SetTweensCapacity(int maxTweeners, int maxSequences)
static bool DOTween.defaultAutoKill
static AutoPlay DOTween.defaultAutoPlay
static float DOTween.defaultEaseOvershootOrAmplitude
static float DOTween.defaultEasePeriod
static Ease DOTween.defaultEaseType
static LoopType DOTween.defaultLoopType
static bool DOTween.defaultRecyclable
static bool DOTween.defaultTimeScaleIndependent
static UpdateType DOTween.defaultUpdateType
static DOTween.Init(bool recycleAllByDefault = false, bool useSafeMode = true, LogBehaviour logBehaviour = LogBehaviour.ErrorsOnly)
recycleAllByDefault :如果为true,则当Tween完成时就会被回收,放到一个池中;否则就会被destroy
useSafeMode :效率会稍微降低,但更安全
logBehaviour :默认值为只打印错误信息
创建Tweener(有三种方法):
static DOTween.To(getter, setter, to, float duration)
以DOTween.To(() =& myVector, x =& myVector = x, new Vector3(3, 4, 8), 1);为例,就是对myVector进行插值,目标值为Vector3(3, 4, 8)
transform.DOMove(new Vector3(2,3,4), 1);
rigidbody.DOMove(new Vector3(2,3,4), 1);
material.DOColor(Color.green, 1);
对于unity内置的一些组件,都可以通过&.+DO开头的方法&的方式创建补间动画
以transform.DOMove(new Vector3(2,3,4), 1)为例,new Vector3(2,3,4)是最终值,意思是用一秒的时间运动到Vector3(2,3,4)
而transform.DOMove(new Vector3(2, 3, 4), 1).From(),就是从Vector3(2,3,4)运动到当前位置
static DOTween.Punch(getter, setter, Vector3 direction, float duration, int vibrato, float elasticity)
static DOTween.Shake(getter, setter, float duration, float/Vector3 strength, int vibrato, float randomness, bool ignoreZAxis)
static DOTween.ToAlpha(getter, setter, float to, float duration)
static DOTween.ToArray(getter, setter, float to, float duration)
static DOTween.ToAxis(getter, setter, float to, float duration, AxisConstraint axis)
static DOTween.To(setter, float startValue, float endValue, float duration)
创建Sequence:
Sequence可以包含Sequence,当执行一个Sequence时会顺序执行Tweener,可以使用Insert方法实现同时执行。
Sequence的方法:
static DOTween.Sequence()
Append(Tween tween)
AppendCallback(TweenCallback callback)
AppendInterval(float interval)
Insert(float atPosition, Tween tween)
InsertCallback(float atPosition, TweenCallback callback)
Join(Tween tween)
Prepend(Tween tween)
PrependCallback(TweenCallback callback)
PrependInterval(float interval)
// Grab a free Sequence to use
Sequence mySequence = DOTween.Sequence();
// Add a movement tween at the beginning
mySequence.Append(transform.DOMoveX(1, 1));
// Add a rotation tween as soon as the previous one is finished
mySequence.Append(transform.DORotate(new Vector3(0, 180, 0), 1));
// Delay the whole Sequence by 1 second
mySequence.PrependInterval(1);
// Insert a scale tween for the whole duration of the Sequence
mySequence.Insert(0, transform.DOScale(new Vector3(3, 3, 3), mySequence.Duration()));等同于:
Sequence mySequence = DOTween.Sequence();
mySequence.Append(transform.DOMoveX(45, 1))
.Append(transform.DORotate(new Vector3(0, 180, 0), 1))
.PrependInterval(1)
.Insert(0, transform.DOScale(new Vector3(3, 3, 3), mySequence.Duration()));
上面我们提到了全局设置,这里我们再说一说针对Tweener和Sequence的局部设置
float timeScale
SetAs(Tween tween \ TweenParams tweenParams)
SetAutoKill(bool autoKillOnCompletion = true)
SetEase(Ease easeType \ AnimationCurve animCurve \ EaseFunction customEase)
SetId(object id)
SetLoops(int loops, LoopType loopType = LoopType.Restart)
SetRecyclable(bool recyclable)
SetUpdate(UpdateType updateType, bool isIndependentUpdate = false)
注意的一点是SetUpdate方法可以让目标忽略timeScale
回调方法:
OnComplete(TweenCallback callback)
OnKill(TweenCallback callback)
OnPlay(TweenCallback callback)
OnPause(TweenCallback callback)
OnRewind(TweenCallback callback)
OnStart(TweenCallback callback)
OnStepComplete(TweenCallback callback)
OnUpdate(TweenCallback callback)
OnWaypointChange(TweenCallback&int& callback)
还有一些针对部分Tweener的特殊的局部设置:
注意SetOptions方法必须紧跟Tweener,就好像这样:
DOTween.To(()=& myVector, x=& myVector = x, new Vector3(2,2,2), 1).SetOptions(AxisConstraint.Y, true);
TweenParams:
就是可以将一些参数应用到多个Tweener中
// Store settings for an infinite looping tween with elastic ease
TweenParams tParms = new TweenParams().SetLoops(-1).SetEase(Ease.OutElastic);
// Apply them to a couple of tweens
transformA.DOMoveX(15, 1).SetAs(tParms);
transformB.DOMoveY(10, 1).SetAs(tParms);
操作Tweener(有三种方法):
1.DOTween静态方法
// Pauses all tweens
DOTween.PauseAll();
// Pauses all tweens that have &badoom& as an id
DOTween.Pause(&badoom&);
// Pauses all tweens that have someTransform as a target
DOTween.Pause(someTransform);2.Tweener方法
myTween.Pause();3.部件.+以DO开头的方法
transform.DOPause();
以上的是Pause方法,以下的是其余的操作方法。上面三种方式中,DOTween和Tweener都有以下的操作方法,而部件的话,要在前面加上&DO&。
CompleteAll/Complete()
FlipAll/Flip()
GotoAll/Goto(float to, bool andPlay = false)
KillAll/Kill(bool complete = true)
PauseAll/Pause()
PlayAll/Play()
PlayBackwardsAll/PlayBackwards()
PlayForwardAll/PlayForward()
RestartAll/Restart(bool includeDelay = true)
RewindAll/Rewind(bool includeDelay = true)
TogglePauseAll/TogglePause()
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using UnityE
using System.C
using DG.T
public class Test : MonoBehaviour {
public RectT
private bool isIn =
// Use this for initialization
void Start ()
//修改的是世界坐标
//Tweener t = rt.DOMove(Vector3.zero, 0.3f);
//修改的是局部坐标
Tweener t = rt.DOLocalMove(Vector3.zero, 0.3f);
//默认动画播放完成会自动销毁
t.SetAutoKill(false);
t.Pause();
public void OnClick ()
if (!isIn)
//将开始该物体的所有Tweener
rt.DOPlayForward();
rt.DOPlayBackwards();
isIn = !isIn;
using UnityE
using System.C
using DG.T
using UnityEngine.UI;
public class Test2 : MonoBehaviour {
// Use this for initialization
void Start ()
//Vector3.zero是绝对位置,表示从Vector3.zero移动到当前位置
//t.DOMove(Vector3.zero, 2).From();
//默认为false
//Vector3.forward是相对位置,表示从Vector3.forward加当前位置移动到当前位置
t.DOMove(Vector3.forward, 2).From(true);
//逐字显示
text.DOText(&宏哥宏哥宏哥宏哥宏哥宏哥宏哥宏哥宏哥宏哥宏哥宏哥宏哥宏哥宏哥宏哥&, 3);
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:502689次
积分:6340
积分:6340
排名:第4036名
原创:134篇
转载:88篇
评论:192条
(2)(8)(16)(1)(6)(10)(20)(1)(1)(3)(19)(22)(5)(1)(5)(13)(32)(32)(26)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'请问各位有比较详细的dotween的学习资料或者视频教程吗?-GAD腾讯游戏开发者平台代码环境:
  unity:version5.3.4.f1
& & & &DOTween:v1.0.312
  IDE:Microsoft visual studio Community 2015
DOTween中几个需要注意的变量和函数功能说明:
1 tweens对象完成后会自动销毁,如此我们基本不用关心DOTween的内存销毁问题。
// Summary:
Default autoKillOnComplete behaviour for new tweens.
Default: TRUE
public static bool defaultAutoK
2&& 构建新的tweens后,会自动play。保持该值,我们则无需要手动调用play
// Summary:
Default autoPlay behaviour for new tweens.
Default: AutoPlay.All
public static AutoPlay defaultAutoP
3 默认的运动方式,主要表现是开始执行时,快速,在后期会逐步减速。该算法在执行时间长度比较短时看着比较合理舒适,但是如果出现类似距离较长,时间也相对较长时,就容易发现在后期有点很不好接受的缓慢移动。此时就需要考虑更改运动方式。
// Summary:
Default ease applied to all new Tweeners (not to Sequences which always have
Ease.Linear as default).
Default: Ease.InOutQuad
public static Ease defaultEaseT
// Summary:
Sets the ease of the tween.
If applied to Sequences eases the whole sequence animation
public static T SetEase&T&(this T t, Ease ease) where T : T
4 DOTween中有两套不同的调用方式=》
shortcuts way,但是需要针对不同对象,需要调用不一样对象:
// Summary:
Tweens a Transform's localPosition to the given value. Also stores the transform
as the tween's target so it can be used for filtered operations
// Parameters:
The end value to reach
The duration of the tween
If TRUE the tween will smoothly snap all values to integers
public static Tweener DOLocalMove(this Transform target, Vector3 endValue, float duration, bool snapping = false);
// Summary:
Tweens a Transform's localRotation to the given value. Also stores the transform
as the tween's target so it can be used for filtered operations
// Parameters:
The end value to reach
The duration of the tween
Rotation mode
public static Tweener DOLocalRotate(this Transform target, Vector3 endValue, float duration, RotateMode mode = RotateMode.Fast);
// Summary:
Tweens a Transform's localScale to the given value. Also stores the transform
as the tween's target so it can be used for filtered operations
// Parameters:
The end value to reach
The duration of the tween
public static Tweener DOScale(this Transform target, Vector3 endValue, float duration);
generic way,大部分的执行都可以用同类型的接口。
如下函数,只要是float类型数值,都可以符合调用要求。我个人使用最多的就是应用在alpha上,处理渐隐渐现效果很好。
// Summary:
Tweens a virtual property from the given start to the given end value and implements
a setter that allows to use that value with an external method or a lambda
To(MyMethod, 0, 12, 0.5f);
Where MyMethod is a function that accepts a float parameter (which will be the
result of the virtual tween)
// Parameters:
The action to perform with the tweened value
startValue:
The value to start from
The end value to reach
The duration of the virtual tween
public static Tweener To(DOSetter&float& setter, float startValue, float endValue, float duration);
5 关于sequence
Sequences are like Tweeners, but instead of animating a property or value they animate other Tweeners or Sequences as a group.
比较简单的Sequence,可以直接用如下函数增加Append /&Join:
// Summary:
Adds the given tween to the end of the Sequence. Has no effect if the Sequence
has already started
// Parameters:
The tween to append
public static Sequence Append(this Sequence s, Tween t);
// Summary:
Inserts the given tween at the same time position of the last tween added to
the Sequence. Has no effect if the Sequence has already started
public static Sequence Join(this Sequence s, Tween t);
如果是比较复杂的,建议直接使用insert,如此可以随意的控制加入tween的时间节点
// Summary:
Inserts the given tween at the given time position in the Sequence, automatically
adding an interval if needed. Has no effect if the Sequence has already started
// Parameters:
atPosition:
The time position where the tween will be placed
The tween to insert
public static Sequence Insert(this Sequence s, float atPosition, Tween t);
// Summary:
Inserts the given callback at the given time position in the Sequence, automatically
adding an interval if needed. Has no effect if the Sequence has already started
// Parameters:
atPosition:
The time position where the callback will be placed
The callback to insert
public static Sequence InsertCallback(this Sequence s, float atPosition, TweenCallback callback);
6 关于Kill函数:特意提出该接口,是因为针对于Sequence,调用DOTween.Kill("Sequence",&true),并不能在kill之前complete,不确定是其本身的bug还是我对接口的理解不对。
// Summary:
Kills all tweens with the given ID or target and returns the number of actual
tweens killed
// Parameters:
If TRUE completes the tweens before killing them
public static int Kill(object targetOrId, bool complete = false);
以下是一些测试例子和执行后的效果图。
[ContextMenu("DoTweenAlpha")]
void DoTweenAlpha()
Debug.Log("DoTweenAlpha");
UIRect uiRect = m_uiRectA
if (uiRect != null)
DOTween.To(x =& uiRect.alpha = x, 1.0f, 0.0f, 5.0f).SetId("Tween");
[ContextMenu("DoTweenKillCompleteAlpha")]
void DoTweenKillCompleteAlpha()
Debug.Log("DoTweenKillCompleteAlpha");
UIRect uiRect = m_uiRectA
if (uiRect != null)
DOTween.Kill("Tween", true);
[ContextMenu("DoTweenKillAlpha")]
void DoTweenKillAlpha()
Debug.Log("DoTweenKillAlpha");
UIRect uiRect = m_uiRectA
if (uiRect != null)
DOTween.Kill("Tween", false);
[ContextMenu("DoSequenceAlpha")]
void DoSequenceAlpha()
Debug.Log("DoSequenceAlpha");
UIRect uiRect = m_uiRectA
if (uiRect != null)
Sequence sequence = DOTween.Sequence();
sequence.Append(DOTween.To(x =& uiRect.alpha = x, 1.0f, 0.0f, 5.0f));
sequence.SetId("Sequence");
[ContextMenu("DoSequenceKillCompleteAlpha")]
void DoSequenceKillCompleteAlpha()
Debug.Log("DoSequenceKillCompleteAlpha");
UIRect uiRect = m_uiRectA
if (uiRect != null)
DOTween.Kill("Sequence", true);
[ContextMenu("DoSequenceKillAlpha")]
void DoSequenceKillAlpha()
Debug.Log("DoSequenceKillAlpha");
UIRect uiRect = m_uiRectA
if (uiRect != null)
DOTween.Kill("Sequence", false);
执行顺序:
DoTweenAlpha-&DoTweenKillAlpha(正确kill,并没有complete);DoTweenAlpha-&DoTweenKillCompleteAlpha(正确kill,并成功complete)
DoSequenceAlpha-&DoSequenceKillAlpha(正确kill,并没有complete);DoSequenceAlpha-&DoSequenceKillCompleteAlpha(正确kill,并没有成功complete)
附上一张DoSequenceAlpha-&DoSequenceKillCompleteAlpha执行后的效果图:
阅读(...) 评论()}

我要回帖

更多关于 dotween 延迟执行 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信