< 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:29
Uncovered lines:8
Coverable lines:37
Total lines:100
Line coverage:78.3% (29 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%110100%
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        {
 113514            public bool withCollisions = true;
 113515            public bool isPointerBlocker = true;
 113516            public bool visible = true;
 17
 018            public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 19        }
 20
 75321        public BaseShape() { model = new Model(); }
 22
 723        new public Model GetModel() { return (Model) model; }
 24
 25        public override void AttachTo(IDCLEntity entity, System.Type overridenAttachedType = null)
 26        {
 26427            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.
 26432            entity.meshesInfo.currentShape = this;
 33
 26434            base.AttachTo(entity, typeof(BaseShape));
 26435        }
 36
 37        public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null)
 38        {
 20439            if (!attachedEntities.Contains(entity))
 040                return;
 41
 42            // We do this instead of OnDetach += because it is required to run after every OnDetach listener
 20443            entity.meshesInfo.currentShape = null;
 44
 20445            base.DetachFrom(entity, typeof(BaseShape));
 46
 20447            entity.OnShapeUpdated?.Invoke(entity);
 20448        }
 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        {
 30356            if (meshGameObject == null)
 057                return;
 58
 30359            if (!shouldBeVisible)
 60            {
 3861                MaterialTransitionController[] materialTransitionControllers = meshGameObject.GetComponentsInChildren<Ma
 62
 7663                for (var i = 0; i < materialTransitionControllers.Length; i++)
 64                {
 065                    Object.Destroy(materialTransitionControllers[i]);
 66                }
 67            }
 68
 30369            if (meshRenderers == null)
 070                meshRenderers = meshGameObject.GetComponentsInChildren<Renderer>(true);
 71
 72            Collider onPointerEventCollider;
 73
 142474            for (var i = 0; i < meshRenderers.Length; i++)
 75            {
 40976                meshRenderers[i].enabled = shouldBeVisible;
 77
 40978                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            }
 30386        }
 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 */
 27794            if (model.withCollisions && !model.isPointerBlocker)
 295                return PhysicsLayers.characterOnlyLayer;
 96
 27597            return PhysicsLayers.defaultLayer;
 98        }
 99    }
 100}