< 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:36
Uncovered lines:9
Coverable lines:45
Total lines:92
Line coverage:80% (36 of 45)
Covered branches:0
Total branches:0

Metrics

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

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/CylinderShape/Handler/ECSCylinderShapeComponentHandler.cs

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.ECSRuntime;
 3using DCL.Models;
 4using UnityEngine;
 5
 6namespace DCL.ECSComponents
 7{
 8    public class ECSCylinderShapeComponentHandler : IECSComponentHandler<PBCylinderShape>
 9    {
 10        internal AssetPromise_PrimitiveMesh primitiveMeshPromisePrimitive;
 11        internal MeshesInfo meshesInfo;
 12        internal Rendereable rendereable;
 13        internal PBCylinderShape lastModel;
 14
 15        private readonly DataStore_ECS7 dataStore;
 16
 017        public ECSCylinderShapeComponentHandler(DataStore_ECS7 dataStoreEcs7)
 18        {
 019            dataStore = dataStoreEcs7;
 020        }
 21
 022        public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) { }
 23
 24        public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity)
 25        {
 1426            if (primitiveMeshPromisePrimitive != null)
 827                AssetPromiseKeeper_PrimitiveMesh.i.Forget(primitiveMeshPromisePrimitive);
 1428            DisposeMesh(entity, scene);
 1429        }
 30
 31        public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBCylinderShape model)
 32        {
 633            if (meshesInfo != null)
 34            {
 035                ECSComponentsUtils.UpdateMeshInfo(model.Visible, model.WithCollisions, model.IsPointerBlocker, meshesInf
 036            }
 37            else
 38            {
 639                Mesh generatedMesh = null;
 640                if (primitiveMeshPromisePrimitive != null)
 041                    AssetPromiseKeeper_PrimitiveMesh.i.Forget(primitiveMeshPromisePrimitive);
 42
 643                PrimitiveMeshModel primitiveMeshModelModel = new PrimitiveMeshModel(PrimitiveMeshModel.Type.Cylinder);
 644                primitiveMeshModelModel.radiusBottom = model.RadiusBottom;
 645                primitiveMeshModelModel.radiusTop = model.RadiusTop;
 46
 647                primitiveMeshPromisePrimitive = new AssetPromise_PrimitiveMesh(primitiveMeshModelModel);
 648                primitiveMeshPromisePrimitive.OnSuccessEvent += shape =>
 49                {
 650                    DisposeMesh(entity, scene);
 651                    generatedMesh = shape.mesh;
 652                    GenerateRenderer(generatedMesh, scene, entity, model);
 653                    dataStore.AddShapeReady(entity.entityId,meshesInfo.meshRootGameObject);
 654                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 655                };
 656                primitiveMeshPromisePrimitive.OnFailEvent += ( mesh,  exception) =>
 57                {
 058                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 059                };
 60
 661                dataStore.AddPendingResource(scene.sceneData.id, model);
 62
 663                AssetPromiseKeeper_PrimitiveMesh.i.Keep(primitiveMeshPromisePrimitive);
 64            }
 665            lastModel = model;
 666        }
 67
 68        private void GenerateRenderer(Mesh mesh, IParcelScene scene, IDCLEntity entity, PBCylinderShape model)
 69        {
 670            meshesInfo = ECSComponentsUtils.GeneratePrimitive(entity, mesh, entity.gameObject, model.Visible, model.With
 71
 72            // Note: We should add the rendereable to the data store and dispose when it not longer exists
 673            rendereable = ECSComponentsUtils.AddRendereableToDataStore(scene.sceneData.id, entity.entityId, mesh, entity
 674        }
 75
 76        internal void DisposeMesh(IDCLEntity entity,IParcelScene scene)
 77        {
 2178            if (meshesInfo != null)
 79            {
 480                dataStore.RemoveShapeReady(entity.entityId);
 481                ECSComponentsUtils.DisposeMeshInfo(meshesInfo);
 82            }
 2183            if (rendereable != null)
 584                ECSComponentsUtils.RemoveRendereableFromDataStore( scene.sceneData.id, rendereable);
 2185            if (lastModel != null)
 1186                dataStore.RemovePendingResource(scene.sceneData.id, lastModel);
 87
 2188            meshesInfo = null;
 2189            rendereable = null;
 2190        }
 91    }
 92}