[Unity插件]DOTween(2)
2016-03-15 15:50
661 查看
官方网站:http://dotween.demigiant.com/下载地址:http://dotween.demigiant.com/download.php快速开始:http://dotween.demigiant.com/getstarted.php官方文档:http://dotween.demigiant.com/documentation.php
一、准备工作
1、下载 DOTween,解压至Unity的Asset文件夹,如果你使用的Unity版本低于Unity4.3,请删除所有的 DOTween43文件2、在你们创建一个新的脚本时,需要在顶部导入命令空间:using DG.Tweening;3、初始化全局选项(可选)DOTween.Init(autoKillMode, useSafeMode, logBehaviour);
如果你不这样做(或在你创建第一个Tween之后)DOTween将自动初始化为默认值,但你仍然可以改变它们
二、介绍
DOTween可以使用 完全通用的方法,像这样你也可以使用 便捷的方法,像这样
无论选择那种方式,当你创建 tween 都会返回一个Tweener 或一个序列(两者的差异),如果你需要保存,你可以保存两者为Tween而无须关心它们的区别。你可以以不同的方式 控制多个tween,你可以使用static的DOTween方法(有过滤的附加选项)…… // Rewind all tweens 撤消所有的tween
DOTween.Rewind();
// Rewind all tweens with a given id 根据指定id撤消tween
DOTween.Rewind(myId);
直接的tween引用
// Rewind a referenced tween 撤消引用的tween myTween.Rewind();
或更多方式
// Rewind all tweens connected to a specific transform 撤消所有的tween到特定的transform transform.DORewind();
三、Global或特定设置
你可以设置 global settings 将应用于所有新创建的补间动画,或通过 具体设置 为每一个单独的补间动画。全局设置
全局设置 允许你设置默认 autoPlay和autoKill 行为,ease type,global timeScale,以及类似的东西。具体设置
具体设置 是通过链分配,他们都开始以“Set”开始(除了Callbacks,是以"On"开始”),所以智能感知帮助你找到他们,这儿有些例子// Create a transform tween and set its ease, loops and OnComplete callback(创建一个transform的tween,设置type为ease,循环,OnComplete回调)transform.DOMove(new Vector3(2,2,2), 2).SetEase(Ease.OutQuint).SetLoops(4).OnComplete(myFunction);
// Same as above but using line breaks to make it more readable(同上,但使用换行符,使其更具可读性)
transform.DOMove(new Vector3(2,2,2), 2)
.SetEase(Ease.OutQuint)
.SetLoops(4)
.OnComplete(myFunction);
// Same as above but storing the tween and applying settings without chaining(同上,但没有使用链的方式)
Tween myTween = transform.DOMove(new Vector3(2,2,2), 2);
myTween.SetEase(Ease.OutQuint);
myTween.SetLoops(4);
myTween.OnComplete(myFunction);
此外一类 tween 类型都有 特殊的附加功能,取决取决于值补间的取决于值补间的类型,它可以通过设置 SetOptions() 只要记住, SetOptions()是特殊的,当主要创建补间动画的方法后它需要立即链接:
// Same as the previous examples, but force the transform to // snap on integer values (very useful for pixel perfect stuff) //和上面的例子类似,但需要强制transform临时调整数值(对于像素完美是非常有用的) transform.DOMove(new Vector3(2,2,2), 2) .SetOptions(true) .SetEase(Ease.OutQuint) .SetLoops(4) .OnComplete(myFunction);你甚至可以Copy 一个tween的设置到另一个tween ,使用SetAs() :// Create a tween with some settings and store it as a Tween
Tween myTween = transform.DOMove(new Vector3(2,2,2), 2)
.SetEase(Ease.OutQuint)
.SetLoops(4)
.OnComplete(myFunction);
// Create another tween and apply the same settings as the previous one(创建另一个tween,并应用上一个tween的设置)
material.DOColor(Color.red, 2).SetAs(myTween);( 这两个tween都会循环4次,easeType为OutQuint,当tween完成时都会调用myFunction)
四、Tween的Life(生命周期)
当你创建tween时它会自动播放(除非你设置了全局的 defaultAutoPlay 行为)直到完成循环当tween完成后它会自动终止(除非你设置了做全局的 defaultAutoKill 行为),这意味着你不能再使用它。如果你们要重复使用同一个tween,仅仅需要设置它的 autoKill 为 False(可以通过 global autoKill 设置所有的tweens 或为你自己的tween 设置 SetAutoKill(false) ).如果你的tween的target为null,在tween播放时会报异常,你需要注意或激活 安全模式五、Cache和tween最大值
如果你有 缓存池 缓存所有的你创建的tween,它们就可以重复使用,不需要创建新的。此外也可以避免使用更多的资源,它会限制最大200个Tweeners并且50FPS在同一时间,如果你需要更多,DOTween会自动增加它的大小,当然你可以直接设置 来避免自动调整可能会发生卡顿的情况// Set max Tweeners to 3000 and max Sequences to 200(设置最大Tweeners为300,最大FPS为200)DOTween.SetTweensCapacity(3000, 200);
在任何时候你想 在tween完成时清除DOTween的cache,你可以调用 DOTween.Clear(),它会kill所有的tweens并释放所有的缓存.
六、Recycling tween
你不需要手动回收 tween,相反你可以选择自动 回收所有的 或 回收特定的不过,在任何时间你都可以 改变 Tweener的 start和end values相关文章推荐
- Unity AssetBundle爬坑手记
- 贝塞尔曲线制作跳跃轨迹
- 推荐 git community book 中文版
- Unity入门之UGUI中Image的属性
- Unity3D游戏开发之使用Unity3D开发2D游戏(二)(2DTookit插件亲测)
- Unity学习之实现拖拽功能
- unity terrain export to obj
- unity3d上用vuforia开发AR
- Unity制作人物头像小图标和小地图
- Unity3D之MeleeWeaponTrail武器轨迹插件的使用
- Unity Shaders and Effects Cookbook (1-1) 基本的表面着色器 (Surface Shader)
- iTween基础之CameraFade(摄像机淡入淡出)
- unity的input鼠标
- unity AssetBundles
- Unity3d开发(九) 动画模型资源导入预处理
- Unity实例-坦克大战
- 自己主动生成材质Material(Unity3D开发之十九)
- Unity3d 5.0 UI穿透判断
- Unity3D面试题整合(看完Unity基础知识就掌握差不多了)
- 有用的Unity社区贴