< 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
Covered methods:4
Total methods:4
Method coverage:100% (4 of 4)

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)]
 15518    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    {
 14128        if(img.maskable)
 29        {
 14130            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    {
 29042        if(targetMat)
 43        {
 29044            SetValues();
 45        }
 46
 29047    }
 48
 49    void SetValues()
 50    {
 29051        targetMat.SetTexture("_Mask", mask);
 29052        targetMat.SetTexture("_Ramp", gradientTexture);
 29053        targetMat.SetVector("_Speed", speed);
 29054        targetMat.SetFloat("_Rotation", rotation);
 29055        targetMat.SetFloat("_Fill", fill);
 56
 29057        if (useTexture)
 58        {
 059            targetMat.SetFloat("_UseTexture", 1);
 60        }
 61        else
 62        {
 29063            targetMat.SetFloat("_UseTexture", 0);
 64        }
 65
 29066        targetMat.SetFloat("_GradientMode", ((int)rainbowType));
 29067        targetMat.SetFloat("_FillDirection", ((int)fillType));
 68
 29069        targetMat.SetFloat("_ColorAmount", gradient.colorKeys.Length);
 70
 29071        float[] tempPos01 = new float[4];
 29072        float[] tempPos02 = new float[4];
 73
 290074        for (int i = 0; i < 4; i++)
 75        {
 116076            tempPos01[i] = 1;
 116077            tempPos02[i] = 1;
 78        }
 79
 290080        for (int i = 0; i < gradient.colorKeys.Length; i++)
 81        {
 116082            targetMat.SetColor("_Color0" + (i + 1).ToString(), gradient.colorKeys[i].color);
 116083            if (i <= 3)
 84            {
 116085                tempPos01[i] = gradient.colorKeys[i].time;
 86            }
 87            else
 88            {
 089                tempPos02[i - 4] = gradient.colorKeys[i].time;
 90            }
 91        }
 29092        Vector4 pos01 = new Vector4(tempPos01[0], tempPos01[1], tempPos01[2], tempPos01[3]);
 29093        Vector4 pos02 = new Vector4(tempPos02[0], tempPos02[1], tempPos02[2], tempPos02[3]);
 94
 29095        targetMat.SetVector("_GradientPositions01", pos01);
 29096        targetMat.SetVector("_GradientPositions02", pos02);
 29097    }
 98}