< Summary

Class:DCL.Models.MeshesInfo
Assembly:MeshesInfo
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Scene/MeshesInfo/MeshesInfo.cs
Covered lines:33
Uncovered lines:9
Coverable lines:42
Total lines:114
Line coverage:78.5% (33 of 42)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MeshesInfo()0%2100%
UpdateRenderersCollection()0%770100%
RecalculateBounds()0%330100%
CleanReferences()0%220100%
UpdateExistingMeshAtIndex(...)0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Scene/MeshesInfo/MeshesInfo.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using DCL.Components;
 5using TMPro;
 6using UnityEngine;
 7
 8namespace DCL.Models
 9{
 10    [Serializable]
 11    public class MeshesInfo
 12    {
 13        public static event Action OnAnyUpdated;
 14        public event Action OnUpdated;
 15        public event Action OnCleanup;
 16
 17        public GameObject innerGameObject;
 18
 19        public GameObject meshRootGameObject
 20        {
 021            get { return meshRootGameObjectValue; }
 22            set
 23            {
 24024                meshRootGameObjectValue = value;
 25
 24026                UpdateRenderersCollection();
 24027            }
 28        }
 29
 30        GameObject meshRootGameObjectValue;
 31
 32        public IShape currentShape;
 33        public Renderer[] renderers;
 34        public MeshFilter[] meshFilters;
 035        public List<Collider> colliders = new List<Collider>();
 36
 37        Vector3 lastBoundsCalculationPosition;
 38        Vector3 lastBoundsCalculationScale;
 39        Quaternion lastBoundsCalculationRotation;
 40        Bounds mergedBoundsValue;
 41
 42        public Bounds mergedBounds
 43        {
 44            get
 45            {
 20746                if (meshRootGameObject.transform.position != lastBoundsCalculationPosition)
 47                {
 4848                    mergedBoundsValue.center += meshRootGameObject.transform.position - lastBoundsCalculationPosition;
 4849                    lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 50                }
 51
 20752                if (meshRootGameObject.transform.lossyScale != lastBoundsCalculationScale || meshRootGameObject.transfor
 953                    RecalculateBounds();
 54
 20755                return mergedBoundsValue;
 56            }
 057            set { mergedBoundsValue = value; }
 58        }
 59
 60        public void UpdateRenderersCollection()
 61        {
 76362            if (meshRootGameObjectValue != null)
 63            {
 53864                renderers = meshRootGameObjectValue.GetComponentsInChildren<Renderer>(true);
 53865                meshFilters = meshRootGameObjectValue.GetComponentsInChildren<MeshFilter>(true);
 66
 53867                TextMeshPro[] tmpros = meshRootGameObjectValue.GetComponentsInChildren<TextMeshPro>(true);
 53868                if (tmpros.Length > 0)
 69                {
 4870                    renderers = renderers.Union(tmpros.Select(x => x.renderer)).ToArray();
 4871                    meshFilters = meshFilters.Union(tmpros.Select(x => x.meshFilter)).ToArray();
 72                }
 73
 53874                RecalculateBounds();
 53875                OnAnyUpdated?.Invoke();
 53876                OnUpdated?.Invoke();
 77            }
 76378        }
 79
 80        public void RecalculateBounds()
 81        {
 54782            if (renderers == null || renderers.Length == 0)
 22483                return;
 84
 32385            lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 32386            lastBoundsCalculationScale = meshRootGameObject.transform.lossyScale;
 32387            lastBoundsCalculationRotation = meshRootGameObject.transform.rotation;
 88
 32389            mergedBoundsValue = MeshesInfoUtils.BuildMergedBounds(renderers);
 32390        }
 91
 92        public void CleanReferences()
 93        {
 23894            OnCleanup?.Invoke();
 23895            meshRootGameObjectValue = null;
 23896            currentShape = null;
 23897            renderers = null;
 23898            colliders.Clear();
 23899        }
 100
 101        public void UpdateExistingMeshAtIndex(Mesh mesh, uint meshFilterIndex = 0)
 102        {
 0103            if (meshFilters != null && meshFilters.Length > meshFilterIndex)
 104            {
 0105                meshFilters[meshFilterIndex].sharedMesh = mesh;
 0106                OnUpdated?.Invoke();
 0107            }
 108            else
 109            {
 0110                Debug.LogError($"MeshFilter index {meshFilterIndex} out of bounds - MeshesInfo.UpdateExistingMesh failed
 111            }
 0112        }
 113    }
 114}