本文只涉及一些案例,具体查看 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. 微信小程序里解决app.js onLaunch事件与小程序页面的onLoad加载前后异常问题

    使用 Promise 解决小程序页面因为需要app.js onLaunch 参数导致的请求失败 app.js onLaunch 的代码 "use strict"; Object.d ...

  2. Mybatis 学习笔记

    可学习渠道  MYBATIS 入门教程 1. Mybatis 介绍 Mybatis 是 sqlmap 技术,对 JDBC 进行封装,将大量的 SQL 语句外部化. 平时我们都用JDBC访问数据库,除了 ...

  3. 【转】Spring学习---为什么要用spring,springMVC

    [原文]https://www.toutiao.com/i6593182323095634445/ 首先,软件里有很多优秀的框架,有一种类型的框架,它的特点是建立在一个现有技术的基础上,提供和现有技术 ...

  4. 一、HttpServletRequest接口 二、HttpServletReponse接口 三、POST和GET请求方式及其乱码处理 四、ServletContext对象和ServletConfig对象

    一.HttpServletRequest接口 内部封装了客户端请求的数据信息 接收客户端的请求参数.HTTP请求数据包中配置参数 ###<1>常用方法 getContextPath()重要 ...

  5. [C++] set与multiset的常用函数

    参考资料:[C++ STL]Set和Multiset set 与 multiset set不允许重复 multiset允许重复 例: set : 1 2 3 4 5 6 multiset : 1 2 ...

  6. linux 的常用命令---------第二阶段

    vim编辑器 vim 文件名(首先进入命令模式) :(进行编辑文件内容)  → 按 i 键进入插入模式,可以写内容啦. ↓ 按 Esc 键,进入命令模式 ↓ 按 shift + : 键,进入末行模式  ...

  7. 突然的明白--public static 类名 函数名()

    public static ImageUtilEngine getImageEngine() { return imageEngine; } 这个是什么啊........纠结了一个多星期的东西 忽然间 ...

  8. Web.config中 mode="RemoteOnly" 跟mode="On" 区别

    转载网址:mode="RemoteOnly" 跟mode="On" 区别 <!-- 自定义错误信息 设置 customErrors mode=" ...

  9. 注冊成为Windows Phone开发人员而且解锁Windows Phone 8.1手机

    注冊成为Windows Phone开发人员而且解锁Windows Phone 8.1手机 上篇文章介绍了怎样使用Qt Creator和Visual Studio构建Windows Phone 8.1应 ...

  10. 大数据入门第十二天——flume入门

    一.概述 1.什么是flume 官网的介绍:http://flume.apache.org/ Flume is a distributed, reliable, and available servi ...