本文只涉及一些案例,具体查看 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. Q矩阵输出

    程序启动时: 1.Q矩阵在InitQX中对角阵赋初值为0.25,GPS卫星数6 2.Q矩阵初值在初始化时由GetBL获得,改变Q对角阵 Q初值第0个卫星 10000000000.000 X初值第0个卫 ...

  2. spark任务调度和资源分配

    Spark调度模式 FIFO和FAIR     Spark中的调度模式主要有两种:FIFO和FAIR.    默认情况下Spark的调度模式是FIFO(先进先出),谁先提交谁先执行,后面的任务需要等待 ...

  3. 026.6 网络编程 tomcat

    ###############Tomcat中相关文件作用    bin:启动关闭服务器的脚本    Conf:配置文件    Lib:Tomcat的jar包,只要部署项目到Tomcat,所有项目可共用 ...

  4. Actor模式初步入门

    Actor模型概念 Actor模型为并行而生,简单说是未解决高并发的一种编程思路.在Actor模型中,主角是Actor,类似一种worker,Actor彼此之间直接发送消息,不需要经过什么中介,消息是 ...

  5. $Gauss$消元

    $Gauss$消元 今天金牌爷来问我一个高消的题目,我才想起来忘了学高消... 高斯消元用于解线性方程组,也就是形如: $\left\{\begin{matrix}a_{11}x_1+a_{12}x_ ...

  6. 借助强大的IDEA开发ide高效实现equals,hashcode以及toString方法

    IDEA工具提供多种生成hashCode与equals的代码方案,注意:尽量不要使用第一个方案,第一个方案对于null不做判空处理,容易NNP问题. 对于生成toString方法方案,默认使用的是+拼 ...

  7. 各种 mv power cell

    1. retention register : VDDB 是 backup power,当primary power shutoff 时 backup 会继续供电,将 reg 当前状态保存下来 2. ...

  8. JAVA框架:hibernate(四)

    一.绑定本地session 原理:之前connection实现事务一个道理,2种方法:1.变量下传.2.因为servlet是单线程,和本地当前线程绑定. 配置: 1)配置核心配置文件hibernate ...

  9. scapy学习笔记(1)

    转载请注明:小五义 http://www.cnblogs.com/xiaowuyi scapy是python写的一个功能强大的交互式数据包处理程序,可用来发送.嗅探.解析和伪造网络数据包,常常被用到网 ...

  10. 解决微云登陆出现wns login error的问题

    原文首发我的主力博客 http://anforen.com/wp/2017/04/weiyunwns_login_error/ PC版微云客户端出现登陆出现wns login error 完全退出QQ ...