Unity DoTween加iTweenPath的简单使用

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 Panel
DOTween.Init();
// EXAMPLE B: initialize with custom settings, and set capacities immediately
DOTween.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
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值