< Summary

Class:RawImageFillParent
Assembly:UIHelpers
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/UIHelpers/RawImageFillParent.cs
Covered lines:13
Uncovered lines:6
Coverable lines:19
Total lines:55
Line coverage:68.4% (13 of 19)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:4
Method coverage:50% (2 of 4)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%6200%
ResizeFillParent()0%3.013090%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/UIHelpers/RawImageFillParent.cs

#LineLine coverage
 1using UnityEngine;
 2using UnityEngine.UI;
 3
 4/// <summary>
 5/// RawImage that resize itself to fill it parent while preserving it texture's aspect ratio.
 6///
 7/// Caution: This component doesn't work with UI atlases!
 8/// </summary>
 9public class RawImageFillParent : RawImage
 10{
 11    new public Texture texture
 12    {
 13        set
 14        {
 115            base.texture = value;
 16
 117            if (value != null)
 18            {
 119                ResizeFillParent();
 20            }
 121        }
 022        get { return base.texture; }
 23    }
 24
 25    protected override void Awake()
 26    {
 027        base.Awake();
 028        if (texture != null)
 29        {
 030            ResizeFillParent();
 31        }
 032    }
 33
 34    void ResizeFillParent()
 35    {
 136        if (transform.parent == null)
 37        {
 038            return;
 39        }
 40
 141        RectTransform parent = transform.parent as RectTransform;
 42
 43        float h, w;
 144        h = parent.rect.height;
 145        w = h * (base.texture.width / (float) base.texture.height);
 46
 147        if ((parent.rect.width - w) > 0)
 48        {
 149            w = parent.rect.width;
 150            h = w * (base.texture.height / (float) base.texture.width);
 51        }
 52
 153        rectTransform.sizeDelta = new Vector2(w, h);
 154    }
 55}