コード例 #1
0
        public static Sequence DOGradientColor(this Material target, Gradient gradient, string property, float duration)
        {
            Sequence t = DOTween.Sequence();

            GradientColorKey[] colorKeys = gradient.colorKeys;
            int length = colorKeys.Length;

            for (int i = 0; i < length; i++)
            {
                GradientColorKey key = colorKeys[i];
                if ((i == 0) && (key.time <= 0f))
                {
                    target.color = key.color;
                }
                else
                {
                    float num3 = (i == (length - 1)) ? (duration - t.Duration(false)) : (duration * ((i == 0) ? key.time : (key.time - colorKeys[i - 1].time)));
                    t.Append(target.DOColor(key.color, property, num3).SetEase <Tweener>(Ease.Linear));
                }
            }
            return(t);
        }
コード例 #2
0
        /// <summary>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</summary>
        /// <par name="gradient">The gradient to use</par><par name="duration">The duration of the tween</par>
        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));
            }
            return(s);
        }
コード例 #3
0
        /// <summary>
        ///     Tweens a Material's named color property 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
        /// </summary>
        /// <param name="gradient">The gradient to use</param>
        /// <param name="property">The name of the material property to tween (like _Tint or _SpecColor)</param>
        /// <param name="duration">The duration of the tween</param>
        public static Sequence DOGradientColor(this Material target, Gradient gradient, string property, float duration)
        {
            Sequence s      = DOTween.Sequence();
            var      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.SetColor(property, 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, property, colorDuration).SetEase(Ease.Linear));
            }

            s.SetTarget(target);
            return(s);
        }
コード例 #4
0
        public static Sequence DOGradientColor(this Image target, Gradient gradient, float duration)
        {
            Sequence sequence = DOTween.Sequence();

            GradientColorKey[] colorKeys = gradient.colorKeys;
            int num = colorKeys.Length;

            for (int i = 0; i < num; i++)
            {
                GradientColorKey gradientColorKey = colorKeys[i];
                if (i == 0 && gradientColorKey.time <= 0f)
                {
                    target.color = gradientColorKey.color;
                    continue;
                }
                float duration2 = (i != num - 1) ? (duration * ((i != 0) ? (gradientColorKey.time - colorKeys[i - 1].time) : gradientColorKey.time)) : (duration - sequence.Duration(includeLoops: false));
                sequence.Append(target.DOColor(gradientColorKey.color, duration2).SetEase(Ease.Linear));
            }
            return(sequence);
        }