< 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:42
Uncovered lines:15
Coverable lines:57
Total lines:141
Line coverage:73.6% (42 of 57)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MeshesInfo()0%110100%
UpdateRenderersCollection(...)0%20400%
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            {
 42824                meshRootGameObjectValue = value;
 42825                UpdateRenderersCollection();
 42826            }
 27        }
 28
 29        GameObject meshRootGameObjectValue;
 30
 31        public IShape currentShape;
 32        public Renderer[] renderers;
 33        public MeshFilter[] meshFilters;
 64434        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            {
 29946                if (meshRootGameObject == null)
 47                {
 048                    RecalculateBounds();
 049                }
 50                else
 51                {
 29952                    if (meshRootGameObject.transform.position != lastBoundsCalculationPosition)
 53                    {
 4854                        mergedBoundsValue.center += meshRootGameObject.transform.position - lastBoundsCalculationPositio
 4855                        lastBoundsCalculationPosition = meshRootGameObject.transform.position;
 56                    }
 57
 29958                    if (meshRootGameObject.transform.lossyScale != lastBoundsCalculationScale ||
 59                        meshRootGameObject.transform.rotation != lastBoundsCalculationRotation)
 2260                        RecalculateBounds();
 61                }
 62
 29963                return mergedBoundsValue;
 64            }
 065            set { mergedBoundsValue = value; }
 66        }
 67
 68        public void UpdateRenderersCollection(Renderer[] renderers, MeshFilter[] meshFilters, Animation animation = null
 69        {
 070            if (meshRootGameObjectValue != null)
 71            {
 072                this.renderers = renderers;
 073                this.meshFilters = meshFilters;
 074                this.animation = animation;
 75
 076                RecalculateBounds();
 077                OnAnyUpdated?.Invoke();
 078                OnUpdated?.Invoke();
 79            }
 080        }
 81
 82        public void UpdateRenderersCollection()
 83        {
 104784            if (meshRootGameObjectValue == null)
 23785                return;
 86
 81087            renderers = meshRootGameObjectValue.GetComponentsInChildren<Renderer>(true);
 81088            meshFilters = meshRootGameObjectValue.GetComponentsInChildren<MeshFilter>(true);
 81089            animation = meshRootGameObjectValue.GetComponentInChildren<Animation>();
 90
 81091            TextMeshPro[] tmpros = meshRootGameObjectValue.GetComponentsInChildren<TextMeshPro>(true);
 81092            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
 81098            RecalculateBounds();
 81099            OnAnyUpdated?.Invoke();
 810100            OnUpdated?.Invoke();
 775101        }
 102
 103        public void RecalculateBounds()
 104        {
 832105            if ((renderers == null || renderers.Length == 0) && colliders.Count == 0)
 106            {
 295107                mergedBoundsValue = new Bounds();
 295108                return;
 109            }
 110
 537111            lastBoundsCalculationPosition = meshRootGameObjectValue.transform.position;
 537112            lastBoundsCalculationScale = meshRootGameObjectValue.transform.lossyScale;
 537113            lastBoundsCalculationRotation = meshRootGameObjectValue.transform.rotation;
 114
 537115            mergedBoundsValue = MeshesInfoUtils.BuildMergedBounds(renderers, colliders);
 537116        }
 117
 118        public void CleanReferences()
 119        {
 246120            OnCleanup?.Invoke();
 246121            meshRootGameObjectValue = null;
 246122            currentShape = null;
 246123            renderers = null;
 246124            colliders.Clear();
 246125        }
 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}