Unity-Tween


1、GoKit

免費開源

AssetStore:https://www.assetstore.unity3d.com/en/#!/content/3663

下載地址:https://github.com/prime31/GoKit

2、ITween

免費開源

官網:http://itween.pixelplacement.com/index.php

AssetStore:https://www.assetstore.unity3d.com/en/#!/content/84

下載地址:https://github.com/jtothebell/iTween

缺點:

  1. 大量使用SendMessage,而SendMessage使用反射,效率不高
  2. iTween的參數都是string,你需要自己去拼一個Hashtable,去記字符串,不人性化!每次寫都要去它的官網上去查字符串怎么拼,挺蛋疼的!

3、LeanTween

免費開源

AssetStore:https://www.assetstore.unity3d.com/en/#!/content/3595

下載地址:https://github.com/dentedpixel/LeanTween

優點:貌似比Hotween和Itween性能好,快!參考:http://dentedpixel.com/developer-diary/leantween-speed-comparison-to-itween/

4、Hotween

免費開源

官網:http://hotween.demigiant.com/

AssetStore:https://www.assetstore.unity3d.com/en/#!/content/3311

下載地址:http://hotween.demigiant.com/

5、DOTween

 這是Hotween官網出的,速度超過4倍更快,更高效,大量的新功能

下載地址:http://dotween.demigiant.com/download.php#download

 Comparison with other engines

If you want, you can download the test package I used (oops sorry, I'll put it up there when I get into beta, otherwise I should update it every hour - but you can still get the most recent one from DOTween's Google Code area).

All these tests were done from a build, since some of these tween engines (DOTween, HOTween and GoKit) do additional stuff while in the Editor to show editor-only debug informations, and thus testing them outside the editor, where it counts, seemed more fair.

To keep the test accurate download the latest versions of all engines and replace the old ones (the ones used here are from July/August 2014).

Generic floats

You'll find more tests for the tween of generic floats because GoKit and iTween couldn't tween as many as the other engines, but I still wanted to show high-level results.

64,000 generic floats in a loop

  DOTween HOTween LeanTween GoKit iTween
Average FPS 124 FPS 25 FPS 102 FPS freezes freezes
Startup time 76 MS 332 MS 34 MS freezes freezes

16,000 generic floats in a loop

  DOTween HOTween LeanTween GoKit iTween
Average FPS 412 FPS 115 FPS 389 FPS 387 FPS freezes
Startup time 14 MS 74 MS 7 MS 47,432 MS freezes

2,000 generic floats in a loop

  DOTween HOTween LeanTween GoKit iTween
Average FPS 1091 FPS 888 FPS 1050 FPS 998 FPS 3 FPS
Startup time 2 MS 11 MS 1 MS 6,258 MS 240 MS

Transforms

4,000 transforms looping around

 

  DOTween HOTween LeanTween GoKit iTween
Average FPS 68 FPS 63 FPS 68 FPS 65 FPS 38 FPS
Startup time 5 MS 30 MS 3 MS 130 MS 229 MS

 

實現人物沿四個點移動,實現這同一效果,代碼分別為:

 

 

