< Summary

Class:UIRainbowController
Assembly:RenderingUIScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/UI/Rainbow/UIRainbowController.cs
Covered lines:30
Uncovered lines:5
Coverable lines:35
Total lines:98
Line coverage:85.7% (30 of 35)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UIRainbowController()0%110100%
Start()0%2.862040%
FixedUpdate()0%220100%
SetValues()0%5.015093.33%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/UI/Rainbow/UIRainbowController.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6public class UIRainbowController : MonoBehaviour
 7{
 8    Material targetMat;
 9    public Image img;
 10    public Texture mask;
 11    public bool useTexture;
 12    public Texture gradientTexture;
 13    public Gradient gradient;
 14    public Vector2 speed;
 15    [Range(-360, 360)]
 16    public float rotation;
 17    [Range(0,1)]
 17018    public float fill = 1f;
 19
 20    public enum rainbowT {linear, radial};
 21    public enum fillT {left, right, up, down};
 22
 23    public rainbowT rainbowType;
 24    public fillT fillType;
 25
 26    void Start()
 27    {
 15328        if(img.maskable)
 29        {
 15330            targetMat = img.materialForRendering;
 31        }
 32        else
 33        {
 034            targetMat = new Material(img.material);
 035            img.material = targetMat;
 36        }
 037    }
 38
 39
 40    void FixedUpdate()
 41    {
 37142        if(targetMat)
 43        {
 37144            SetValues();
 45        }
 46
 37147    }
 48
 49    void SetValues()
 50    {
 37151        targetMat.SetTexture("_Mask", mask);
 37152        targetMat.SetTexture("_Ramp", gradientTexture);
 37153        targetMat.SetVector("_Speed", speed);
 37154        targetMat.SetFloat("_Rotation", rotation);
 37155        targetMat.SetFloat("_Fill", fill);
 56
 37157        if (useTexture)
 58        {
 059            targetMat.SetFloat("_UseTexture", 1);
 60        }
 61        else
 62        {
 37163            targetMat.SetFloat("_UseTexture", 0);
 64        }
 65
 37166        targetMat.SetFloat("_GradientMode", ((int)rainbowType));
 37167        targetMat.SetFloat("_FillDirection", ((int)fillType));
 68
 37169        targetMat.SetFloat("_ColorAmount", gradient.colorKeys.Length);
 70
 37171        float[] tempPos01 = new float[4];
 37172        float[] tempPos02 = new float[4];
 73
 371074        for (int i = 0; i < 4; i++)
 75        {
 148476            tempPos01[i] = 1;
 148477            tempPos02[i] = 1;
 78        }
 79
 371080        for (int i = 0; i < gradient.colorKeys.Length; i++)
 81        {
 148482            targetMat.SetColor("_Color0" + (i + 1).ToString(), gradient.colorKeys[i].color);
 148483            if (i <= 3)
 84            {
 148485                tempPos01[i] = gradient.colorKeys[i].time;
 86            }
 87            else
 88            {
 089                tempPos02[i - 4] = gradient.colorKeys[i].time;
 90            }
 91        }
 37192        Vector4 pos01 = new Vector4(tempPos01[0], tempPos01[1], tempPos01[2], tempPos01[3]);
 37193        Vector4 pos02 = new Vector4(tempPos02[0], tempPos02[1], tempPos02[2], tempPos02[3]);
 94
 37195        targetMat.SetVector("_GradientPositions01", pos01);
 37196        targetMat.SetVector("_GradientPositions02", pos02);
 37197    }
 98}