本文只涉及一些案例,具体查看 DoTween 官方文档

一、 Basics

 public class Basics : MonoBehaviour
{
public Transform redCube, greenCube, blueCube, purpleCube; IEnumerator Start()
{
// Start after one second delay (to ignore Unity hiccups when activating Play mode in Editor)
yield return new WaitForSeconds(); // 2秒时间移动到 0,4,0
redCube.DOMove(new Vector3(,,), ); // 2秒时间从 0,4,0 移动到原始位置
greenCube.DOMove(new Vector3(,,), ).From(); // 2秒时间移动 0,4,0 相对位置
blueCube.DOMove(new Vector3(,,), ).SetRelative(); // 2秒时间移动 6,0,0 相对位置
purpleCube.DOMove(new Vector3(,,), ).SetRelative();
// 2秒内将颜色变为黄色,并且循环往复一直执行
purpleCube.GetComponent<Renderer>().material.DOColor(Color.yellow, ).SetLoops(-, LoopType.Yoyo);
}
}

  该场景主要涉及对一些 Unity 组件(transform, material)属性的变换,当然我们也可以对其他一些组件(Audio, Camera, Light, Rigidbody, ...)进行操作。

二、Follow

 public class Follow : MonoBehaviour
{
public Transform target; // Target to follow
Vector3 targetLastPos;
Tweener tween; void Start()
{
// 启动后先移动到目标位置,保存 Tweener 并且设置不自动销毁
tween = transform.DOMove(target.position, ).SetAutoKill(false);
// 存储上一目标位置
targetLastPos = target.position;
} void Update()
{
// 目标没有移动
if (targetLastPos == target.position) return;
// 修改目标位置,重新开始动画
tween.ChangeEndValue(target.position, true).Restart();
// 保存目标位置,用于下次比较
targetLastPos = target.position;
}
}

  该场景实现目标跟随,当目标物移动的时候,跟随物体会相应移动。其中涉及到 Tweener 的设置与控制。

三、Materials

 public class Materials : MonoBehaviour
{
public GameObject target;
public Color toColor; Tween colorTween, emissionTween, offsetTween; void Start()
{
// 获取材质组件
Material mat = target.GetComponent<Renderer>().material; // 改变材质颜色,动画默认状态为暂停
colorTween = mat.DOColor(toColor, ).SetLoops(-, LoopType.Yoyo).Pause(); // 修改材质光线发散颜色,注意属性 _EmissionColor
emissionTween = mat.DOColor(new Color(, , , ), "_EmissionColor", ).SetLoops(-, LoopType.Yoyo).Pause(); // 修改材质偏移,动画变化为线性,持续增加
offsetTween = mat.DOOffset(new Vector2(, ), ).SetEase(Ease.Linear).SetLoops(-, LoopType.Incremental).Pause();
} // Toggle methods (called by UI events) public void ToggleColor()
{
// 切换动画状态,播放或者暂停
colorTween.TogglePause();
} public void ToggleEmission()
{
emissionTween.TogglePause();
} public void ToggleOffset()
{
offsetTween.TogglePause();
}
}

  该场景主要实现 material 的动画效果。其中 SetEase 方法设置动画的属性变化方式(线性,抛物线等,就是变化速度)。

  

四、Paths

 public class Paths : MonoBehaviour
{
public Transform target;
public PathType pathType = PathType.CatmullRom;
// 路径
public Vector3[] waypoints = new[] {
new Vector3(, , ),
new Vector3(, , ),
new Vector3(, , ),
new Vector3(, , ),
new Vector3(-, , )
}; void Start()
{
// 按路径运动
// 使用 SetOptions 函数使路径封闭
// 使用 SetLookAt 函数使物体朝向路径本身
Tween t = target.DOPath(waypoints, , pathType)
.SetOptions(true)
.SetLookAt(0.001f);
// 线性变化且无限循环
t.SetEase(Ease.Linear).SetLoops(-);
}
}

  该场景实现了物体按路径运动动画。

  

