< 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            {
 21524                meshRootGameObjectValue = value;
 25
 21526                UpdateRenderersCollection();
 21527            }
 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            {
 13346                if (meshRootGameObject.transform.position != lastBoundsCalculationPosition)
 47                {
 3948                    mergedBoundsValue.center += meshRootGameObject.transform.position - lastBoundsCalculationPosition;
 3949                    lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 50                }
 51
 13352                if (meshRootGameObject.transform.lossyScale != lastBoundsCalculationScale || meshRootGameObject.transfor
 653                    RecalculateBounds();
 54
 13355                return mergedBoundsValue;
 56            }
 057            set { mergedBoundsValue = value; }
 58        }
 59
 60        public void UpdateRenderersCollection()
 61        {
 67762            if (meshRootGameObjectValue != null)
 63            {
 47764                renderers = meshRootGameObjectValue.GetComponentsInChildren<Renderer>(true);
 47765                meshFilters = meshRootGameObjectValue.GetComponentsInChildren<MeshFilter>(true);
 66
 47767                TextMeshPro[] tmpros = meshRootGameObjectValue.GetComponentsInChildren<TextMeshPro>(true);
 47768                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
 47774                RecalculateBounds();
 47775                OnAnyUpdated?.Invoke();
 47776                OnUpdated?.Invoke();
 77            }
 67778        }
 79
 80        public void RecalculateBounds()
 81        {
 48382            if (renderers == null || renderers.Length == 0)
 20683                return;
 84
 27785            lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 27786            lastBoundsCalculationScale = meshRootGameObject.transform.lossyScale;
 27787            lastBoundsCalculationRotation = meshRootGameObject.transform.rotation;
 88
 27789            mergedBoundsValue = MeshesInfoUtils.BuildMergedBounds(renderers);
 27790        }
 91
 92        public void CleanReferences()
 93        {
 20694            OnCleanup?.Invoke();
 20695            meshRootGameObjectValue = null;
 20696            currentShape = null;
 20697            renderers = null;
 20698            colliders.Clear();
 20699        }
 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}