您的位置:首页 > 移动开发 > Unity3D

Unity常用插件Dotween(四)

2017-06-28 21:55 399 查看
看demo场景时看漏了一个,其实这才是第三个场景。

这个场景叫做material,展示了对材质的操作。

先看看场景中操作的对象



没有albedo贴图,颜色是黑色(albedo控制物体表面的颜色,和透明度)。有emission贴图,颜色是白色(emission就是自发光效果)。

这个场景中的示例代码,演示了对材质,主颜色的操作,自发光颜色的操作,和贴图offset的操作

// NOTE: all tweens will be created in a paused state, so they can be toggled via the UI

// Store the material, since we will tween that
Material mat = target.GetComponent<Renderer>().material;

// COLOR
colorTween = mat.DOColor(toColor, 1).SetLoops(-1, LoopType.Yoyo).Pause();

// EMISSION
// Note that the float value you see in Unity's inspector, next to the emission's color,
// doesn't really exist in the shader (it's generated by Unity's inspector and applied to the material's color),
// se we have to tween the full _EmissionColor.
emissionTween = mat.DOColor(new Color(0, 0, 0, 0), "_EmissionColor", 1).SetLoops(-1, LoopType.Yoyo).Pause();

// OFFSET
// In this case we set the loop to Incremental and the ease to Linear, because it's cooler
offsetTween = mat.DOOffset(new Vector2(1, 1), 1).SetEase(Ease.Linear).SetLoops(-1, LoopType.Incremental).Pause();

创建tween时的.Pause()使tween创建后并不执行,而需要通过ui来执行和停止。
colorTween.TogglePause();

TogglePause可以切换动画的播放与暂停
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: