< 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            {
 48124                meshRootGameObjectValue = value;
 48125                UpdateRenderersCollection();
 48126            }
 27        }
 28
 29        GameObject meshRootGameObjectValue;
 30
 31        public IShape currentShape;
 32        public Renderer[] renderers;
 33        public MeshFilter[] meshFilters;
 69734        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            {
 45746                if (meshRootGameObject == null)
 47                {
 048                    RecalculateBounds();
 049                }
 50                else
 51                {
 45752                    if (meshRootGameObject.transform.position != lastBoundsCalculationPosition)
 53                    {
 5054                        mergedBoundsValue.center += meshRootGameObject.transform.position - lastBoundsCalculationPositio
 5055                        lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 56                    }
 57
 45758                    if (meshRootGameObject.transform.lossyScale != lastBoundsCalculationScale ||
 59                        meshRootGameObject.transform.rotation != lastBoundsCalculationRotation)
 3260                        RecalculateBounds();
 61                }
 62
 45763                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        {
 109184            if (meshRootGameObjectValue == null)
 23385                return;
 86
 85887            renderers = meshRootGameObjectValue.GetComponentsInChildren<Renderer>(true);
 85888            meshFilters = meshRootGameObjectValue.GetComponentsInChildren<MeshFilter>(true);
 85889            animation = meshRootGameObjectValue.GetComponentInChildren<Animation>();
 90
 85891            TextMeshPro[] tmpros = meshRootGameObjectValue.GetComponentsInChildren<TextMeshPro>(true);
 85892            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
 85898            RecalculateBounds();
 85899            OnAnyUpdated?.Invoke();
 858100            OnUpdated?.Invoke();
 781101        }
 102
 103        public void RecalculateBounds()
 104        {
 916105            if ((renderers == null || renderers.Length == 0) && colliders.Count == 0)
 106            {
 305107                mergedBoundsValue = new Bounds();
 305108                return;
 109            }
 110
 611111            lastBoundsCalculationPosition = meshRootGameObjectValue.transform.position;
 611112            lastBoundsCalculationScale = meshRootGameObjectValue.transform.lossyScale;
 611113            lastBoundsCalculationRotation = meshRootGameObjectValue.transform.rotation;
 114
 611115            mergedBoundsValue = MeshesInfoUtils.BuildMergedBounds(renderers, colliders);
 611116        }
 117
 118        public void CleanReferences()
 119        {
 267120            OnCleanup?.Invoke();
 267121            meshRootGameObjectValue = null;
 267122            currentShape = null;
 267123            renderers = null;
 267124            colliders.Clear();
 267125        }
 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}