< 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:40
Uncovered lines:6
Coverable lines:46
Total lines:95
Line coverage:86.9% (40 of 46)
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.093078.57%
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                AssetPromise_PrimitiveMesh_Model primitiveMeshModelModel = AssetPromise_PrimitiveMesh_Model.CreateCylind
 47
 648                primitiveMeshPromisePrimitive = new AssetPromise_PrimitiveMesh(primitiveMeshModelModel);
 649                primitiveMeshPromisePrimitive.OnSuccessEvent += shape =>
 50                {
 651                    DisposeMesh(entity, scene);
 652                    generatedMesh = shape.mesh;
 653                    GenerateRenderer(generatedMesh, scene, entity, model.GetVisible(), model.GetWithCollisions(), model.
 654                    dataStore.AddShapeReady(entity.entityId,meshesInfo.meshRootGameObject);
 655                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 656                };
 657                primitiveMeshPromisePrimitive.OnFailEvent += ( mesh,  exception) =>
 58                {
 059                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 060                };
 61
 662                dataStore.AddPendingResource(scene.sceneData.id, model);
 63
 664                AssetPromiseKeeper_PrimitiveMesh.i.Keep(primitiveMeshPromisePrimitive);
 65            }
 666            lastModel = model;
 667        }
 68
 69        private void GenerateRenderer(Mesh mesh, IParcelScene scene, IDCLEntity entity, bool isVisible, bool withCollisi
 70        {
 671            meshesInfo = ECSComponentsUtils.GeneratePrimitive(entity, mesh, entity.gameObject, isVisible, withCollisions
 672            texturizableInternalComponent.AddRenderers(scene, entity, meshesInfo?.renderers);
 73
 74            // Note: We should add the rendereable to the data store and dispose when it not longer exists
 675            rendereable = ECSComponentsUtils.AddRendereableToDataStore(scene.sceneData.id, entity.entityId, mesh, entity
 676        }
 77
 78        internal void DisposeMesh(IDCLEntity entity,IParcelScene scene)
 79        {
 2180            if (meshesInfo != null)
 81            {
 482                texturizableInternalComponent.RemoveRenderers(scene, entity, meshesInfo?.renderers);
 483                dataStore.RemoveShapeReady(entity.entityId);
 484                ECSComponentsUtils.DisposeMeshInfo(meshesInfo);
 85            }
 2186            if (rendereable != null)
 587                ECSComponentsUtils.RemoveRendereableFromDataStore( scene.sceneData.id, rendereable);
 2188            if (lastModel != null)
 1189                dataStore.RemovePendingResource(scene.sceneData.id, lastModel);
 90
 2191            meshesInfo = null;
 2192            rendereable = null;
 2193        }
 94    }
 95}