< Summary

Class:DCL.ECSComponents.ECSSphereShapeComponentHandler
Assembly:DCL.ECSComponents.SphereShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/SphereShape/Handler/ECSSphereShapeHandler.cs
Covered lines:34
Uncovered lines:9
Coverable lines:43
Total lines:89
Line coverage:79% (34 of 43)
Covered branches:0
Total branches:0

Metrics

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

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/SphereShape/Handler/ECSSphereShapeHandler.cs

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.ECSRuntime;
 3using DCL.Models;
 4using UnityEngine;
 5
 6namespace DCL.ECSComponents
 7{
 8    public class ECSSphereShapeComponentHandler : IECSComponentHandler<PBSphereShape>
 9    {
 10        internal AssetPromise_PrimitiveMesh primitiveMeshPromisePrimitive;
 11        internal MeshesInfo meshesInfo;
 12        internal Rendereable rendereable;
 13        internal PBSphereShape lastModel;
 14
 15        private readonly DataStore_ECS7 dataStore;
 16
 017        public ECSSphereShapeComponentHandler(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        {
 1026            if (primitiveMeshPromisePrimitive != null)
 827                AssetPromiseKeeper_PrimitiveMesh.i.Forget(primitiveMeshPromisePrimitive);
 1028            DisposeMesh(entity, scene);
 1029        }
 30
 31        public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBSphereShape 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.Sphere);
 644                primitiveMeshPromisePrimitive = new AssetPromise_PrimitiveMesh(primitiveMeshModelModel);
 645                primitiveMeshPromisePrimitive.OnSuccessEvent += shape =>
 46                {
 647                    DisposeMesh(entity, scene);
 648                    generatedMesh = shape.mesh;
 649                    GenerateRenderer(generatedMesh, scene, entity, model);
 650                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 651                    dataStore.AddShapeReady(entity.entityId,meshesInfo.meshRootGameObject);
 652                };
 653                primitiveMeshPromisePrimitive.OnFailEvent += ( mesh,  exception) =>
 54                {
 055                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 056                };
 57
 658                dataStore.AddPendingResource(scene.sceneData.id, model);
 59
 660                AssetPromiseKeeper_PrimitiveMesh.i.Keep(primitiveMeshPromisePrimitive);
 61            }
 662            lastModel = model;
 663        }
 64
 65        private void GenerateRenderer(Mesh mesh, IParcelScene scene, IDCLEntity entity, PBSphereShape model)
 66        {
 667            meshesInfo = ECSComponentsUtils.GeneratePrimitive(entity, mesh, entity.gameObject, model.Visible, model.With
 68
 69            // Note: We should add the rendereable to the data store and dispose when it not longer exists
 670            rendereable = ECSComponentsUtils.AddRendereableToDataStore(scene.sceneData.id, entity.entityId, mesh, entity
 671        }
 72
 73        internal void DisposeMesh(IDCLEntity entity, IParcelScene scene)
 74        {
 1775            if (meshesInfo != null)
 76            {
 477                dataStore.RemoveShapeReady(entity.entityId);
 478                ECSComponentsUtils.DisposeMeshInfo(meshesInfo);
 79            }
 1780            if(rendereable != null)
 581                ECSComponentsUtils.RemoveRendereableFromDataStore( scene.sceneData.id,rendereable);
 1782            if (lastModel != null)
 1183                dataStore.RemovePendingResource(scene.sceneData.id, lastModel);
 84
 1785            meshesInfo = null;
 1786            rendereable = null;
 1787        }
 88    }
 89}