< Summary

Class:DG.Tweening.DOTweenModuleSprite
Assembly:PluginScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Plugins/DOTween/Modules/DOTweenModuleSprite.cs
Covered lines:0
Uncovered lines:25
Coverable lines:25
Total lines:93
Line coverage:0% (0 of 25)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DOColor(...)0%2100%
DOFade(...)0%2100%
DOGradientColor(...)0%42600%
DOBlendableColor(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Plugins/DOTween/Modules/DOTweenModuleSprite.cs

#LineLine coverage
 1// Author: Daniele Giardini - http://www.demigiant.com
 2// Created: 2018/07/13
 3
 4#if true && (UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_2017_1_OR_NEWER) // MODULE_MARKER
 5using System;
 6using UnityEngine;
 7using DG.Tweening.Core;
 8using DG.Tweening.Plugins.Options;
 9
 10#pragma warning disable 1591
 11namespace DG.Tweening
 12{
 13  public static class DOTweenModuleSprite
 14    {
 15        #region Shortcuts
 16
 17        #region SpriteRenderer
 18
 19        /// <summary>Tweens a SpriteRenderer's color to the given value.
 20        /// Also stores the spriteRenderer as the tween's target so it can be used for filtered operations</summary>
 21        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param
 22        public static TweenerCore<Color, Color, ColorOptions> DOColor(this SpriteRenderer target, Color endValue, float 
 23        {
 024            TweenerCore<Color, Color, ColorOptions> t = DOTween.To(() => target.color, x => target.color = x, endValue, 
 025            t.SetTarget(target);
 026            return t;
 27        }
 28
 29        /// <summary>Tweens a Material's alpha color to the given value.
 30        /// Also stores the spriteRenderer as the tween's target so it can be used for filtered operations</summary>
 31        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param
 32        public static TweenerCore<Color, Color, ColorOptions> DOFade(this SpriteRenderer target, float endValue, float d
 33        {
 034            TweenerCore<Color, Color, ColorOptions> t = DOTween.ToAlpha(() => target.color, x => target.color = x, endVa
 035            t.SetTarget(target);
 036            return t;
 37        }
 38
 39        /// <summary>Tweens a SpriteRenderer's color using the given gradient
 40        /// (NOTE 1: only uses the colors of the gradient, not the alphas - NOTE 2: creates a Sequence, not a Tweener).
 41        /// Also stores the image as the tween's target so it can be used for filtered operations</summary>
 42        /// <param name="gradient">The gradient to use</param><param name="duration">The duration of the tween</param>
 43        public static Sequence DOGradientColor(this SpriteRenderer target, Gradient gradient, float duration)
 44        {
 045            Sequence s = DOTween.Sequence();
 046            GradientColorKey[] colors = gradient.colorKeys;
 047            int len = colors.Length;
 048            for (int i = 0; i < len; ++i) {
 049                GradientColorKey c = colors[i];
 050                if (i == 0 && c.time <= 0) {
 051                    target.color = c.color;
 052                    continue;
 53                }
 054                float colorDuration = i == len - 1
 55                    ? duration - s.Duration(false) // Verifies that total duration is correct
 56                    : duration * (i == 0 ? c.time : c.time - colors[i - 1].time);
 057                s.Append(target.DOColor(c.color, colorDuration).SetEase(Ease.Linear));
 58            }
 059            s.SetTarget(target);
 060            return s;
 61        }
 62
 63        #endregion
 64
 65        #region Blendables
 66
 67        #region SpriteRenderer
 68
 69        /// <summary>Tweens a SpriteRenderer's color to the given value,
 70        /// in a way that allows other DOBlendableColor tweens to work together on the same target,
 71        /// instead than fight each other as multiple DOColor would do.
 72        /// Also stores the SpriteRenderer as the tween's target so it can be used for filtered operations</summary>
 73        /// <param name="endValue">The value to tween to</param><param name="duration">The duration of the tween</param>
 74        public static Tweener DOBlendableColor(this SpriteRenderer target, Color endValue, float duration)
 75        {
 076            endValue = endValue - target.color;
 077            Color to = new Color(0, 0, 0, 0);
 078            return DOTween.To(() => to, x => {
 079                    Color diff = x - to;
 080                    to = x;
 081                    target.color += diff;
 082                }, endValue, duration)
 83                .Blendable().SetTarget(target);
 84        }
 85
 86        #endregion
 87
 88        #endregion
 89
 90        #endregion
 91  }
 92}
 93#endif