< Summary

Class:ECSComponentsUtils
Assembly:ECSComponents.Utils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/Utils/ECSComponentsUtils.cs
Covered lines:8
Uncovered lines:32
Coverable lines:40
Total lines:117
Line coverage:20% (8 of 40)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
RemoveMaterialTransition(...)0%6200%
UpdateMeshInfo(...)0%6200%
UpdateMeshInfoColliders(...)0%30500%
RemoveRendereableFromDataStore(...)0%110100%
AddRendereableToDataStore(...)0%110100%
DisposeMeshInfo(...)0%30500%
CalculateNFTCollidersLayer(...)0%12300%
CalculateCollidersLayer(...)0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/Utils/ECSComponentsUtils.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using DCL;
 4using DCL.Configuration;
 5using DCL.ECSComponents;
 6using DCL.Helpers;
 7using DCL.Models;
 8using UnityEngine;
 9
 10public static class ECSComponentsUtils
 11{
 12    public static void RemoveMaterialTransition(GameObject go)
 13    {
 014        MaterialTransitionController[] materialTransitionControllers = go.GetComponentsInChildren<MaterialTransitionCont
 15
 016        for (var i = 0; i < materialTransitionControllers.Length; i++)
 17        {
 018            GameObject.Destroy(materialTransitionControllers[i]);
 19        }
 020    }
 21
 22    public static void UpdateMeshInfo(bool isVisible, bool withCollisions, bool isPointerBlocker, MeshesInfo meshesInfo)
 23    {
 024        foreach (Renderer renderer in meshesInfo.renderers)
 25        {
 026            renderer.enabled = isVisible;
 27        }
 28
 029        UpdateMeshInfoColliders(withCollisions, isPointerBlocker, meshesInfo);
 030    }
 31
 32    public static void UpdateMeshInfoColliders(bool withCollisions, bool isPointerBlocker, MeshesInfo meshesInfo)
 33    {
 034        int colliderLayer = isPointerBlocker ? PhysicsLayers.onPointerEventLayer : PhysicsLayers.defaultLayer;
 35
 036        foreach (Collider collider in meshesInfo.colliders)
 37        {
 038            if (collider == null) continue;
 39
 040            collider.enabled = withCollisions;
 041            collider.gameObject.layer = colliderLayer;
 42        }
 043    }
 44
 45    public static void RemoveRendereableFromDataStore(string sceneId, Rendereable rendereable)
 46    {
 147        DataStore.i.sceneWorldObjects.RemoveRendereable(sceneId, rendereable);
 148    }
 49
 50    public static Rendereable AddRendereableToDataStore(string sceneId, long entityId, Mesh mesh, GameObject gameObject,
 51    {
 252        int triangleCount = mesh.triangles.Length;
 53
 254        var newRendereable =
 55            new Rendereable()
 56            {
 57                container = gameObject,
 58                totalTriangleCount = triangleCount,
 59                meshes = new HashSet<Mesh>() { mesh },
 60                meshToTriangleCount = new Dictionary<Mesh, int>() { { mesh, triangleCount } }
 61            };
 62
 263        newRendereable.renderers = new HashSet<Renderer>(renderers);
 264        newRendereable.ownerId = entityId;
 65
 266        DataStore.i.sceneWorldObjects.AddRendereable(sceneId, newRendereable);
 267        return newRendereable;
 68    }
 69
 70    public static void DisposeMeshInfo(MeshesInfo meshesInfo)
 71    {
 72        // Dispose renderer
 073        foreach (Renderer renderer in meshesInfo.renderers)
 74        {
 075            Utils.CleanMaterials(renderer);
 076            GameObject.Destroy(renderer);
 77        }
 78
 79        // Dispose Mesh filter
 080        foreach (MeshFilter meshFilter in meshesInfo.meshFilters)
 81        {
 082            GameObject.Destroy(meshFilter);
 83        }
 84
 85        // Dispose collider
 086        foreach (Collider collider in meshesInfo.colliders)
 87        {
 088            if (collider == null) continue;
 89
 090            GameObject.Destroy(collider);
 91        }
 92
 093        meshesInfo.CleanReferences();
 094    }
 95
 96    public static int CalculateNFTCollidersLayer(bool withCollisions, bool isPointerBlocker)
 97    {
 98        // We can't enable this layer changer logic until we redeploy all the builder and street scenes with the correct
 99        /* if (!model.withCollisions && model.isPointerBlocker)
 100            return PhysicsLayers.onPointerEventLayer;
 101        else */
 0102        if (withCollisions && !isPointerBlocker)
 0103            return PhysicsLayers.characterOnlyLayer;
 104
 0105        return PhysicsLayers.defaultLayer;
 106    }
 107
 108    private static int CalculateCollidersLayer(bool withCollisions, bool isPointerBlocker)
 109    {
 0110        if (isPointerBlocker)
 0111            return PhysicsLayers.onPointerEventLayer;
 0112        else if (withCollisions)
 0113            return PhysicsLayers.characterOnlyLayer;
 114
 0115        return PhysicsLayers.defaultLayer;
 116    }
 117}