五、Sequences

 public class Sequences : MonoBehaviour
{
public Transform cube;
public float duration = ; IEnumerator Start()
{
yield return new WaitForSeconds(); // 新建一个 Sequence
Sequence s = DOTween.Sequence();
// 添加一个动画,持续一个周期
s.Append(cube.DOMoveX(, duration).SetRelative().SetEase(Ease.InOutQuad));
// 添加一个动画,持续半个周期
s.Insert(, cube.DORotate(new Vector3(, , ), duration / ).SetEase(Ease.InQuad).SetLoops(, LoopType.Yoyo));
// 添加一个动画,半个周期时开始,切持续半个周期
s.Insert(duration / , cube.GetComponent<Renderer>().material.DOColor(Color.yellow, duration / ));
s.SetLoops(-, LoopType.Yoyo);
}
}

   该场景实现了一个简单的 Sequences。其中 Append 方法是将动画加在末尾,而 Insert 方法是可以加到任意位置。

六、UGUI

 public class UGUI : MonoBehaviour
{
public Image dotweenLogo, circleOutline;
public Text text, relativeText, scrambledText;
public Slider slider; void Start()
{
// Logo 图片渐渐消失动画
dotweenLogo.DOFade(, 1.5f).SetAutoKill(false).Pause(); // 图片颜色动画
circleOutline.DOColor(RandomColor(), 1.5f).SetEase(Ease.Linear).Pause();
// 图片部分显示动画,结束后按相反方向
circleOutline.DOFillAmount(, 1.5f).SetEase(Ease.Linear).SetLoops(-, LoopType.Yoyo)
.OnStepComplete(()=> {
circleOutline.fillClockwise = !circleOutline.fillClockwise;
circleOutline.DOColor(RandomColor(), 1.5f).SetEase(Ease.Linear);
})
.Pause(); // 文字动画
text.DOText("This text will replace the existing one", ).SetEase(Ease.Linear).SetAutoKill(false).Pause();
relativeText.DOText(" - This text will be added to the existing one", ).SetRelative().SetEase(Ease.Linear).SetAutoKill(false).Pause();
scrambledText.DOText("This text will appear from scrambled chars", , true, ScrambleMode.All).SetEase(Ease.Linear).SetAutoKill(false).Pause(); // 滑动条动画
slider.DOValue(, 1.5f).SetEase(Ease.InOutQuad).SetLoops(-, LoopType.Yoyo).Pause();
} // Called by PLAY button OnClick event. Starts all tweens
public void StartTweens()
{
DOTween.PlayAll();
} // Called by RESTART button OnClick event. Restarts all tweens
public void RestartTweens()
{
DOTween.RestartAll();
} // Returns a random color
Color RandomColor()
{
return new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), );
}
}

  该场景主要实现了 UGUI 组件的动画。

