// Author: Daniele Giardini - http://www.demigiant.com // Created: 2018/07/13 #if false && (UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_2017_1_OR_NEWER) // MODULE_MARKER using System; using UnityEngine; using DG.Tweening.Core; using DG.Tweening.Plugins.Options; #pragma warning disable 1591 namespace DG.Tweening { public static class DOTweenModuleSprite { #region Shortcuts #region SpriteRenderer /// Tweens a SpriteRenderer's color to the given value. /// Also stores the spriteRenderer as the tween's target so it can be used for filtered operations /// The end value to reachThe duration of the tween public static TweenerCore DOColor(this SpriteRenderer target, Color endValue, float duration) { TweenerCore t = DOTween.To(() => target.color, x => target.color = x, endValue, duration); t.SetTarget(target); return t; } /// Tweens a Material's alpha color to the given value. /// Also stores the spriteRenderer as the tween's target so it can be used for filtered operations /// The end value to reachThe duration of the tween public static TweenerCore DOFade(this SpriteRenderer target, float endValue, float duration) { TweenerCore t = DOTween.ToAlpha(() => target.color, x => target.color = x, endValue, duration); t.SetTarget(target); return t; } /// Tweens a SpriteRenderer's color using the given gradient /// (NOTE 1: only uses the colors of the gradient, not the alphas - NOTE 2: creates a Sequence, not a Tweener). /// Also stores the image as the tween's target so it can be used for filtered operations /// The gradient to useThe duration of the tween public static Sequence DOGradientColor(this SpriteRenderer target, Gradient gradient, float duration) { Sequence s = DOTween.Sequence(); GradientColorKey[] colors = gradient.colorKeys; int len = colors.Length; for (int i = 0; i < len; ++i) { GradientColorKey c = colors[i]; if (i == 0 && c.time <= 0) { target.color = c.color; continue; } float colorDuration = i == len - 1 ? duration - s.Duration(false) // Verifies that total duration is correct : duration * (i == 0 ? c.time : c.time - colors[i - 1].time); s.Append(target.DOColor(c.color, colorDuration).SetEase(Ease.Linear)); } s.SetTarget(target); return s; } #endregion #region Blendables #region SpriteRenderer /// Tweens a SpriteRenderer's color to the given value, /// in a way that allows other DOBlendableColor tweens to work together on the same target, /// instead than fight each other as multiple DOColor would do. /// Also stores the SpriteRenderer as the tween's target so it can be used for filtered operations /// The value to tween toThe duration of the tween public static Tweener DOBlendableColor(this SpriteRenderer target, Color endValue, float duration) { endValue = endValue - target.color; Color to = new Color(0, 0, 0, 0); return DOTween.To(() => to, x => { Color diff = x - to; to = x; target.color += diff; }, endValue, duration) .Blendable().SetTarget(target); } #endregion #endregion #endregion } } #endif