< 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:37
Uncovered lines:5
Coverable lines:42
Total lines:113
Line coverage:88% (37 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%4.594066.67%

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            {
 30924                meshRootGameObjectValue = value;
 30925                UpdateRenderersCollection();
 30926            }
 27        }
 28
 29        GameObject meshRootGameObjectValue;
 30
 31        public IShape currentShape;
 32        public Renderer[] renderers;
 33        public MeshFilter[] meshFilters;
 034        public List<Collider> colliders = new List<Collider>();
 35
 36        Vector3 lastBoundsCalculationPosition;
 37        Vector3 lastBoundsCalculationScale;
 38        Quaternion lastBoundsCalculationRotation;
 39        Bounds mergedBoundsValue;
 40
 41        public Bounds mergedBounds
 42        {
 43            get
 44            {
 22945                if (meshRootGameObject.transform.position != lastBoundsCalculationPosition)
 46                {
 4047                    mergedBoundsValue.center += meshRootGameObject.transform.position - lastBoundsCalculationPosition;
 4048                    lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 49                }
 50
 22951                if (meshRootGameObject.transform.lossyScale != lastBoundsCalculationScale || meshRootGameObject.transfor
 652                    RecalculateBounds();
 53
 22954                return mergedBoundsValue;
 55            }
 056            set { mergedBoundsValue = value; }
 57        }
 58
 59        public void UpdateRenderersCollection()
 60        {
 73061            if (meshRootGameObjectValue != null)
 62            {
 65063                renderers = meshRootGameObjectValue.GetComponentsInChildren<Renderer>(true);
 65064                meshFilters = meshRootGameObjectValue.GetComponentsInChildren<MeshFilter>(true);
 65
 65066                TextMeshPro[] tmpros = meshRootGameObjectValue.GetComponentsInChildren<TextMeshPro>(true);
 65067                if (tmpros.Length > 0)
 68                {
 4869                    renderers = renderers.Union(tmpros.Select(x => x.renderer)).ToArray();
 4870                    meshFilters = meshFilters.Union(tmpros.Select(x => x.meshFilter)).ToArray();
 71                }
 72
 65073                RecalculateBounds();
 65074                OnAnyUpdated?.Invoke();
 65075                OnUpdated?.Invoke();
 76            }
 72577        }
 78
 79        public void RecalculateBounds()
 80        {
 65681            if (renderers == null || renderers.Length == 0)
 28382                return;
 83
 37384            lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 37385            lastBoundsCalculationScale = meshRootGameObject.transform.lossyScale;
 37386            lastBoundsCalculationRotation = meshRootGameObject.transform.rotation;
 87
 37388            mergedBoundsValue = MeshesInfoUtils.BuildMergedBounds(renderers);
 37389        }
 90
 91        public void CleanReferences()
 92        {
 8093            OnCleanup?.Invoke();
 8094            meshRootGameObjectValue = null;
 8095            currentShape = null;
 8096            renderers = null;
 8097            colliders.Clear();
 8098        }
 99
 100        public void UpdateExistingMeshAtIndex(Mesh mesh, uint meshFilterIndex = 0)
 101        {
 3102            if (meshFilters != null && meshFilters.Length > meshFilterIndex)
 103            {
 3104                meshFilters[meshFilterIndex].sharedMesh = mesh;
 3105                OnUpdated?.Invoke();
 3106            }
 107            else
 108            {
 0109                Debug.LogError($"MeshFilter index {meshFilterIndex} out of bounds - MeshesInfo.UpdateExistingMesh failed
 110            }
 0111        }
 112    }
 113}