< 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:98
Line coverage:78.9% (30 of 38)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Model()0%110100%
GetDataFromJSON(...)0%2100%
BaseShape()0%110100%
GetModel()0%2100%
AttachTo(...)0%2.032080%
DetachFrom(...)0%3.043083.33%
IsVisible()0%2100%
HasCollisions()0%2100%
ConfigureVisibility(...)0%9.119088.89%
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;
 6
 7namespace DCL.Components
 8{
 9    public abstract class BaseShape : BaseDisposable, IShape
 10    {
 11        [System.Serializable]
 12        public class Model : BaseModel
 13        {
 123314            public bool withCollisions = true;
 123315            public bool isPointerBlocker = true;
 123316            public bool visible = true;
 17
 018            public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 19        }
 20
 82521        public BaseShape() { model = new Model(); }
 22
 023        new public Model GetModel() { return (Model) model; }
 24
 25        public override void AttachTo(IDCLEntity entity, System.Type overridenAttachedType = null)
 26        {
 28327            if (attachedEntities.Contains(entity))
 028                return;
 29
 30            //NOTE(Brian): This assignation must be before the base.AttachTo call, or the OnAttach events will receive e
 31            //             and fail to generate colliders randomly.
 28332            entity.meshesInfo.currentShape = this;
 33
 28334            base.AttachTo(entity, typeof(BaseShape));
 28335        }
 36
 37        public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null)
 38        {
 22139            if (!attachedEntities.Contains(entity))
 040                return;
 41
 42            // We do this instead of OnDetach += because it is required to run after every OnDetach listener
 22143            entity.meshesInfo.currentShape = null;
 44
 22145            base.DetachFrom(entity, typeof(BaseShape));
 46
 22147            entity.OnShapeUpdated?.Invoke(entity);
 22148        }
 49
 050        public virtual bool IsVisible() { return false; }
 51
 052        public virtual bool HasCollisions() { return false; }
 53
 54        public static void ConfigureVisibility(GameObject meshGameObject, bool shouldBeVisible, bool debug, Renderer[] m
 55        {
 29756            if (meshGameObject == null)
 057                return;
 58
 29759            if (meshRenderers == null)
 060                meshRenderers = meshGameObject.GetComponentsInChildren<Renderer>(true);
 61
 62            Collider onPointerEventCollider;
 63
 141064            for (var i = 0; i < meshRenderers.Length; i++)
 65            {
 40866                meshRenderers[i].enabled = shouldBeVisible;
 67
 40868                if (shouldBeVisible && meshRenderers[i].sharedMaterial != null)
 69                {
 36570                    MaterialTransitionController transition =  meshRenderers[i].gameObject.GetOrCreateComponent<Material
 36571                    transition.delay = 0;
 36572                    transition.useHologram = false;
 36573                    transition.OnDidFinishLoading(meshRenderers[i].sharedMaterial);
 74                }
 75
 40876                if (meshRenderers[i].transform.childCount > 0)
 77                {
 1978                    onPointerEventCollider = meshRenderers[i].transform.GetChild(0).GetComponent<Collider>();
 79
 1980                    if (onPointerEventCollider != null && onPointerEventCollider.gameObject.layer == PhysicsLayers.onPoi
 1981                        onPointerEventCollider.enabled = shouldBeVisible;
 82                }
 83            }
 29784        }
 85
 86        protected int CalculateCollidersLayer(Model model)
 87        {
 88            // We can't enable this layer changer logic until we redeploy all the builder and street scenes with the cor
 89            /* if (!model.withCollisions && model.isPointerBlocker)
 90                return PhysicsLayers.onPointerEventLayer;
 91            else */
 28092            if (model.withCollisions && !model.isPointerBlocker)
 293                return PhysicsLayers.characterOnlyLayer;
 94
 27895            return PhysicsLayers.defaultLayer;
 96        }
 97    }
 98}