精华内容
下载资源
问答
  • DOTween

    2017-12-02 14:28:05
  • DoTween

    2019-09-29 02:59:44
    DoTween unity 插件 动画 DoTween 官网:http://dotween.demigiant.com/ 一、Start 注意:下载Dotween导入unity后别忘打开其面板点击Setup DOTween设置DotweenDotween可以依据你当前的unity版本...

    DoTween

    官网:http://dotween.demigiant.com/

    一、Start

    注意:下载Dotween导入unity后别忘打开其面板点击Setup DOTween设置Dotween,Dotween可以依据你当前的unity版本自己做一些调整。
    enter description here

    1.step

    这里使用lamda表达式,通过dotween的to方法将其移动到 Vector3(348, 196, 0)的值返回到Vector3 Movector3这个变量上,可以在后续通过Movector3来实现动画。其实可以通过该方法来实现很多插值的动画效果。

    DOTween.To(() => Movector3, x => Movector3 = x, new Vector3(348, 196, 0), 2);

    2.step

    很多组件DoTween都为其添加了很多扩展方法,可以直接调用。可以方便的为transform,text,img等添加相应的动画。

    Tweener tweener = ImgTransform.DOLocalMove(new Vector3(100, 100, 0), 0.3f);
    tweener.SetAutoKill(false);//是否在动画结束后销毁动画对象,这里选择否
    tweener.Pause();//暂停动画,使其不要在开始时就运行。

        public void OnBtnClick()
        {
            if (!isIn)
            {
                //ImgTransform.DOPlay();该方法只能调用一次动画
                ImgTransform.DOPlayForward();//正序播放动画
            }
            else
            {
                ImgTransform.DOPlayBackwards();//倒序播放动画
            }
            isIn = !isIn;
        }
    

    3.step

    From可以将To动画转换为From动画。OnComplete 方法可以在动画完成时调用其他方法。该网址可以查看动画类型中的效果:
    http://robertpenner.com/easing/easing_demo.html
    Tweener tweener=CubeTransform.DOMoveX(8, 2).From(false);//当为true时,是从初始的位置加上增量后的位置移动到初始位置;当为false时则是从该位置移动到初始位置。即true时参数为增量,false是参数为坐标位置。
    tweener.SetEase(Ease.InCirc);
    tweener.SetLoops(5,LoopType.Yoyo);//Restart重新播放动画;Incremental增量式的,以结束点为起点继续开始动画;Yoyo悠悠球式,往复运动,往复动画也计入次数中。
    http://robertpenner.com/easing/easing_demo.html

    	        tweener.OnComplete(()=> Debug.Log("finished"));
    

    4.step

    为ugui Text组件添加动画效果,分别为打字效果和改变文字颜色。

    Text.DOText("秋水共长天一色,落霞与孤鹜齐飞。", 2);//文字动画类似于打字机特效,如果文本框已有文字,则会被逐个覆盖掉。
    Text.DOColor(Color.blue, 4);//调整动画颜色

    5.step

    可以为对象直接添加DoTweenAnimation脚本来控制对象的运动,上面有常用的属性设置。

    6.step

    移动路径动画,DoTweenPath组件为用户提供了方面的路径动画编辑面板,可以通过快捷键的方式在scene模式下快速的编辑路径点,并且可以PathType中将路径设置平滑,也可以在Orientation控制对象在移动过程中的朝向。

    Adcance

    1.step

    DO:用来执行一些动画效果如:

    // Regular TO tween
    ransform.DOMoveX(2, 1);
    // FROM version of the same tween
    transform.DOMoveX(2, 1).From();
    // FROM version of the same tween, with a relative FROM value
    transform.DOMoveX(2, 1).From(true);
    

    Set:用来设置一些动画属性,既可以设置全局的动画属性,也可以操作单个的tweener属性:

    //这里使用链式编程的方法分别设置了该动画属性,一些类型需要通过SetOptions 来特殊处理,如后续说明。
    transform.DOMove(new Vector3(2,2,2), 2)
    .SetOptions(true)
     .SetEase(Ease.OutQuint)
    .SetLoops(4)
    

    说明SetOptions特殊设置的属性

    Generic Tweens Specific Options (already included in the corresponding tween shortcuts)
    Color tween ➨ SetOptions(bool alphaOnly)
    float tween ➨ SetOptions(bool snapping)
    Quaternion tween ➨ SetOptions(bool useShortest360Route)
    Rect tween ➨ SetOptions(bool snapping)
    String tween ➨ SetOptions(bool richTextEnabled, ScrambleMode scrambleMode = ScrambleMode.None, string scrambleChars = null)
    Vector2/3/4 tween ➨ SetOptions(AxisConstraint constraint, bool snapping)
    Vector3Array tween ➨ SetOptions(bool snapping)
    DOPath Specific Options
    Path tween ➨ SetOptions(bool closePath, AxisConstraint lockPosition = AxisConstraint.None, AxisConstraint lockRotation = AxisConstraint.None)
    Path tween ➨ SetLookAt(Vector3 lookAtPosition/lookAtTarget/lookAhead, Vector3 forwardDirection, Vector3 up = Vector3.up)
    TweenParams
    

    On:动画调用过程中的回调,可以在动画开始、结束等时调用相应的方法。

    // Callback without parameters
    transform.DOMoveX(4, 1).OnComplete(MyCallback);
    // Callback with parameters
    transform.DOMoveX(4, 1).OnComplete(()=>MyCallback(someParam, someOtherParam));
    

    2.step

    常用的几个方法

    PlayAll/Play():播放。
    PlayBackwardsAll/PlayBackwards():逆序播放
    PlayForwardAll/PlayForward():顺序播放
    RestartAll/Restart(bool includeDelay = true, float changeDelayTo = -1):重播
    TogglePauseAll/TogglePause():依据当前的状态来取反播放暂停
    

    Unity最受欢迎的插件,可以让您的游戏如虎添翼,为您节省大量时间可以投入在游戏的创意和细节上

     

    如果这些内容帮助到你了,希望您给予支持 o(^ ^)o

     

     

    转载于:https://www.cnblogs.com/Firepad-magic/p/5897589.html

    展开全文
  • Dotween

    2016-09-29 14:58:47
    参考自DOTween官方文档:  DOTween起始上手起来很快,当然前提也是用心看一下哈。 > 可以在Unity AssetStore下载得到。 使用方法:  准备: 在导入DOTween后,你需要设置dotween额外的库设置基你的...

    原文链接:http://blog.csdn.net/u012740992/article/details/47315459

    参考自DOTween官方文档: 
    DOTween起始上手起来很快,当然前提也是用心看一下哈。

    > 可以在Unity AssetStore下载得到。

    使用方法: 
    准备:

    在导入DOTween后,你需要设置dotween额外的库设置基你的Unity版本。Tools—–>DOTween Utility 
    Panel——>点击SetupDoTween即可。DOTween只是为了对应Unity的版本不需关心更多。**

    这里写图片描述



    一,最先简单的使用一下DOTween:

    <code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">using</span> UnityEngine;
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">using</span> System.Collections;
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">using</span> DG.Tweening;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//DOTween命名空间</span>
    
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">class</span> Basics : MonoBehaviour
    {
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//tweeen的目标对象</span>
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> Transform cubeA, cubeB;
    
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> Start()
        {
            <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//全局初始化</span>
            DOTween.Init(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">false</span>, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>, LogBehaviour.ErrorsOnly);
    
            <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//快捷方式创建tween</span>
            cubeA.DOMove(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> Vector3(-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>).SetRelative().SetLoops(-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>, LoopType.Yoyo);
            <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//通用方式创建tween</span>
            DOTween.To(()=> cubeB.position, x=> cubeB.position = x, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> Vector3(-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>).SetRelative().SetLoops(-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>, LoopType.Yoyo);
    
        }
    }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li></ul>

    给cubeA,B指定连个Cube后运行,就可以看到效果了。

    这里写图片描述



    前提说明: 
    Tweener:一个持有值的控制并使值起作用的tween 
    Sequence:一个特殊的tween,与其控制一个值,Sequence控制其它tweens和将它们当成一个组。 
    Tween:一个通用的词,表名包括Tweener和Sequence Nested 
    tween : 一个包含在Sequence内的tween。

    方法前缀:Prefixes 前缀对于编辑器代码感应很重要,所以计量记住这些: 
    DO开头:操作所有已知对象,如transform对象或material对象。当然也是DOTween类的前缀。

    transform.DOMoveX(10, 1); 
    transform.DORestart(); 
    DOTween.Play(); 

    Set: 所有可以链式返回tween的设置。(除了From之外,尽管把它当作一个设置来用,但它实际上并不是一个真正的设置)

    myTween.SetLoops(4, LoopType.Yoyo).SetSpeedBased();

    On: 所有可链式返回tween的回调

    myTween.OnStart(myStartFun).OnComplete(myFunction);



    二 ,解析(初始化):

    1,在要使用Dotween的类里引入命名空间 DG.Tweening;

    2,初始化DOTween全局配置,不初始化将使用默认值,后面仍可以改变初始化的配置,具体方法下步。

    需要记住:如果在创建第一个Tween后才调用DOTween.Init将不会生效。 
    考虑到你仍然在任何时候初始化设置,可以使用全局设置。Global settings 
    通常,你可以在调用DOTween后链式调用DOTween.SetTweensCapacity来一同初始化可同时执行最大的Tweers和Sequence数量。 
    例子如下举例B:

    还有多一种选择就是使用设置Panel的初始化配置:假如在DOTween.Iint初始化时不传任何参数或者传空,那么DOTween将会对此参数使用Panel的设置,但仍需要在代码调用一次Init并参数为空,要不将使用默认的参数。如:

    在Unity工具栏: Tools—–>DOTween Utility Panel—>Preferences 设置: 
    这里写图片描述

    <code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//举例A,使用设置面板的初始化设置</span>
    DOTween.Init();
    
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//举例B:用指定参数初始化,并同时指定最大同时执行Tweeners和Sequence的容量</span>
    DOTween.Init(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>, LogBehaviour.Verbose).SetCapacity(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">200</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>);</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li></ul>

    解析一下初始化参数

    <code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> <span class="hljs-xmlDocTag" style="box-sizing: border-box;"><summary></span></span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> 初始化</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> <span class="hljs-xmlDocTag" style="box-sizing: border-box;"></summary></span></span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> <span class="hljs-xmlDocTag" style="box-sizing: border-box;"><param name="recycleAllByDefault"></span></span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> 默认值为false</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> 如果为true那么所创建的tween建可以循环利用,这意味着当tween播放挂起时并不会被摧毁,</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> 它们将会被放到缓存池待重新使用,这样可以避免GC再为可重复利用的tween分配。但tween挂起你</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> 将需要注意对tween的引用,因为它们就算挂起了,仍可以会被激活,也有可能正被其它的tween使用而被激活。</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> 如果你想tween挂起时自动把tween设置为null,可以这样:</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> myTween.OnKill(()=>mytween = null)</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> 你任何时候都可以改变这个设置:</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> 改变静态变量DG.Tweening.DOTween.defaultRecyclable的参数</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> 或者你也可以为某个tween指定设置这个参数:myTween.SetRecyclable(bool recyclable)</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> </span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> <span class="hljs-xmlDocTag" style="box-sizing: border-box;"></param></span></span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> <span class="hljs-xmlDocTag" style="box-sizing: border-box;"><param name="useSafeMode"></span></span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> 默认为false</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> 如果为true,那么tween将会有些性能将会低一些,但更安全,tween将会去处理一系列事情,如tween在播放而目标为空。</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> <span class="hljs-xmlDocTag" style="box-sizing: border-box;"></param></span></span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> <span class="hljs-xmlDocTag" style="box-sizing: border-box;"><param name="logBehaviour"></span></span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> 打印什么类型日志,默认打印error类型</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> <span class="hljs-xmlDocTag" style="box-sizing: border-box;"></param></span></span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"><span class="hljs-xmlDocTag" style="box-sizing: border-box;">///</span> <span class="hljs-xmlDocTag" style="box-sizing: border-box;"><returns></span><span class="hljs-xmlDocTag" style="box-sizing: border-box;"></returns></span></span>
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">static</span> IDOTweenInit <span class="hljs-title" style="box-sizing: border-box;">Init</span>(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span>? recycleAllByDefault = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">null</span>, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span>? useSafeMode = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">null</span>, LogBehaviour? logBehaviour = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">null</span>);
    </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li></ul>


    三,解析(tween创建方式和设置tween):

    创建tween有3中方式:通用方式,快捷方式,额外通用方式。

    1,通用方式: 这是最灵活的方式,播放中间几乎允许你进行任何值得运算,包括public private static或dynamic(和你想的一样,快捷调用方式最后也是调用这个方法)

    <code class="hljs coffeescript has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span>使myVector在一秒内变换到到<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8</span>
    DOTween.To(getter, setter, to, float duration)
    DOTween.To<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-params" style="color: rgb(102, 0, 102); box-sizing: border-box;">(()=> myVector, x=> myVector = x, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)</span>;
    // 在一秒内变换<span class="hljs-title" style="box-sizing: border-box;">float</span>类型值到52
    <span class="hljs-title" style="box-sizing: border-box;">DOTween</span>.<span class="hljs-title" style="box-sizing: border-box;">To</span><span class="hljs-params" style="color: rgb(102, 0, 102); box-sizing: border-box;">(()=> myFloat, x=> myFloat = x, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">52</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)</span>;</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li></ul>

    2,快捷方式:

    DOTween的快捷方法一些Unity类实例可以使用,像transform, Rigibody和Material等,可以直接从它们的引用开始一个tween, (也将自动的设置这个对象自身为tween驱动的对象) 除了个别指定的外,每个快捷调用也都有一个Form()方法的调用,直接在快捷方法后链式调用From()就会把目标 tween变为起始Tween(也就是把始终位置调换)。 记住:当把Form分配给tween时,目标对象位置将直接跳到起始位置(你写那行代码时就跳,而不是等到tween启动)。

    <code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">//transform将移动到Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>) transform<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOMove</span>(new Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
    rigidbody<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOMove</span>(new Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
    material<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOColor</span>(Color<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.green</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
    
    //From()后反过来,从Vector(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>)到现在的位置 transform<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOMove</span>(new Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.From</span>()<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
    rigidbody<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOMove</span>(new Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.From</span>()<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
    material<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOColor</span>(Color<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.green</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.From</span>()<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
     ```
     
    </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li></ul>

    3,额外通用的法式: 
    这些额外通用的方式允许tween的值通过特殊的方式指定。 除了指定的外,这些方式也有Form(),与快捷调用类似。

    <code class="hljs coffeescript has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">DOTween.Shake<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-params" style="color: rgb(102, 0, 102); box-sizing: border-box;">(()=> myVector, x=> myVector = x, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">45</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">false</span>)</span>;
    
    <span class="hljs-title" style="box-sizing: border-box;">DOTween</span>.<span class="hljs-title" style="box-sizing: border-box;">ToAlpha</span><span class="hljs-params" style="color: rgb(102, 0, 102); box-sizing: border-box;">(()=> myColor, x=> myColor = x, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)</span>; </span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

    无论使用哪种方法,最终会返回一个Twenner或Sequence 所以你仍然可以保持着它们的引用,也可以不关心他们的区别都保存为一个Tween。 也可以直接使用DOTween的多种静态方控制Tween:

    <code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//回放所有</span>
    tween DOTween.RewindAll(); 
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//回放指定ID的</span>
    tween DOTween.Rewind(myId);</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul>

    以上只是创建了tween,下面说明如何设置tween,如 渐变类型,全局时间缩放等。

    设置分为全局设置和特殊设置:

    1,全局设置:

    你可以设置全局配置,这将应用到新建的tween,全局设置允许设置tween自动播放那个和自动关闭行为,渐变类型,全局时间缩放,之类的参数。 设置的方法通常都是DOTween的静态方法:

    DOTween.defaultAutoKill = false; DOTween.defaultEaseType = Ease.InOutCirc;

    2,特殊设置: 
    特殊设置是通过分配的链将以“Set”开始(callback除外),所以编辑器的代码感知会帮你找到它们。

    <code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> //创建一个transformtween,设置它的ease,loops和完成回调 transform<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOMove</span>(new Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>) <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.SetEase</span>(Ease<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.OutQuint</span>) <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.SetLoops</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>) <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.OnComplete</span>(myFunction)<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>
    <code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">//同上,但持有tween的引用来设置,不使用链式编程
    Tween myTween = transform<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOMove</span>(new Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>)<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">; </span>
    myTween<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.SetEase</span>(Ease<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.OutQuint</span>)<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">; myTween.SetLoops(4); myTween.OnComplete(myFunction);</span>
    </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul>

    然而,一些tween类型有它们特殊的选项,这个由tween的值类型可不可以设置SetOptions()决定,只要记住setOption()是特殊的,在maim tween的创建方法后要立刻绑定调用:

    <code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">//和之前的例子一样,但强制转换transform为interger单元值(这对像素填充来说很有用)
     transform<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOMove</span>(new Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>) <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.SetOptions</span>(true) <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.SetEase</span>(Ease<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.OutQuint</span>) <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.SetLoops</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>) <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.OnComplete</span>(myFunction)<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;。</span>
    </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

    甚至可以copy一个tween的设置到另一个tween,使用SetAs()

    <code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">//创建一个tween并进行设置,然后保持它的引用 Tween myTween = transform<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOMove</span>(new Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>) <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.SetEase</span>(Ease<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.OutQuint</span>) <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.SetLoops</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>) <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.OnComplete</span>(myFunction)<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
    
    //C创建另外一个tween,使用上一个相同的设置 material<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOColor</span>(Color<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.red</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>) <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.SetAs</span>(myTween)<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
    
    //所有的tween将以Ease<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.OutQunit</span> 循环loop <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>次,完成后调用同一方法,即使tween的对象和类型不一样
    </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li></ul>


    四,创建一个Sequence:

    Sequence像Tweeners,但并不直接控制参数或值,而是把Tweeners或Sequence当成一个组。 
    Sequence可以包含Sequence,多少有hirecrchy的深度决定,没有限制。

    可以用如下两个步奏创建一个Sequence:

    <code class="hljs rsl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//1,获取一个新的Sequence,并保持它的引用</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//返回一个可用的Sequence,你可以往里面Add tween它会保存起来</span>
    equence mySequence = DOTween.Sequence();
    
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//2,增加tween,间隔和回调到Sequence</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//记住:这些方法必须在Sequence Start前的起作用(通常是你创建之后的下一帧,除非已停止),在Start之后的将不会有效果。</span>
    mySequence.Append(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">transform</span>.DOMoveX(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">45</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>));
    mySequence.AppendInterval(interval);
    
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//给定的时间插入一个tween,允许你重叠已存在的tween而不是替换</span>
    mySequence.InsertCallback(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>, MyCallback);</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li></ul>

    提示:如果你创建一个Sequence知识为了使用回调和定时器,那么可以这样使用:

    <code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> // 获取一个空的Sequence
    Sequence mySequence = DOTween<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.Sequence</span>()<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
    // 在开启添加一个move的tween
    mySequence<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.Append</span>(transform<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOMoveX</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">45</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>))<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
    // 在第一个结束后开启一个旋转的tween
    mySequence<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.Append</span>(transform<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DORotate</span>(new Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">180</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>))<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
    // 所有的延迟一秒
    mySequence<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.PrependInterval</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
    // 在整个Sequence期间插入一个缩放的tween
    mySequence<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.Insert</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, transform<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOScale</span>(new Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>), mySequence<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.Duration</span>()))<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
    
    
    //和上面的例子效果一样,但使用链式编程,使其看起来更简洁
    Sequence mySequence = DOTween<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.Sequence</span>()<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span>
    
    mySequence<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.Append</span>(transform<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOMoveX</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">45</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>))
      <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.Append</span>(transform<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DORotate</span>(new Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">180</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>), <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>))
      <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.PrependInterval</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)
      <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.Insert</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, transform<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.DOScale</span>(new Vector3(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span>), mySequence<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.Duration</span>()))<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li></ul>


    五,其它:

    当你创建一个tween的时候它将会自动播放直到完成loop次数,除非你改变全局设置的defaultAutoPlay设置。 
    当一个tween播放完成将会自己摧毁,这意味着你不能再次使用这个tween,除非你改变全局设置的defultAutoKill 
    如果你的tween的target为空,在tween播放时将会报错,你需要注意这个问题或者激活安全模式。

    如果你激活recycling(再循环),DOTween将会缓存你创建的所有的tween,所以可以不再建新的tween就可以重复利用它们。 
    当然,为了避免占用过大的资源,里面设置最大200个tween和50个Sequence同时运行,如果需要更多,DOTween将自动递增容量,但你也可以直接闭避免卡顿自动调整容量 
    //设置最大tween数量3000和最大Sequences数量200: 
    DOTWeen.SetTweensCapacity(3000,200); 
    任何时候你想清除DOTween的缓存或彻底重置它们,可以调用DOTween.Clean(),这将摧毁所有的tween和清除所有的DOTween缓存。

    //循环利用a tween 
    你不需要手动循环利用tweens,你可以选择自动重复利用全部或者只指定一些,你依旧可以任何时候改变Tweener的结束和开始值

    展开全文

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,647
精华内容 658
关键字:

dotween