< 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: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/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        {
 115414            public bool withCollisions = true;
 115415            public bool isPointerBlocker = true;
 115416            public bool visible = true;
 17
 018            public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 19        }
 20
 78621        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        {
 27827            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.
 27832            entity.meshesInfo.currentShape = this;
 33
 27834            base.AttachTo(entity, typeof(BaseShape));
 27835        }
 36
 37        public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null)
 38        {
 8039            if (!attachedEntities.Contains(entity))
 040                return;
 41
 42            // We do this instead of OnDetach += because it is required to run after every OnDetach listener
 8043            entity.meshesInfo.currentShape = null;
 44
 8045            base.DetachFrom(entity, typeof(BaseShape));
 46
 8047            entity.OnShapeUpdated?.Invoke(entity);
 8048        }
 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        {
 28956            if (meshGameObject == null)
 057                return;
 58
 28959            if (!shouldBeVisible)
 60            {
 2661                MaterialTransitionController[] materialTransitionControllers = meshGameObject.GetComponentsInChildren<Ma
 62
 5263                for (var i = 0; i < materialTransitionControllers.Length; i++)
 64                {
 065                    GameObject.Destroy(materialTransitionControllers[i]);
 66                }
 67            }
 68
 28969            if (meshRenderers == null)
 070                meshRenderers = meshGameObject.GetComponentsInChildren<Renderer>(true);
 71
 72            Collider onPointerEventCollider;
 73
 134274            for (var i = 0; i < meshRenderers.Length; i++)
 75            {
 38276                meshRenderers[i].enabled = shouldBeVisible;
 77
 38278                if (meshRenderers[i].transform.childCount > 0)
 79                {
 1980                    onPointerEventCollider = meshRenderers[i].transform.GetChild(0).GetComponent<Collider>();
 81
 1982                    if (onPointerEventCollider != null && onPointerEventCollider.gameObject.layer == PhysicsLayers.onPoi
 1983                        onPointerEventCollider.enabled = shouldBeVisible;
 84                }
 85            }
 28986        }
 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 */
 28094            if (model.withCollisions && !model.isPointerBlocker)
 295                return PhysicsLayers.characterOnlyLayer;
 96
 27897            return PhysicsLayers.defaultLayer;
 98        }
 99    }
 100}