< Summary

Class:SceneEntitiesTracker
Assembly:DebugPlugins_ShapesBoundingBoxDisplayer
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/DebugPlugins/ShapesBoundingBoxDisplayer/SceneEntitiesTracker.cs
Covered lines:32
Uncovered lines:1
Coverable lines:33
Total lines:85
Line coverage:96.9% (32 of 33)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SceneEntitiesTracker()0%110100%
Dispose()0%220100%
OnEntityAdded(...)0%110100%
OnEntityRemoved(...)0%110100%
WatchEntityShape(...)0%2.062075%
KillWatchEntityShape(...)0%330100%
GetWireframeOriginal()0%220100%
DestroyWireframeOriginal()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/DebugPlugins/ShapesBoundingBoxDisplayer/SceneEntitiesTracker.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Helpers;
 4using DCL.Models;
 5using DCLPlugins.DebugPlugins.Commons;
 6using UnityEngine;
 7using Object = UnityEngine.Object;
 8
 9internal class SceneEntitiesTracker : ISceneListener
 10{
 11    internal const string WIREFRAME_GAMEOBJECT_NAME = "ShapeBoundingBoxWireframe";
 12    private const string WIREFRAME_PREFAB_NAME = "Prefabs/WireframeCubeMesh";
 13
 1014    private readonly Dictionary<IDCLEntity, WatchEntityShapeHandler> entityShapeHandler = new Dictionary<IDCLEntity, Wat
 15    private GameObject wireframeOriginal;
 16    private Material wireframeMaterial;
 17
 18    void IDisposable.Dispose()
 19    {
 4220        foreach (var handler in entityShapeHandler.Values)
 21        {
 1122            handler.Dispose();
 23        }
 24
 1025        entityShapeHandler.Clear();
 1026        DestroyWireframeOriginal();
 1027    }
 28
 29    void ISceneListener.OnEntityAdded(IDCLEntity entity)
 30    {
 1631        WatchEntityShape(entity);
 1632    }
 33
 34    void ISceneListener.OnEntityRemoved(IDCLEntity entity)
 35    {
 536        KillWatchEntityShape(entity);
 537    }
 38
 39    private void WatchEntityShape(IDCLEntity entity)
 40    {
 1641        if (entityShapeHandler.ContainsKey(entity))
 42        {
 043            return;
 44        }
 1645        entityShapeHandler.Add(entity, new WatchEntityShapeHandler(entity, new EntityWireframe(GetWireframeOriginal())))
 1646    }
 47
 48    private void KillWatchEntityShape(IDCLEntity entity)
 49    {
 550        if (entityShapeHandler.TryGetValue(entity, out WatchEntityShapeHandler entityWatchHandler))
 51        {
 552            entityWatchHandler.Dispose();
 553            entityShapeHandler.Remove(entity);
 54        }
 55
 556        if (entityShapeHandler.Count == 0)
 57        {
 258            DestroyWireframeOriginal();
 59        }
 560    }
 61
 62    private GameObject GetWireframeOriginal()
 63    {
 1664        if (wireframeOriginal != null)
 65        {
 966            return wireframeOriginal;
 67        }
 768        wireframeOriginal = Object.Instantiate(Resources.Load<GameObject>(WIREFRAME_PREFAB_NAME));
 769        wireframeOriginal.name = WIREFRAME_GAMEOBJECT_NAME;
 770        wireframeMaterial = wireframeOriginal.GetComponent<Renderer>().material;
 771        wireframeMaterial.SetColor(ShaderUtils.EmissionColor, Color.grey);
 772        wireframeOriginal.SetActive(false);
 773        return wireframeOriginal;
 74    }
 75
 76    private void DestroyWireframeOriginal()
 77    {
 1278        if (wireframeOriginal == null)
 79        {
 480            return;
 81        }
 882        Object.Destroy(wireframeOriginal);
 883        Object.Destroy(wireframeMaterial);
 884    }
 85}