< Summary

Class:DCL.ECSComponents.ECSCylinderShapeComponentHandler
Assembly:DCL.ECSComponents.CylinderShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/CylinderShape/Handler/ECSCylinderShapeComponentHandler.cs
Covered lines:42
Uncovered lines:6
Coverable lines:48
Total lines:97
Line coverage:87.5% (42 of 48)
Covered branches:0
Total branches:0

Metrics

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

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/CylinderShape/Handler/ECSCylinderShapeComponentHandler.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 ECSCylinderShapeComponentHandler : IECSComponentHandler<PBCylinderShape>
 10    {
 11        internal AssetPromise_PrimitiveMesh primitiveMeshPromisePrimitive;
 12        internal MeshesInfo meshesInfo;
 13        internal Rendereable rendereable;
 14        internal PBCylinderShape lastModel;
 15
 16        private readonly DataStore_ECS7 dataStore;
 17        private readonly IInternalECSComponent<InternalTexturizable> texturizableInternalComponent;
 18
 1019        public ECSCylinderShapeComponentHandler(DataStore_ECS7 dataStoreEcs7, IInternalECSComponent<InternalTexturizable
 20        {
 1021            dataStore = dataStoreEcs7;
 1022            this.texturizableInternalComponent = texturizableInternalComponent;
 1023        }
 24
 025        public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) { }
 26
 27        public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity)
 28        {
 1429            if (primitiveMeshPromisePrimitive != null)
 830                AssetPromiseKeeper_PrimitiveMesh.i.Forget(primitiveMeshPromisePrimitive);
 1431            DisposeMesh(entity, scene);
 1432        }
 33
 34        public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBCylinderShape model)
 35        {
 636            if (meshesInfo != null)
 37            {
 038                ECSComponentsUtils.UpdateMeshInfo(model.GetVisible(), model.GetWithCollisions(), model.GetIsPointerBlock
 039            }
 40            else
 41            {
 642                Mesh generatedMesh = null;
 643                if (primitiveMeshPromisePrimitive != null)
 044                    AssetPromiseKeeper_PrimitiveMesh.i.Forget(primitiveMeshPromisePrimitive);
 45
 646                PrimitiveMeshModel primitiveMeshModelModel = new PrimitiveMeshModel(PrimitiveMeshModel.Type.Cylinder);
 647                primitiveMeshModelModel.radiusBottom = model.GetRadiusBottom();
 648                primitiveMeshModelModel.radiusTop = model.GetRadiusTop();
 49
 650                primitiveMeshPromisePrimitive = new AssetPromise_PrimitiveMesh(primitiveMeshModelModel);
 651                primitiveMeshPromisePrimitive.OnSuccessEvent += shape =>
 52                {
 653                    DisposeMesh(entity, scene);
 654                    generatedMesh = shape.mesh;
 655                    GenerateRenderer(generatedMesh, scene, entity, model.GetVisible(), model.GetWithCollisions(), model.
 656                    dataStore.AddShapeReady(entity.entityId,meshesInfo.meshRootGameObject);
 657                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 658                };
 659                primitiveMeshPromisePrimitive.OnFailEvent += ( mesh,  exception) =>
 60                {
 061                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 062                };
 63
 664                dataStore.AddPendingResource(scene.sceneData.id, model);
 65
 666                AssetPromiseKeeper_PrimitiveMesh.i.Keep(primitiveMeshPromisePrimitive);
 67            }
 668            lastModel = model;
 669        }
 70
 71        private void GenerateRenderer(Mesh mesh, IParcelScene scene, IDCLEntity entity, bool isVisible, bool withCollisi
 72        {
 673            meshesInfo = ECSComponentsUtils.GeneratePrimitive(entity, mesh, entity.gameObject, isVisible, withCollisions
 674            texturizableInternalComponent.AddRenderers(scene, entity, meshesInfo?.renderers);
 75
 76            // Note: We should add the rendereable to the data store and dispose when it not longer exists
 677            rendereable = ECSComponentsUtils.AddRendereableToDataStore(scene.sceneData.id, entity.entityId, mesh, entity
 678        }
 79
 80        internal void DisposeMesh(IDCLEntity entity,IParcelScene scene)
 81        {
 2182            if (meshesInfo != null)
 83            {
 484                texturizableInternalComponent.RemoveRenderers(scene, entity, meshesInfo?.renderers);
 485                dataStore.RemoveShapeReady(entity.entityId);
 486                ECSComponentsUtils.DisposeMeshInfo(meshesInfo);
 87            }
 2188            if (rendereable != null)
 589                ECSComponentsUtils.RemoveRendereableFromDataStore( scene.sceneData.id, rendereable);
 2190            if (lastModel != null)
 1191                dataStore.RemovePendingResource(scene.sceneData.id, lastModel);
 92
 2193            meshesInfo = null;
 2194            rendereable = null;
 2195        }
 96    }
 97}