< 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)]
 17118    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    {
 38542        if(targetMat)
 43        {
 38544            SetValues();
 45        }
 46
 38547    }
 48
 49    void SetValues()
 50    {
 38551        targetMat.SetTexture("_Mask", mask);
 38552        targetMat.SetTexture("_Ramp", gradientTexture);
 38553        targetMat.SetVector("_Speed", speed);
 38554        targetMat.SetFloat("_Rotation", rotation);
 38555        targetMat.SetFloat("_Fill", fill);
 56
 38557        if (useTexture)
 58        {
 059            targetMat.SetFloat("_UseTexture", 1);
 60        }
 61        else
 62        {
 38563            targetMat.SetFloat("_UseTexture", 0);
 64        }
 65
 38566        targetMat.SetFloat("_GradientMode", ((int)rainbowType));
 38567        targetMat.SetFloat("_FillDirection", ((int)fillType));
 68
 38569        targetMat.SetFloat("_ColorAmount", gradient.colorKeys.Length);
 70
 38571        float[] tempPos01 = new float[4];
 38572        float[] tempPos02 = new float[4];
 73
 385074        for (int i = 0; i < 4; i++)
 75        {
 154076            tempPos01[i] = 1;
 154077            tempPos02[i] = 1;
 78        }
 79
 385080        for (int i = 0; i < gradient.colorKeys.Length; i++)
 81        {
 154082            targetMat.SetColor("_Color0" + (i + 1).ToString(), gradient.colorKeys[i].color);
 154083            if (i <= 3)
 84            {
 154085                tempPos01[i] = gradient.colorKeys[i].time;
 86            }
 87            else
 88            {
 089                tempPos02[i - 4] = gradient.colorKeys[i].time;
 90            }
 91        }
 38592        Vector4 pos01 = new Vector4(tempPos01[0], tempPos01[1], tempPos01[2], tempPos01[3]);
 38593        Vector4 pos02 = new Vector4(tempPos02[0], tempPos02[1], tempPos02[2], tempPos02[3]);
 94
 38595        targetMat.SetVector("_GradientPositions01", pos01);
 38596        targetMat.SetVector("_GradientPositions02", pos02);
 38597    }
 98}