< 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:35
Uncovered lines:7
Coverable lines:42
Total lines:92
Line coverage:83.3% (35 of 42)
Covered branches:0
Total branches:0

Metrics

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

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/PlaneShape/Handler/ECSPlaneShapeComponentHandler.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using DCL;
 4using DCL.Controllers;
 5using DCL.ECSRuntime;
 6using DCL.Helpers;
 7using DCL.Models;
 8using UnityEngine;
 9
 10namespace DCL.ECSComponents
 11{
 12    public class ECSPlaneShapeComponentHandler : IECSComponentHandler<PBPlaneShape>
 13    {
 14        internal AssetPromise_PrimitiveMesh primitiveMeshPromisePrimitive;
 15        internal MeshesInfo meshesInfo;
 16        internal Rendereable rendereable;
 17        internal PBPlaneShape lastModel;
 18
 19        private readonly DataStore_ECS7 dataStore;
 20
 021        public ECSPlaneShapeComponentHandler(DataStore_ECS7 dataStore) { this.dataStore = dataStore;}
 22
 023        public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) { }
 24
 25        public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity)
 26        {
 1027            if (primitiveMeshPromisePrimitive != null)
 828                AssetPromiseKeeper_PrimitiveMesh.i.Forget(primitiveMeshPromisePrimitive);
 1029            DisposeMesh(entity, scene);
 1030        }
 31
 32        public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBPlaneShape model)
 33        {
 634            if (lastModel != null && lastModel.Uvs.Equals(model.Uvs))
 35            {
 036                ECSComponentsUtils.UpdateMeshInfo(model.Visible, model.WithCollisions, model.IsPointerBlocker, meshesInf
 037            }
 38            else
 39            {
 640                Mesh generatedMesh = null;
 641                if (primitiveMeshPromisePrimitive != null)
 042                    AssetPromiseKeeper_PrimitiveMesh.i.Forget(primitiveMeshPromisePrimitive);
 43
 644                PrimitiveMeshModel primitiveMeshModelModel = new PrimitiveMeshModel(PrimitiveMeshModel.Type.Plane);
 645                primitiveMeshModelModel.uvs = model.Uvs;
 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.RemovePendingResource(scene.sceneData.id, model);
 654                    dataStore.AddShapeReady(entity.entityId,meshesInfo.meshRootGameObject);
 655                };
 656                primitiveMeshPromisePrimitive.OnFailEvent += ( mesh,  exception) =>
 57                {
 058                    dataStore.RemovePendingResource(scene.sceneData.id, model);
 059                };
 60
 661                dataStore.AddPendingResource(scene.sceneData.id, model);
 662                AssetPromiseKeeper_PrimitiveMesh.i.Keep(primitiveMeshPromisePrimitive);
 63            }
 64
 665            lastModel = model;
 666        }
 67
 68        private void GenerateRenderer(Mesh mesh, IParcelScene scene, IDCLEntity entity, PBPlaneShape 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        {
 1778            if (meshesInfo != null)
 79            {
 480                dataStore.RemoveShapeReady(entity.entityId);
 481                ECSComponentsUtils.DisposeMeshInfo(meshesInfo);
 82            }
 1783            if(rendereable != null)
 584                ECSComponentsUtils.RemoveRendereableFromDataStore( scene.sceneData.id,rendereable);
 1785            if(lastModel != null)
 1186                dataStore.RemovePendingResource(scene.sceneData.id, lastModel);
 87
 1788            meshesInfo = null;
 1789            rendereable = null;
 1790        }
 91    }
 92}