Unity DoTween加iTweenPath的简单使用

来源:互联网 发布:淘宝客导购名称怎么填 编辑:程序博客网 时间:2024/05/16 23:33

Dotween比iTween的优点

1,DoTween的通知机制使用 iTween的效率比iTween高上好几倍,iTween使用消息传递机制使用SendMessage,sendMessage使用反射实现,效率不高。

2,iTween使用的参数还是字符串,用起来有些不习惯


如果要了解DOTween详细点的也可以看这篇博客哈O(∩_∩)O~~:DOTween教程


一, 下载、文档 Dotween:http://dotween.demigiant.com/pro.php

也可以直接从Unity 的assert store下载

引入DoTween后,可在工具栏Tools--》DoTween Utility Pannel-->SetupDotween适配当前unity版本的新feature,也可打开dotween官网文档,也可以在Preferences设置

DoTween的全局信息。



二,引入Unity项目后,Dotween 的命名空间是  using  DG.Tweening;

开始初始化

DOTween.Init(autoKillMode, useSafeMode, logBehaviour);
不初始化则使用默认值,

// EXAMPLE A: initialize with the preferences set in DOTween's Utility PanelDOTween.Init();// EXAMPLE B: initialize with custom settings, and set capacities immediatelyDOTween.Init(true, true, LogBehaviour.Verbose).SetCapacity(200, 10);

DoTween可操作多种变量

transform.DOMove(new Vector3(2,3,4), 1);rigidbody.DOMove(new Vector3(2,3,4), 1);material.DOColor(Color.green, 1);

可使用链式编程:

          transform.DOPath(path, 5, PathType.CatmullRom, PathMode.Full3D, 10, Color.red)                .SetLoops(100, LoopType.Yoyo)                .SetEase(Ease.OutQuart)                ;

三,在itween里,我一时没有发现类似iTween里很好用的iTweenpath工具,可视化创建物体运动路径

所以我把iTween里的ITweenPath类也拿来和Dotween用了。

用法:可视化创建路径

1,把ITweenPath类导入Unity后

2,新建一个空GameObject,更名为“iPath”,然后挂上iTweenPath脚本

3,给ITweenPath分配5个路径节点,然后就可以在Scene手动创建路径了




4,路径创建好了,新建一个需要移动的物体:

3D Object -->>Cube吧,然后新建C#脚本DotMove,写代码

using UnityEngine;using System.Collections;using DG.Tweening;public class DotMove : MonoBehaviour {    public iTweenPath ipath;    void Start() {        //获取路径节点        Vector3[] path = new Vector3[ipath.nodeCount];        for (int i = 0; i < ipath.nodeCount; i++) {             path[i] = ipath.nodes[i];        }               //DoTween设置路径       transform.DOPath(path, 5, PathType.CatmullRom, PathMode.Full3D, 10, Color.red)               .SetLoops(100, LoopType.Yoyo)               .SetEase(Ease.OutQuart) ;        }   }

4,回到编辑器,往cube的DoMove ipath挂上ipath,然后run————————》》,完成。



0 0
原创粉丝点击