Unity Dotween官方案例学习的更多相关文章

  1. Unity XLua 官方案例学习

    1. Helloworld using UnityEngine; using XLua; public class Helloworld : MonoBehaviour { // Use this f ...

  2. Unity EasyTouch官方案例学习

    一.代码检测手势事件 1. EasyTouch4.x 写法 首先要手动在 Hierarchy 窗口添加 EasyTouch 物体,以触摸(Touch)手势为例,代码如下: using UnityEng ...

  3. 8.3 ContosoMVCWeb官方案例学习

    1. 分页案例学习 2. 排序搜索案例学习 3.使用Configuration.cs中的Seed方法 在数据库迁移过程中,使用update-database,会运行seed方法.seed方法能够将初始 ...

  4. Egret官方案例学习笔记

    1.资源记载方式 (1)Egret引擎是2.0.5. (2)resource/resource.json文件是: { "resources": [ { "name&quo ...

  5. Unity XLua 官方教程学习

    一.Lua 文件加载 1. 执行字符串 using UnityEngine; using XLua; public class ByString : MonoBehaviour { LuaEnv lu ...

  6. UE4的AI学习(2)——官方案例实例分析

    官方给出的AI实例是实现一个跟随着玩家跑的AI,当玩家没有在AI视野里时,它会继续跑到最后看到玩家的地点,等待几秒后如果仍然看不到玩家,则跑回初始地点.官方的案例已经讲得比较详细,对于一些具体的函数调 ...

  7. Unity CommandBuffer的一些学习整理

    1.前言 近期在整理CommandBuffer这块资料,之前的了解一直较为混乱. 算不上新东西了,但个人觉得有些时候要比加一个摄像机再转RT廉价一些,至少省了深度排序这些操作. 本文使用两个例子讲解C ...

  8. 通过angularJS官方案例快速入门

    官方案例-angular-phonecat angularJS官方提供了一个官方案例给大家进行循序渐进的学习,但是如果之前没有接触过node.js以及git的同学这个案例拿着也无从下手-这里就介绍一下 ...

  9. Siki_Unity_2-4_UGUI_Unity5.1 UI 案例学习

    Unity 2-4 UGUI Unity5.1 UI 案例学习 任务1-1:UGUI简介 什么是GUI: 游戏的开始菜单 RPG游戏的菜单栏.侧边栏和功能栏(比如背包系统.任务列表等) 设计用来控制移 ...

随机推荐

  1. java读取txt文件的2中方法---并将内容(每一行以固定的字符分割切成2段)存到map中去

    #java读取txt文件的第一种方法 /** * 方法:readTxt * 功能:读取txt文件并把txt文件的内容---每一行作为一个字符串加入到List中去 * 参数:txt文件的地址 * 返回: ...

  2. 跨平台开发 -- C# 使用 C/C++ 生成的动态链接库

    操作环境:Visual Studio 2017 如何实现 使用 C# 进行嵌入式开发? .NET Core 虽然实现了跨平台,但是不可能处处使用 C# 开发,就好像没人使用SQL开发安卓APP,每种语 ...

  3. 详解动态规划(Dynamic Programming)& 背包问题

    详解动态规划(Dynamic Programming)& 背包问题 引入 有序号为1~n这n项工作,每项工作在Si时间开始,在Ti时间结束.对于每项工作都可以选择参加与否.如果选择了参与,那么 ...

  4. Springboot连接MySQL8.0出现的问题

    以前用的是5.7版本的MySQL,在学习实践Springboot的时候顺带升级了一下8.0,遇到了一些坑,在这记录一下,有碰到同类问题的童鞋需要自取. 使用 navicat连接发现报错1251- Cl ...

  5. html简单介绍(一)

    什么是html HTML 是用来描述网页的一种语言.HTML 指的是超文本标记语言 (Hyper Text Markup Language)HTML 不是一种编程语言,而是一种标记语言 (markup ...

  6. os.path.md

    os.path 我们可以利用os.path模块提供的函数更容易地在跨平台上处理文件. 即使我们的程序不是用于夸平台, 也应该使用os.path来让路径名字更加可靠. Parsing Paths os. ...

  7. 面向对象的JavaScript --- 动态类型语言

    面向对象的JavaScript --- 动态类型语言 动态类型语言与面向接口编程 JavaScript 没有提供传统面向对象语言中的类式继承,而是通过原型委托的方式来实现对象与对象之间的继承. Jav ...

  8. BZOJ5092:[Lydsy1711月赛]分割序列(贪心,高维前缀和)

    Description 对于一个长度为n的非负整数序列b_1,b_2,...,b_n,定义这个序列的能量为:f(b)=max{i=0,1,...,n}((b_1 xor b_2 xor...xor b ...

  9. tomcat Win10 配置环境变量详解

    在Win10系统总该如何配偶之tomcat 环境变量?今天win10之家给大家带来了关于win10系统中配置tomcat环境的操作方法.在配置之前我们需要做以下几点: 步骤:安装和配置好了Java 的 ...

  10. Oracle create tablespace 创建表空间语法详解

    CREATE [UNDO]  TABLESPACE tablespace_name          [DATAFILE datefile_spec1 [,datefile_spec2] ...... ...