Unity3d itween path插件是可以通过调用相应的函数从而进行遊戲编程中物體移動效果的插件,主要用于遊戲开发,可以帮助用户完成各种动画,多种参数可以自由设置。欢迎下载!

Unity itween插件原理
iTween的核心是数值插值,简单说就是给iTween两个数值(开始值,结束值),它会自动生成一些中间值,例如:, 开始值-> 中间值 -> 中间值 …. -> 结束值。
这里的数值可以理解为: 数字,坐标点,角度,物体大小,物体颜色,音量大小等。
主要文件有两个iTween.cs 和 iTweenPath.unitypackage(编辑路径才需要这个包)
Unity itween插件演示效果
物體移動
iTween.MoveTo(gameObject,new Vector3(100,200,0),2);
第二個參數是要移動到的目標點坐標
其中第一個參數是要移動的物體
第三個參數是移動需要的時間,然後物體將在2秒之內移動到坐標點爲(x=100,y=200,z=0)的位置。
itween path使用教程
一, 下载、文档 Dotween:
引入DoTween后,可在工具栏Tools--》DoTween Utility Pannel-->SetupDotween适配当前unity版本的新feature,也可打开dotween官网文档,也可以在Preferences设置
DoTween的全局信息。
二,引入Unity项目后,Dotween 的命名空间是 using DG.Tweening;
開始初始化
DOTween.Init(autoKillMode, useSafeMode, logBehaviour);
不初始化則使用默認值,
[csharp] view plain copy// EXAMPLE A: initialize with the preferences set in DOTween's Utility Panel
DOTween.Init();
// EXAMPLE B: initialize with custom settings, and set capacities immediately
DOTween.Init(true, true, LogBehaviour.Verbose).SetCapacity(200, 10);
DoTween可操作多種變量
[csharp] view plain copytransform.DOMove(new Vector3(2,3,4), 1);
rigidbody.DOMove(new Vector3(2,3,4), 1);
material.DOColor(Color.green, 1);
可使用鏈式編程:
[csharp] view plain copytransform.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,写代码
[csharp] view plain copyusing 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 = ipath.nodes;
}
//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————————》》,完成。
