< Summary

Class:DCL.ECSComponents.ECSPlaneShapeComponentHandler
Assembly:DCL.ECSComponents.PlaneShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/PlaneShape/Handler/ECSPlaneShapeComponentHandler.cs
Covered lines:41
Uncovered lines:6
Coverable lines:47
Total lines:96
Line coverage:87.2% (41 of 47)
Covered branches:0
Total branches:0

Metrics

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

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/PlaneShape/Handler/ECSPlaneShapeComponentHandler.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 ECSPlaneShapeComponentHandler : IECSComponentHandler<PBPlaneShape>
 10    {
 11        internal AssetPromise_PrimitiveMesh primitiveMeshPromisePrimitive;
 12        internal MeshesInfo meshesInfo;
 13        internal Rendereable rendereable;
 14        internal PBPlaneShape lastModel;
 15
 16        private readonly DataStore_ECS7 dataStore;
 17        private readonly IInternalECSComponent<InternalTexturizable> texturizableInternalComponent;
 18
 619        public ECSPlaneShapeComponentHandler(DataStore_ECS7 dataStore, IInternalECSComponent<InternalTexturizable> textu
 20        {
 621            this.dataStore = dataStore;
 622            this.texturizableInternalComponent = texturizableInternalComponent;
 623        }
 24
 025        public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) { }
 26
 27        public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity)
 28        {
 1029            if (primitiveMeshPromisePrimitive != null)
 830                AssetPromiseKeeper_PrimitiveMesh.i.Forget(primitiveMeshPromisePrimitive);
 1031            DisposeMesh(entity, scene);
 1032        }
 33
 34        public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBPlaneShape model)
 35        {
 636            if (lastModel != null && lastModel.Uvs.Equals(model.Uvs))
 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.Plane);
 647                primitiveMeshModelModel.uvs = model.Uvs;
 48
 649                primitiveMeshPromisePrimitive = new AssetPromise_PrimitiveMesh(primitiveMeshModelModel);
 650                primitiveMeshPromisePrimitive.OnSuccessEvent += shape =>
 51                {
 652                    DisposeMesh(entity,scene);
 653                    generatedMesh = shape.mesh;
 654                    GenerateRenderer(generatedMesh, scene, entity, model);
 655                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 656                    dataStore.AddShapeReady(entity.entityId,meshesInfo.meshRootGameObject);
 657                };
 658                primitiveMeshPromisePrimitive.OnFailEvent += ( mesh,  exception) =>
 59                {
 060                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 061                };
 62
 663                dataStore.AddPendingResource(scene.sceneData.id, model);
 664                AssetPromiseKeeper_PrimitiveMesh.i.Keep(primitiveMeshPromisePrimitive);
 65            }
 66
 667            lastModel = model;
 668        }
 69
 70        private void GenerateRenderer(Mesh mesh, IParcelScene scene, IDCLEntity entity, PBPlaneShape model)
 71        {
 672            meshesInfo = ECSComponentsUtils.GeneratePrimitive(entity, mesh, entity.gameObject, model.GetVisible(), model
 673            texturizableInternalComponent.AddRenderers(scene, entity, meshesInfo?.renderers);
 74
 75            // Note: We should add the rendereable to the data store and dispose when it not longer exists
 676            rendereable = ECSComponentsUtils.AddRendereableToDataStore(scene.sceneData.id, entity.entityId, mesh, entity
 677        }
 78
 79        internal void DisposeMesh(IDCLEntity entity, IParcelScene scene)
 80        {
 1781            if (meshesInfo != null)
 82            {
 483                texturizableInternalComponent.RemoveRenderers(scene, entity, meshesInfo?.renderers);
 484                dataStore.RemoveShapeReady(entity.entityId);
 485                ECSComponentsUtils.DisposeMeshInfo(meshesInfo);
 86            }
 1787            if(rendereable != null)
 588                ECSComponentsUtils.RemoveRendereableFromDataStore( scene.sceneData.id,rendereable);
 1789            if(lastModel != null)
 1190                dataStore.RemovePendingResource(scene.sceneData.id, lastModel);
 91
 1792            meshesInfo = null;
 1793            rendereable = null;
 1794        }
 95    }
 96}