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
 DOTweenHOTweenLeanTweenGoKitiTween
Average FPS124 FPS25 FPS102 FPSfreezesfreezes
Startup time76 MS332 MS34 MSfreezesfreezes
16,000 generic floats in a loop
 DOTweenHOTweenLeanTweenGoKitiTween
Average FPS412 FPS115 FPS389 FPS387 FPSfreezes
Startup time14 MS74 MS7 MS47,432 MSfreezes
2,000 generic floats in a loop
 DOTweenHOTweenLeanTweenGoKitiTween
Average FPS1091 FPS888 FPS1050 FPS998 FPS3 FPS
Startup time2 MS11 MS1 MS6,258 MS240 MS

Transforms

4,000 transforms looping around

 

 DOTweenHOTweenLeanTweenGoKitiTween
Average FPS68 FPS63 FPS68 FPS65 FPS38 FPS
Startup time5 MS30 MS3 MS130 MS229 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

转载于:https://www.cnblogs.com/MrZivChu/p/UnityTween.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值