< 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:45
Uncovered lines:7
Coverable lines:52
Total lines:131
Line coverage:86.5% (45 of 52)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MeshesInfo()0%2100%
UpdateRenderersCollection(...)0%4.034087.5%
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/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            {
 47424                meshRootGameObjectValue = value;
 47425                UpdateRenderersCollection();
 47426            }
 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>();
 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            {
 18846                if (meshRootGameObject.transform.position != lastBoundsCalculationPosition)
 47                {
 4148                    mergedBoundsValue.center += meshRootGameObject.transform.position - lastBoundsCalculationPosition;
 4149                    lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 50                }
 51
 18852                if (meshRootGameObject.transform.lossyScale != lastBoundsCalculationScale ||
 53                    meshRootGameObject.transform.rotation != lastBoundsCalculationRotation)
 454                    RecalculateBounds();
 55
 18856                return mergedBoundsValue;
 57            }
 058            set { mergedBoundsValue = value; }
 59        }
 60
 61        public void UpdateRenderersCollection(Renderer[] renderers, MeshFilter[] meshFilters, Animation animation = null
 62        {
 2663            if (meshRootGameObjectValue != null)
 64            {
 2665                this.renderers = renderers;
 2666                this.meshFilters = meshFilters;
 2667                this.animation = animation;
 68
 2669                RecalculateBounds();
 2670                OnAnyUpdated?.Invoke();
 2671                OnUpdated?.Invoke();
 72            }
 073        }
 74
 75        public void UpdateRenderersCollection()
 76        {
 108077            if (meshRootGameObjectValue != null)
 78            {
 85279                renderers = meshRootGameObjectValue.GetComponentsInChildren<Renderer>(true);
 85280                meshFilters = meshRootGameObjectValue.GetComponentsInChildren<MeshFilter>(true);
 85281                animation = meshRootGameObjectValue.GetComponentInChildren<Animation>();
 82
 85283                TextMeshPro[] tmpros = meshRootGameObjectValue.GetComponentsInChildren<TextMeshPro>(true);
 85284                if (tmpros.Length > 0)
 85                {
 11286                    renderers = renderers.Union(tmpros.Select(x => x.renderer)).ToArray();
 11287                    meshFilters = meshFilters.Union(tmpros.Select(x => x.meshFilter)).ToArray();
 88                }
 89
 85290                RecalculateBounds();
 85291                OnAnyUpdated?.Invoke();
 85292                OnUpdated?.Invoke();
 93            }
 100394        }
 95
 96        public void RecalculateBounds()
 97        {
 88298            if (renderers == null || renderers.Length == 0)
 30099                return;
 100
 582101            lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 582102            lastBoundsCalculationScale = meshRootGameObject.transform.lossyScale;
 582103            lastBoundsCalculationRotation = meshRootGameObject.transform.rotation;
 104
 582105            mergedBoundsValue = MeshesInfoUtils.BuildMergedBounds(renderers);
 582106        }
 107
 108        public void CleanReferences()
 109        {
 265110            OnCleanup?.Invoke();
 265111            meshRootGameObjectValue = null;
 265112            currentShape = null;
 265113            renderers = null;
 265114            colliders.Clear();
 265115        }
 116
 117        public void UpdateExistingMeshAtIndex(Mesh mesh, uint meshFilterIndex = 0)
 118        {
 3119            if (meshFilters != null && meshFilters.Length > meshFilterIndex)
 120            {
 3121                meshFilters[meshFilterIndex].sharedMesh = mesh;
 3122                OnUpdated?.Invoke();
 3123            }
 124            else
 125            {
 0126                Debug.LogError(
 127                    $"MeshFilter index {meshFilterIndex} out of bounds - MeshesInfo.UpdateExistingMesh failed");
 128            }
 0129        }
 130    }
 131}