< Summary

Class:DCL.Components.BaseShape
Assembly:DCL.Components.BaseShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/BaseShape/BaseShape.cs
Covered lines:30
Uncovered lines:8
Coverable lines:38
Total lines:101
Line coverage:78.9% (30 of 38)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:11
Method coverage:63.6% (7 of 11)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Model()0%110100%
GetDataFromJSON(...)0%2100%
GetDataFromPb(...)0%2100%
BaseShape()0%110100%
GetModel()0%110100%
AttachTo(...)0%2.032080%
DetachFrom(...)0%3.043083.33%
IsVisible()0%2100%
HasCollisions()0%2100%
ConfigureVisibility(...)0%8.18088.24%
CalculateCollidersLayer(...)0%330100%

File(s)

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

#LineLine coverage
 1using DCL.Configuration;
 2using DCL.Controllers;
 3using DCL.Helpers;
 4using DCL.Models;
 5using UnityEngine;
 6using Decentraland.Sdk.Ecs6;
 7
 8namespace DCL.Components
 9{
 10    public abstract class BaseShape : BaseDisposable, IShape
 11    {
 12        [System.Serializable]
 13        public class Model : BaseModel
 14        {
 109115            public bool withCollisions = true;
 109116            public bool isPointerBlocker = true;
 109117            public bool visible = true;
 18
 19            public override BaseModel GetDataFromJSON(string json) =>
 020                Utils.SafeFromJson<Model>(json);
 21
 22            public override BaseModel GetDataFromPb(ComponentBodyPayload pbModel) =>
 023                default;
 24        }
 25
 24226        protected BaseShape()
 27        {
 24228            model = new Model();
 24229        }
 30
 31        public new Model GetModel() =>
 732            (Model) model;
 33
 34        public override void AttachTo(IDCLEntity entity, System.Type overridenAttachedType = null)
 35        {
 25536            if (attachedEntities.Contains(entity))
 037                return;
 38
 39            //NOTE(Brian): This assignation must be before the base.AttachTo call, or the OnAttach events will receive e
 40            //             and fail to generate colliders randomly.
 25541            entity.meshesInfo.currentShape = this;
 42
 25543            base.AttachTo(entity, typeof(BaseShape));
 25544        }
 45
 46        public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null)
 47        {
 19548            if (!attachedEntities.Contains(entity))
 049                return;
 50
 51            // We do this instead of OnDetach += because it is required to run after every OnDetach listener
 19552            entity.meshesInfo.currentShape = null;
 53
 19554            base.DetachFrom(entity, typeof(BaseShape));
 55
 19556            entity.OnShapeUpdated?.Invoke(entity);
 19557        }
 58
 059        public virtual bool IsVisible() { return false; }
 60
 061        public virtual bool HasCollisions() { return false; }
 62
 63        public static void ConfigureVisibility(GameObject meshGameObject, bool shouldBeVisible, Renderer[] meshRenderers
 64        {
 29765            if (meshGameObject == null)
 066                return;
 67
 29768            if (meshRenderers == null)
 069                meshRenderers = meshGameObject.GetComponentsInChildren<Renderer>(true);
 70
 135871            for (var i = 0; i < meshRenderers.Length; i++)
 72            {
 38273                if (meshRenderers[i] == null)
 74                    continue;
 75
 38276                meshRenderers[i].enabled = shouldBeVisible;
 38277                Transform meshRendererT = meshRenderers[i].transform;
 78
 80279                for (int j = 0; j < meshRendererT.transform.childCount; j++)
 80                {
 1981                    Collider onPointerEventCollider = meshRendererT.GetChild(j).GetComponent<Collider>();
 82
 1983                    if (onPointerEventCollider != null && onPointerEventCollider.gameObject.layer == PhysicsLayers.onPoi
 1984                        onPointerEventCollider.enabled = shouldBeVisible;
 85                }
 86            }
 29787        }
 88
 89        protected int CalculateCollidersLayer(Model model)
 90        {
 91            // We can't enable this layer changer logic until we redeploy all the builder and street scenes with the cor
 92            /* if (!model.withCollisions && model.isPointerBlocker)
 93                return PhysicsLayers.onPointerEventLayer;
 94            else */
 27195            if (model.withCollisions && !model.isPointerBlocker)
 296                return PhysicsLayers.characterOnlyLayer;
 97
 26998            return PhysicsLayers.defaultLayer;
 99        }
 100    }
 101}