< 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            {
 24324                meshRootGameObjectValue = value;
 24325                UpdateRenderersCollection();
 24326            }
 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            {
 22645                if (meshRootGameObject.transform.position != lastBoundsCalculationPosition)
 46                {
 4447                    mergedBoundsValue.center += meshRootGameObject.transform.position - lastBoundsCalculationPosition;
 4448                    lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 49                }
 50
 22651                if (meshRootGameObject.transform.lossyScale != lastBoundsCalculationScale || meshRootGameObject.transfor
 752                    RecalculateBounds();
 53
 22654                return mergedBoundsValue;
 55            }
 056            set { mergedBoundsValue = value; }
 57        }
 58
 59        public void UpdateRenderersCollection()
 60        {
 77761            if (meshRootGameObjectValue != null)
 62            {
 55163                renderers = meshRootGameObjectValue.GetComponentsInChildren<Renderer>(true);
 55164                meshFilters = meshRootGameObjectValue.GetComponentsInChildren<MeshFilter>(true);
 65
 55166                TextMeshPro[] tmpros = meshRootGameObjectValue.GetComponentsInChildren<TextMeshPro>(true);
 55167                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
 55173                RecalculateBounds();
 55174                OnAnyUpdated?.Invoke();
 55175                OnUpdated?.Invoke();
 76            }
 77777        }
 78
 79        public void RecalculateBounds()
 80        {
 55881            if (renderers == null || renderers.Length == 0)
 22682                return;
 83
 33284            lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 33285            lastBoundsCalculationScale = meshRootGameObject.transform.lossyScale;
 33286            lastBoundsCalculationRotation = meshRootGameObject.transform.rotation;
 87
 33288            mergedBoundsValue = MeshesInfoUtils.BuildMergedBounds(renderers);
 33289        }
 90
 91        public void CleanReferences()
 92        {
 23993            OnCleanup?.Invoke();
 23994            meshRootGameObjectValue = null;
 23995            currentShape = null;
 23996            renderers = null;
 23997            colliders.Clear();
 23998        }
 99
 100        public void UpdateExistingMeshAtIndex(Mesh mesh, uint meshFilterIndex = 0)
 101        {
 1102            if (meshFilters != null && meshFilters.Length > meshFilterIndex)
 103            {
 1104                meshFilters[meshFilterIndex].sharedMesh = mesh;
 1105                OnUpdated?.Invoke();
 1106            }
 107            else
 108            {
 0109                Debug.LogError($"MeshFilter index {meshFilterIndex} out of bounds - MeshesInfo.UpdateExistingMesh failed
 110            }
 0111        }
 112    }
 113}