< Summary

Class:DCL.Components.BaseShape
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/BaseShape.cs
Covered lines:28
Uncovered lines:9
Coverable lines:37
Total lines:100
Line coverage:75.6% (28 of 37)
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.769078.95%
CalculateCollidersLayer(...)0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/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        {
 100914            public bool withCollisions = true;
 100915            public bool isPointerBlocker = true;
 100916            public bool visible = true;
 17
 018            public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 19        }
 20
 67821        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        {
 23327            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.
 23332            entity.meshesInfo.currentShape = this;
 33
 23334            base.AttachTo(entity, typeof(BaseShape));
 23335        }
 36
 37        public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null)
 38        {
 22639            if (!attachedEntities.Contains(entity))
 040                return;
 41
 42            // We do this instead of OnDetach += because it is required to run after every OnDetach listener
 22643            entity.meshesInfo.currentShape = null;
 44
 22645            base.DetachFrom(entity, typeof(BaseShape));
 46
 22647            entity.OnShapeUpdated?.Invoke(entity);
 22648        }
 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, Renderer[] meshRenderers
 55        {
 25256            if (meshGameObject == null)
 057                return;
 58
 25259            if (!shouldBeVisible)
 60            {
 2261                MaterialTransitionController[] materialTransitionControllers = meshGameObject.GetComponentsInChildren<Ma
 62
 4463                for (var i = 0; i < materialTransitionControllers.Length; i++)
 64                {
 065                    GameObject.Destroy(materialTransitionControllers[i]);
 66                }
 67            }
 68
 25269            if (meshRenderers == null)
 070                meshRenderers = meshGameObject.GetComponentsInChildren<Renderer>(true);
 71
 72            Collider onPointerEventCollider;
 73
 117874            for (var i = 0; i < meshRenderers.Length; i++)
 75            {
 33776                meshRenderers[i].enabled = shouldBeVisible;
 77
 33778                if (meshRenderers[i].transform.childCount > 0)
 79                {
 1680                    onPointerEventCollider = meshRenderers[i].transform.GetChild(0).GetComponent<Collider>();
 81
 1682                    if (onPointerEventCollider != null && onPointerEventCollider.gameObject.layer == PhysicsLayers.onPoi
 1583                        onPointerEventCollider.enabled = shouldBeVisible;
 84                }
 85            }
 25286        }
 87
 88        protected int CalculateCollidersLayer(Model model)
 89        {
 90            // We can't enable this layer changer logic until we redeploy all the builder and street scenes with the cor
 91            /* if (!model.withCollisions && model.isPointerBlocker)
 92                return PhysicsLayers.onPointerEventLayer;
 93            else */
 23894            if (model.withCollisions && !model.isPointerBlocker)
 195                return PhysicsLayers.characterOnlyLayer;
 96
 23797            return PhysicsLayers.defaultLayer;
 98        }
 99    }
 100}