< Summary

Class:DCL.Models.MeshesInfo
Assembly:MeshesInfo
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/MeshesInfo/MeshesInfo.cs
Covered lines:50
Uncovered lines:5
Coverable lines:55
Total lines:141
Line coverage:90.9% (50 of 55)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MeshesInfo()0%110100%
UpdateRenderersCollection(...)0%4.034087.5%
UpdateRenderersCollection()0%770100%
RecalculateBounds()0%440100%
CleanReferences()0%220100%
UpdateExistingMeshAtIndex(...)0%5.024060%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/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        {
 750121            get { return meshRootGameObjectValue; }
 22            set
 23            {
 46224                meshRootGameObjectValue = value;
 46225                UpdateRenderersCollection();
 46226            }
 27        }
 28
 29        GameObject meshRootGameObjectValue;
 30
 31        public IShape currentShape;
 32        public Renderer[] renderers;
 33        public MeshFilter[] meshFilters;
 67834        public HashSet<Collider> colliders = new HashSet<Collider>();
 95735        public Animation animation { get; private set; }
 36
 37        Vector3 lastBoundsCalculationPosition;
 38        Vector3 lastBoundsCalculationScale;
 39        Quaternion lastBoundsCalculationRotation;
 40        Bounds mergedBoundsValue;
 41
 42        public Bounds mergedBounds
 43        {
 44            get
 45            {
 27046                if (meshRootGameObject == null)
 47                {
 048                    RecalculateBounds();
 49                }
 50                else
 51                {
 27052                    if (meshRootGameObject.transform.position != lastBoundsCalculationPosition)
 53                    {
 4454                        mergedBoundsValue.center += meshRootGameObject.transform.position - lastBoundsCalculationPositio
 4455                        lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 56                    }
 57
 27058                    if (meshRootGameObject.transform.lossyScale != lastBoundsCalculationScale ||
 59                        meshRootGameObject.transform.rotation != lastBoundsCalculationRotation)
 2060                        RecalculateBounds();
 61                }
 62
 27063                return mergedBoundsValue;
 64            }
 065            set { mergedBoundsValue = value; }
 66        }
 67
 68        public void UpdateRenderersCollection(Renderer[] renderers, MeshFilter[] meshFilters, Animation animation = null
 69        {
 2670            if (meshRootGameObjectValue != null)
 71            {
 2672                this.renderers = renderers;
 2673                this.meshFilters = meshFilters;
 2674                this.animation = animation;
 75
 2676                RecalculateBounds();
 2677                OnAnyUpdated?.Invoke();
 2678                OnUpdated?.Invoke();
 79            }
 080        }
 81
 82        public void UpdateRenderersCollection()
 83        {
 106884            if (meshRootGameObjectValue == null)
 23185                return;
 86
 83787            renderers = meshRootGameObjectValue.GetComponentsInChildren<Renderer>(true);
 83788            meshFilters = meshRootGameObjectValue.GetComponentsInChildren<MeshFilter>(true);
 83789            animation = meshRootGameObjectValue.GetComponentInChildren<Animation>();
 90
 83791            TextMeshPro[] tmpros = meshRootGameObjectValue.GetComponentsInChildren<TextMeshPro>(true);
 83792            if (tmpros.Length > 0)
 93            {
 11294                renderers = renderers.Union(tmpros.Select(x => x.renderer)).ToArray();
 11295                meshFilters = meshFilters.Union(tmpros.Select(x => x.meshFilter)).ToArray();
 96            }
 97
 83798            RecalculateBounds();
 83799            OnAnyUpdated?.Invoke();
 837100            OnUpdated?.Invoke();
 760101        }
 102
 103        public void RecalculateBounds()
 104        {
 883105            if ((renderers == null || renderers.Length == 0) && colliders.Count == 0)
 106            {
 303107                mergedBoundsValue = new Bounds();
 303108                return;
 109            }
 110
 580111            lastBoundsCalculationPosition = meshRootGameObjectValue.transform.position;
 580112            lastBoundsCalculationScale = meshRootGameObjectValue.transform.lossyScale;
 580113            lastBoundsCalculationRotation = meshRootGameObjectValue.transform.rotation;
 114
 580115            mergedBoundsValue = MeshesInfoUtils.BuildMergedBounds(renderers, colliders);
 580116        }
 117
 118        public void CleanReferences()
 119        {
 265120            OnCleanup?.Invoke();
 265121            meshRootGameObjectValue = null;
 265122            currentShape = null;
 265123            renderers = null;
 265124            colliders.Clear();
 265125        }
 126
 127        public void UpdateExistingMeshAtIndex(Mesh mesh, uint meshFilterIndex = 0)
 128        {
 3129            if (meshFilters != null && meshFilters.Length > meshFilterIndex)
 130            {
 3131                meshFilters[meshFilterIndex].sharedMesh = mesh;
 3132                OnUpdated?.Invoke();
 133            }
 134            else
 135            {
 0136                Debug.LogError(
 137                    $"MeshFilter index {meshFilterIndex} out of bounds - MeshesInfo.UpdateExistingMesh failed");
 138            }
 0139        }
 140    }
 141}