< 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:38
Uncovered lines:7
Coverable lines:45
Total lines:94
Line coverage:84.4% (38 of 45)
Covered branches:0
Total branches:0

Metrics

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

File(s)

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

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.ECSRuntime;
 3using DCL.Models;
 4using DCL.ECSComponents;
 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
 018        public ECSBoxShapeComponentHandler(DataStore_ECS7 dataStoreEcs7)
 19        {
 020            dataStore = dataStoreEcs7;
 021        }
 22
 023        public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) { }
 24
 25        public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity)
 26        {
 1827            if (primitiveMeshPromisePrimitive != null)
 1028                AssetPromiseKeeper_PrimitiveMesh.i.Forget(primitiveMeshPromisePrimitive);
 1829            DisposeMesh(entity, scene);
 30
 1831            lastModel = null;
 1832        }
 33
 34        public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBBoxShape model)
 35        {
 936            if (lastModel != null && lastModel.Uvs.Equals(model.Uvs))
 37            {
 138                ECSComponentsUtils.UpdateMeshInfo(model.Visible, model.WithCollisions, model.IsPointerBlocker, meshesInf
 139            }
 40            else
 41            {
 842                Mesh generatedMesh = null;
 843                if (primitiveMeshPromisePrimitive != null)
 044                    AssetPromiseKeeper_PrimitiveMesh.i.Forget(primitiveMeshPromisePrimitive);
 45
 846                PrimitiveMeshModel primitiveMeshModelModel = new PrimitiveMeshModel(PrimitiveMeshModel.Type.Box);
 847                primitiveMeshModelModel.uvs = model.Uvs;
 48
 849                primitiveMeshPromisePrimitive = new AssetPromise_PrimitiveMesh(primitiveMeshModelModel);
 850                primitiveMeshPromisePrimitive.OnSuccessEvent += shape =>
 51                {
 852                    DisposeMesh(entity,scene);
 853                    generatedMesh = shape.mesh;
 854                    GenerateRenderer(generatedMesh, scene, entity, model);
 855                    dataStore.AddShapeReady(entity.entityId,meshesInfo.meshRootGameObject);
 856                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 857                };
 858                primitiveMeshPromisePrimitive.OnFailEvent += ( mesh,  exception) =>
 59                {
 060                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 061                };
 62
 863                dataStore.AddPendingResource(scene.sceneData.id, model);
 864                AssetPromiseKeeper_PrimitiveMesh.i.Keep(primitiveMeshPromisePrimitive);
 65            }
 66
 967            lastModel = model;
 968        }
 69
 70        private void GenerateRenderer(Mesh mesh, IParcelScene scene, IDCLEntity entity, PBBoxShape model)
 71        {
 872            meshesInfo = ECSComponentsUtils.GeneratePrimitive(entity, mesh, entity.gameObject, model.Visible, model.With
 73
 74            // Note: We should add the rendereable to the data store and dispose when it not longer exists
 875            rendereable = ECSComponentsUtils.AddRendereableToDataStore(scene.sceneData.id, entity.entityId, mesh, entity
 876        }
 77
 78        internal void DisposeMesh(IDCLEntity entity,IParcelScene scene)
 79        {
 2780            if (meshesInfo != null)
 81            {
 682                dataStore.RemoveShapeReady(entity.entityId);
 683                ECSComponentsUtils.DisposeMeshInfo(meshesInfo);
 84            }
 2785            if(rendereable != null)
 786                ECSComponentsUtils.RemoveRendereableFromDataStore( scene.sceneData.id,rendereable);
 2787            if(lastModel != null)
 988                dataStore.RemovePendingResource(scene.sceneData.id, lastModel);
 89
 2790            meshesInfo = null;
 2791            rendereable = null;
 2792        }
 93    }
 94}