< Summary

Class:DCL.ECSComponents.ECSBoxShapeComponentHandler
Assembly:DCL.ECSComponents.BoxShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/BoxShape/Handler/ECSBoxShapeComponentHandler.cs
Covered lines:44
Uncovered lines:4
Coverable lines:48
Total lines:98
Line coverage:91.6% (44 of 48)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ECSBoxShapeComponentHandler(...)0%110100%
OnComponentCreated(...)0%2100%
OnComponentRemoved(...)0%220100%
OnComponentModelUpdated(...)0%44093.33%
GenerateRenderer(...)0%330100%
DisposeMesh(...)0%660100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/BoxShape/Handler/ECSBoxShapeComponentHandler.cs

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.ECS7.InternalComponents;
 3using DCL.ECSRuntime;
 4using DCL.Models;
 5using UnityEngine;
 6
 7namespace DCL.ECSComponents
 8{
 9    public class ECSBoxShapeComponentHandler : IECSComponentHandler<PBBoxShape>
 10    {
 11        internal AssetPromise_PrimitiveMesh primitiveMeshPromisePrimitive;
 12        internal MeshesInfo meshesInfo;
 13        internal Rendereable rendereable;
 14        internal PBBoxShape lastModel;
 15
 16        private readonly DataStore_ECS7 dataStore;
 17        private readonly IInternalECSComponent<InternalTexturizable> texturizableInternalComponent;
 18
 1319        public ECSBoxShapeComponentHandler(DataStore_ECS7 dataStoreEcs7, IInternalECSComponent<InternalTexturizable> tex
 20        {
 1321            dataStore = dataStoreEcs7;
 1322            this.texturizableInternalComponent = texturizableInternalComponent;
 1323        }
 24
 025        public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) { }
 26
 27        public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity)
 28        {
 1829            if (primitiveMeshPromisePrimitive != null)
 1030                AssetPromiseKeeper_PrimitiveMesh.i.Forget(primitiveMeshPromisePrimitive);
 1831            DisposeMesh(entity, scene);
 32
 1833            lastModel = null;
 1834        }
 35
 36        public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBBoxShape model)
 37        {
 938            if (lastModel != null && lastModel.Uvs.Equals(model.Uvs))
 39            {
 140                ECSComponentsUtils.UpdateMeshInfo(model.GetVisible(), model.GetWithCollisions(), model.GetIsPointerBlock
 141            }
 42            else
 43            {
 844                Mesh generatedMesh = null;
 845                if (primitiveMeshPromisePrimitive != null)
 046                    AssetPromiseKeeper_PrimitiveMesh.i.Forget(primitiveMeshPromisePrimitive);
 47
 848                PrimitiveMeshModel primitiveMeshModelModel = new PrimitiveMeshModel(PrimitiveMeshModel.Type.Box);
 849                primitiveMeshModelModel.uvs = model.Uvs;
 50
 851                primitiveMeshPromisePrimitive = new AssetPromise_PrimitiveMesh(primitiveMeshModelModel);
 852                primitiveMeshPromisePrimitive.OnSuccessEvent += shape =>
 53                {
 854                    DisposeMesh(entity,scene);
 855                    generatedMesh = shape.mesh;
 856                    GenerateRenderer(generatedMesh, scene, entity, model.GetVisible(), model.GetWithCollisions(), model.
 857                    dataStore.AddShapeReady(entity.entityId,meshesInfo.meshRootGameObject);
 858                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 859                };
 860                primitiveMeshPromisePrimitive.OnFailEvent += ( mesh,  exception) =>
 61                {
 062                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 063                };
 64
 865                dataStore.AddPendingResource(scene.sceneData.id, model);
 866                AssetPromiseKeeper_PrimitiveMesh.i.Keep(primitiveMeshPromisePrimitive);
 67            }
 68
 969            lastModel = model;
 970        }
 71
 72        private void GenerateRenderer(Mesh mesh, IParcelScene scene, IDCLEntity entity, bool isVisible, bool withCollisi
 73        {
 874            meshesInfo = ECSComponentsUtils.GeneratePrimitive(entity, mesh, entity.gameObject, isVisible, withCollisions
 875            texturizableInternalComponent.AddRenderers(scene, entity, meshesInfo?.renderers);
 76
 77            // Note: We should add the rendereable to the data store and dispose when it not longer exists
 878            rendereable = ECSComponentsUtils.AddRendereableToDataStore(scene.sceneData.id, entity.entityId, mesh, entity
 879        }
 80
 81        internal void DisposeMesh(IDCLEntity entity,IParcelScene scene)
 82        {
 2783            if (meshesInfo != null)
 84            {
 685                texturizableInternalComponent.RemoveRenderers(scene, entity, meshesInfo?.renderers);
 686                dataStore.RemoveShapeReady(entity.entityId);
 687                ECSComponentsUtils.DisposeMeshInfo(meshesInfo);
 88            }
 2789            if(rendereable != null)
 790                ECSComponentsUtils.RemoveRendereableFromDataStore( scene.sceneData.id,rendereable);
 2791            if(lastModel != null)
 992                dataStore.RemovePendingResource(scene.sceneData.id, lastModel);
 93
 2794            meshesInfo = null;
 2795            rendereable = null;
 2796        }
 97    }
 98}