< 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: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
ECSPlaneShapeComponentHandler(...)0%110100%
OnComponentCreated(...)0%2100%
OnComponentRemoved(...)0%220100%
OnComponentModelUpdated(...)0%4.164078.57%
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                AssetPromise_PrimitiveMesh_Model primitiveMeshModelModel = AssetPromise_PrimitiveMesh_Model.CreatePlane(
 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);
 654                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 655                    dataStore.AddShapeReady(entity.entityId,meshesInfo.meshRootGameObject);
 656                };
 657                primitiveMeshPromisePrimitive.OnFailEvent += ( mesh,  exception) =>
 58                {
 059                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 060                };
 61
 662                dataStore.AddPendingResource(scene.sceneData.id, model);
 663                AssetPromiseKeeper_PrimitiveMesh.i.Keep(primitiveMeshPromisePrimitive);
 64            }
 65
 666            lastModel = model;
 667        }
 68
 69        private void GenerateRenderer(Mesh mesh, IParcelScene scene, IDCLEntity entity, PBPlaneShape model)
 70        {
 671            meshesInfo = ECSComponentsUtils.GeneratePrimitive(entity, mesh, entity.gameObject, model.GetVisible(), model
 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        {
 1780            if (meshesInfo != null)
 81            {
 482                texturizableInternalComponent.RemoveRenderers(scene, entity, meshesInfo?.renderers);
 483                dataStore.RemoveShapeReady(entity.entityId);
 484                ECSComponentsUtils.DisposeMeshInfo(meshesInfo);
 85            }
 1786            if(rendereable != null)
 587                ECSComponentsUtils.RemoveRendereableFromDataStore( scene.sceneData.id,rendereable);
 1788            if(lastModel != null)
 1189                dataStore.RemovePendingResource(scene.sceneData.id, lastModel);
 90
 1791            meshesInfo = null;
 1792            rendereable = null;
 1793        }
 94    }
 95}