public class MyDotween : MonoBehaviour
{
    public Transform[] paths;
    void Start()
    {
        Vector3[] v = new Vector3[4];
        for (int i = 0; i < paths.Length; i++)
        {
            v[i] = paths[i].position;
        }
        transform.DOPath(v, 3f, PathType.Linear).SetLookAt(-1).SetDelay(1f).SetEase(Ease.Linear).OnComplete(ItweenAnimationEnd);
    }
    //對象移動時調用
    void ItweenAnimationEnd()
    {
        Debug.Log("end : ");
    }
}
Dotween
public class MyLeanTween : MonoBehaviour
{
    public Transform[] paths;
    void Start()
    {
        //四個點的話,那么應該是這樣確定點的位置,並且數組長度必須是4的倍數:
        // O(對象自己的位置)->A    A->B    B->C   C->D
        Vector3[] v = new Vector3[8];
        v[0] = transform.position;
        for (int i = 0; i < paths.Length; i++)
        {
            v[i * 2 + 1] = paths[i].position;
            if (i == 3)
                continue;
            v[i * 2 + 2] = paths[i].position;
        }
        Hashtable args = new Hashtable();
        args.Add("path", v);
        //是否讓模型始終面朝當面目標的方向
        args.Add("orientToPath", true);
        //移動結束時調用,參數和上面類似
        args.Add("onComplete", "LeanAnimationEnd");
        args.Add("onCompleteParam", "zwh");
        //設置類型為線性,線性效果會好一些。
        args.Add("loopType", LeanTweenType.linear);
        //設置延遲
        args.Add("delay", 1f);
        //設置循環
        args.Add("repeat", 1);
        LeanTween.move(gameObject, v, 3f, args);
    }
    //對象移動時調用
    void LeanAnimationEnd(object obj)
    {
        Debug.Log("end : " + obj);
    }
}
LeanTween
public class MyGoKit : MonoBehaviour
{
    public Transform[] paths;
    void Start()
    {
        Vector3[] v = new Vector3[5];
        v[0] = transform.position;//設置自身的位置為第一個位置,因為沒有像ITween中的movetopath選項可以設置
        for (int i = 0; i < paths.Length; i++)
        {
            v[i + 1] = paths[i].position;
        }
        GoTweenConfig config = new GoTweenConfig();
        //設置路徑的點
        var path = new GoSpline(v, true);
        //設置類型為線性,線性效果會好一些。
        config.easeType = GoEaseType.Linear;
        //GoLookAtType.NextPathNode是和ITween的orienttopath設置功能是一樣的
        config.positionPath(path, false, GoLookAtType.NextPathNode);
        //設置循環
        config.setIterations(1);
        config.onComplete(delegate(AbstractGoTween obj)
        {
            Debug.Log("end : " + obj);
        });

        //這里to方法的第一個參數必須傳transform類型的變量,不然報錯
        Go.to(gameObject.transform, 3f, config);
    }

    void OnDrawGizmos()
    {
        //在scene視圖中繪制出路徑與線
        iTween.DrawLine(paths, Color.yellow);

        iTween.DrawPath(paths, Color.red);
    }
}
GoKit
public class MyHotween : MonoBehaviour
{
    public Transform[] paths;
    void Start()
    {
        Vector3[] v = new Vector3[4];
        for (int i = 0; i < paths.Length; i++)
        {
            v[i] = paths[i].position;
        }
        TweenParms tp = new TweenParms();
        tp.Delay(1f);
        tp.Loops(1);
        tp.OnComplete(PathCycleComplete, "zwh");
        tp.Ease(EaseType.Linear);
        PlugVector3Path p = new PlugVector3Path(v, PathType.Linear);
        p.OrientToPath(true);
        tp.Prop("position", p);
        HOTween.To(gameObject.transform, 3, tp);

    }

    void PathCycleComplete(TweenEvent abc)
    {
        Debug.Log("end : " + abc.parms[0]);
    }
}
Hotween
public class MyItween : MonoBehaviour
{
    //路徑尋路中的所有點
    public Transform[] paths;

    void Start()
    {
        Hashtable args = new Hashtable();
        //設置路徑的點
        args.Add("path", paths);

        //設置類型為線性,線性效果會好一些。
        args.Add("easeType", iTween.EaseType.linear);

        //設置尋路的速度
        args.Add("speed", 6f);

        //是否先從原始位置走到路徑中第一個點的位置
        args.Add("movetopath", true);

        //是否讓模型始終面朝當面目標的方向
        //如果你發現你的模型在尋路的時候時鍾都是一個方向那么一定要打開這個
        args.Add("orienttopath", true);

        //移動結束時調用,參數和上面類似
        args.Add("oncomplete", "ItweenAnimationEnd");
        args.Add("oncompleteparams", "zwh");
        args.Add("oncompletetarget", gameObject);

        //讓模型開始尋路    
        iTween.MoveTo(gameObject, args);
    }
    //對象移動時調用
    void ItweenAnimationEnd(string f)
    {
        Debug.Log("end : " + f);
    }
    void OnDrawGizmos()
    {
        //在scene視圖中繪制出路徑與線
        iTween.DrawLine(paths, Color.yellow);

        iTween.DrawPath(paths, Color.red);
    }
}
Itween

總結:

從以上分析,Dotween和Leantween效率比較好,但是從代碼角度看,Dotween代碼可讀性強,體現了面向對象的思想,而Leantween仍然要死記字符串!

參考:http://www.xuanyusong.com/archives/2671

        http://dotween.demigiant.com/index.php


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM