< Summary

Class:BIWOutline
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/BIWOutline.cs
Covered lines:56
Uncovered lines:3
Coverable lines:59
Total lines:116
Line coverage:94.9% (56 of 59)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
OnDestroy()0%110100%
Dispose()0%440100%
Activate()0%110100%
Deactivate()0%110100%
SetOutlineMaterial(...)0%110100%
OnResize()0%2.012086.67%
OnPreviewModeChanged(...)0%2100%
Update()0%550100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/BIWOutline.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using DCL.Configuration;
 4using DCL.Helpers;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8[RequireComponent(typeof(Camera))]
 9public class BIWOutline : MonoBehaviour
 10{
 11
 12    [SerializeField] Material OutlineMaterial = null;
 13
 14    private Camera builderCamera;
 15
 16    private Camera outlineCamera;
 17    private Canvas outlineCanvas;
 18    private RawImage outlineRawImage;
 19
 20    private int lastScreenWidth = 0;
 21    private int lastScreenHeight = 0;
 22
 23    private void Awake()
 24    {
 1425        builderCamera = GetComponent<Camera>();
 26
 1427        outlineCamera = new GameObject("BuilderOutlineCamera").AddComponent<Camera>();
 1428        outlineCamera.CopyFrom(builderCamera);
 1429        outlineCamera.clearFlags = CameraClearFlags.SolidColor;
 1430        outlineCamera.backgroundColor = Color.clear;
 1431        outlineCamera.cullingMask = BIWSettings.SELECTION_LAYER;
 1432        outlineCamera.depth = builderCamera.depth - 1;
 1433        outlineCamera.transform.SetParent(builderCamera.transform);
 34
 1435        outlineCanvas = new GameObject("BuilderOutlineCanvas").AddComponent<Canvas>();
 1436        outlineCanvas.renderMode = RenderMode.ScreenSpaceCamera;
 1437        outlineCanvas.worldCamera = builderCamera;
 1438        outlineCanvas.planeDistance = 1;
 39
 1440        outlineRawImage = new GameObject("BuilderOutlineRawImage").AddComponent<RawImage>();
 1441        outlineRawImage.transform.SetParent(outlineCanvas.transform);
 1442        outlineRawImage.transform.ResetLocalTRS();
 43
 1444        outlineRawImage.rectTransform.sizeDelta = new Vector2(outlineCanvas.pixelRect.width, outlineCanvas.pixelRect.hei
 1445        outlineRawImage.raycastTarget = false;
 1446        outlineRawImage.material = OutlineMaterial;
 1447    }
 48
 2849    private void OnDestroy() { Dispose(); }
 50
 51    public void Dispose()
 52    {
 2853        if (outlineCanvas != null)
 2254            Destroy(outlineCanvas.gameObject);
 2855        if (outlineRawImage != null)
 2256            Destroy(outlineRawImage.gameObject);
 2857        if (outlineCamera != null)
 2258            Destroy(outlineCamera.gameObject);
 2859    }
 60
 61    public void Activate()
 62    {
 1563        outlineCamera.gameObject.SetActive(true);
 1564        outlineCanvas.gameObject.SetActive(true);
 1565        outlineRawImage.gameObject.SetActive(true);
 1566    }
 67
 68    public void Deactivate()
 69    {
 370        outlineCamera.gameObject.SetActive(false);
 371        outlineCanvas.gameObject.SetActive(false);
 372        outlineRawImage.gameObject.SetActive(false);
 373    }
 74
 75    public void SetOutlineMaterial(Material mat)
 76    {
 1477        OutlineMaterial = mat;
 1478        outlineRawImage.material = OutlineMaterial;
 1479    }
 80
 81    private void OnResize()
 82    {
 683        outlineRawImage.gameObject.SetActive(false); // Hack: force Unity to refresh the texture
 84
 685        RenderTexture currentRenderTexture = outlineCamera.targetTexture;
 686        if (currentRenderTexture != null)
 87        {
 088            currentRenderTexture.Release();
 089            Object.Destroy(currentRenderTexture);
 90        }
 91
 692        RenderTexture renderTexture = new RenderTexture(Screen.width, Screen.height, 24);
 693        renderTexture.antiAliasing = 4;
 694        renderTexture.depth = 16;
 695        renderTexture.autoGenerateMips = true;
 696        renderTexture.useMipMap = true;
 97
 698        outlineCamera.targetTexture = renderTexture;
 699        OutlineMaterial.mainTexture = outlineCamera.targetTexture;
 6100        outlineRawImage.rectTransform.sizeDelta = new Vector2(outlineCanvas.pixelRect.width, outlineCanvas.pixelRect.hei
 6101        outlineRawImage.gameObject.SetActive(true);
 6102    }
 103
 0104    private void OnPreviewModeChanged(bool isPreview) { outlineCanvas.gameObject.SetActive(!isPreview); }
 105
 106    private void Update()
 107    {
 6108        if ((Screen.width > 0 && Screen.height > 0) && (lastScreenWidth != Screen.width || lastScreenHeight != Screen.he
 109        {
 6110            lastScreenWidth = Screen.width;
 6111            lastScreenHeight = Screen.height;
 6112            OnResize();
 113        }
 6114    }
 115
 116}