< 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:49
Uncovered lines:8
Coverable lines:57
Total lines:141
Line coverage:85.9% (49 of 57)
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%4.594066.67%

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        {
 021            get { return meshRootGameObjectValue; }
 22            set
 23            {
 46524                meshRootGameObjectValue = value;
 46525                UpdateRenderersCollection();
 46526            }
 27        }
 28
 29        GameObject meshRootGameObjectValue;
 30
 31        public IShape currentShape;
 32        public Renderer[] renderers;
 33        public MeshFilter[] meshFilters;
 68134        public HashSet<Collider> colliders = new HashSet<Collider>();
 035        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            {
 28846                if (meshRootGameObject == null)
 47                {
 048                    RecalculateBounds();
 049                }
 50                else
 51                {
 28852                    if (meshRootGameObject.transform.position != lastBoundsCalculationPosition)
 53                    {
 4654                        mergedBoundsValue.center += meshRootGameObject.transform.position - lastBoundsCalculationPositio
 4655                        lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 56                    }
 57
 28858                    if (meshRootGameObject.transform.lossyScale != lastBoundsCalculationScale ||
 59                        meshRootGameObject.transform.rotation != lastBoundsCalculationRotation)
 2160                        RecalculateBounds();
 61                }
 62
 28863                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        {
 107784            if (meshRootGameObjectValue == null)
 23485                return;
 86
 84387            renderers = meshRootGameObjectValue.GetComponentsInChildren<Renderer>(true);
 84388            meshFilters = meshRootGameObjectValue.GetComponentsInChildren<MeshFilter>(true);
 84389            animation = meshRootGameObjectValue.GetComponentInChildren<Animation>();
 90
 84391            TextMeshPro[] tmpros = meshRootGameObjectValue.GetComponentsInChildren<TextMeshPro>(true);
 84392            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
 84398            RecalculateBounds();
 84399            OnAnyUpdated?.Invoke();
 843100            OnUpdated?.Invoke();
 766101        }
 102
 103        public void RecalculateBounds()
 104        {
 890105            if ((renderers == null || renderers.Length == 0) && colliders.Count == 0)
 106            {
 306107                mergedBoundsValue = new Bounds();
 306108                return;
 109            }
 110
 584111            lastBoundsCalculationPosition = meshRootGameObjectValue.transform.position;
 584112            lastBoundsCalculationScale = meshRootGameObjectValue.transform.lossyScale;
 584113            lastBoundsCalculationRotation = meshRootGameObjectValue.transform.rotation;
 114
 584115            mergedBoundsValue = MeshesInfoUtils.BuildMergedBounds(renderers, colliders);
 584116        }
 117
 118        public void CleanReferences()
 119        {
 268120            OnCleanup?.Invoke();
 268121            meshRootGameObjectValue = null;
 268122            currentShape = null;
 268123            renderers = null;
 268124            colliders.Clear();
 268125        }
 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();
 3133            }
 134            else
 135            {
 0136                Debug.LogError(
 137                    $"MeshFilter index {meshFilterIndex} out of bounds - MeshesInfo.UpdateExistingMesh failed");
 138            }
 0139        }
 140    }
 141}