< Summary

Class:DCL.Components.BoxShape
Assembly:DCL.Components.ParametrizedShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/ParametrizedShapes/BoxShape.cs
Covered lines:24
Uncovered lines:12
Coverable lines:36
Total lines:96
Line coverage:66.6% (24 of 36)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:7
Method coverage:71.4% (5 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetDataFromJSON(...)0%110100%
GetDataFromPb(...)0%56700%
BoxShape()0%110100%
GetClassId()0%2100%
GenerateGeometry()0%440100%
DestroyGeometry()0%220100%
ShouldGenerateNewMesh(...)0%9.218073.33%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/ParametrizedShapes/BoxShape.cs

#LineLine coverage
 1using DCL.Helpers;
 2using DCL.Models;
 3using UnityEngine;
 4using Decentraland.Sdk.Ecs6;
 5using System.Linq;
 6
 7namespace DCL.Components
 8{
 9    public class BoxShape : ParametrizedShape<BoxShape.Model>
 10    {
 11        [System.Serializable]
 12        public new class Model : BaseShape.Model
 13        {
 14            public float[] uvs;
 15
 16            public override BaseModel GetDataFromJSON(string json) =>
 12417                Utils.SafeFromJson<Model>(json);
 18
 19            public override BaseModel GetDataFromPb(ComponentBodyPayload pbModel)
 20            {
 021                if (pbModel.PayloadCase != ComponentBodyPayload.PayloadOneofCase.BoxShape)
 022                    return Utils.SafeUnimplemented<BoxShape, Model>(expected: ComponentBodyPayload.PayloadOneofCase.BoxS
 23
 024                var pb = new Model();
 025                if (pbModel.BoxShape.HasVisible) pb.visible = pbModel.BoxShape.Visible;
 026                if (pbModel.BoxShape.HasWithCollisions) pb.withCollisions = pbModel.BoxShape.WithCollisions;
 027                if (pbModel.BoxShape.HasIsPointerBlocker) pb.isPointerBlocker = pbModel.BoxShape.IsPointerBlocker;
 028                if (pbModel.BoxShape.Uvs is { Count: > 0 }) pb.uvs = pbModel.BoxShape.Uvs.ToArray();
 29
 030                return pb;
 31            }
 32        }
 33
 31534        public BoxShape() { model = new Model(); }
 35
 36        public static Mesh cubeMesh = null;
 37        private static int cubeMeshRefCount = 0;
 38
 039        public override int GetClassId() { return (int) CLASS_ID.BOX_SHAPE; }
 40
 41        public override Mesh GenerateGeometry()
 42        {
 10643            var model = (Model) this.model;
 44
 10645            if (cubeMesh == null)
 346                cubeMesh = PrimitiveMeshBuilder.BuildCube(1f);
 47
 10648            if (model.uvs != null && model.uvs.Length > 0)
 49            {
 150                cubeMesh.uv = Utils.FloatArrayToV2List(model.uvs);
 51            }
 52
 10653            cubeMeshRefCount++;
 10654            return cubeMesh;
 55        }
 56
 57        protected override void DestroyGeometry()
 58        {
 7159            cubeMeshRefCount--;
 60
 7161            if (cubeMeshRefCount == 0)
 62            {
 263                GameObject.Destroy(cubeMesh);
 264                cubeMesh = null;
 65            }
 7166        }
 67
 68        protected override bool ShouldGenerateNewMesh(BaseShape.Model previousModel)
 69        {
 12870            if (currentMesh == null)
 10771                return true;
 72
 2173            BoxShape.Model newBoxModel = (BoxShape.Model) this.model;
 2174            BoxShape.Model oldBoxModel = (BoxShape.Model) previousModel;
 75
 2176            if (newBoxModel.uvs != null && oldBoxModel.uvs != null)
 77            {
 1478                if (newBoxModel.uvs.Length != oldBoxModel.uvs.Length)
 079                    return true;
 80
 2881                for (int i = 0; i < newBoxModel.uvs.Length; i++)
 82                {
 083                    if (newBoxModel.uvs[i] != oldBoxModel.uvs[i])
 084                        return true;
 85                }
 86            }
 87            else
 88            {
 789                if (newBoxModel.uvs != oldBoxModel.uvs)
 390                    return true;
 91            }
 92
 1893            return false;
 94        }
 95    }
 96}