< Summary

Class:DCL.Billboard
Assembly:DCL.Components.Billboard
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Billboard/Billboard.cs
Covered lines:30
Uncovered lines:1
Coverable lines:31
Total lines:94
Line coverage:96.7% (30 of 31)
Covered branches:0
Total branches:0
Covered methods:14
Total methods:15
Method coverage:93.3% (14 of 15)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Model()0%110100%
GetDataFromJSON(...)0%110100%
GetDataFromPb(...)0%6200%
GetModel()0%110100%
GetClassId()0%110100%
ApplyChanges()0%440100%
GetLookAtVector(...)0%880100%
Awake()0%110100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections;
 3using DCL.Components;
 4using DCL.Helpers;
 5using DCL.Models;
 6using UnityEngine;
 7using Decentraland.Sdk.Ecs6;
 8
 9namespace DCL
 10{
 11    public class Billboard : BaseComponent, IBillboard
 12    {
 13        [Serializable]
 14        public class Model : BaseModel
 15        {
 1716            public bool x = true;
 1717            public bool y = true;
 1718            public bool z = true;
 19
 20            public override BaseModel GetDataFromJSON(string json) =>
 721                Utils.SafeFromJson<Model>(json);
 22
 23            public override BaseModel GetDataFromPb(ComponentBodyPayload pbModel) =>
 024                pbModel.PayloadCase == ComponentBodyPayload.PayloadOneofCase.Billboard
 25                    ? new Model
 26                    {
 27                        x = pbModel.Billboard.X,
 28                        y = pbModel.Billboard.Y,
 29                        z = pbModel.Billboard.Z,
 30                    }
 31                    : Utils.SafeUnimplemented<Billboard, Model>(expected: ComponentBodyPayload.PayloadOneofCase.Billboar
 32        }
 33
 34        private const string COMPONENT_NAME = "billboard";
 35
 7736        public Transform Tr { get; set; }
 8437        public Transform EntityTransform { get; set; }
 3338        public Vector3 LastPosition { get; set; }
 39
 40
 741        public new Model GetModel() => (Model)model;
 42
 543        public override string componentName => COMPONENT_NAME;
 44
 45
 46        public override int GetClassId()
 47        {
 148            return (int)CLASS_ID_COMPONENT.BILLBOARD;
 49        }
 50
 51        public override IEnumerator ApplyChanges(BaseModel newModel)
 52        {
 953            if (EntityTransform == null)
 54            {
 855                yield return new WaitUntil(() => entity.gameObject != null);
 456                EntityTransform = entity.gameObject.transform;
 57            }
 958        }
 59
 60
 61        public Vector3 GetLookAtVector(Vector3 cameraPosition)
 62        {
 1363            bool hasTextShape = scene.componentsManagerLegacy.HasComponent(entity, CLASS_ID_COMPONENT.TEXT_SHAPE);
 1364            Vector3 lookAtDir = hasTextShape ? (EntityTransform.position - cameraPosition) : (cameraPosition - EntityTra
 65
 1366            Model model = (Model) this.model;
 67            // Note (Zak): This check is here to avoid normalizing twice if not needed
 1368            if (!(model.x && model.y && model.z))
 69            {
 470                lookAtDir.Normalize();
 71
 72                // Note (Zak): Model x,y,z are axis that we want to enable/disable
 73                // while lookAtDir x,y,z are the components of the look-at vector
 474                if (!model.x || model.z)
 475                    lookAtDir.y = EntityTransform.forward.y;
 476                if (!model.y)
 177                    lookAtDir.x = EntityTransform.forward.x;
 78            }
 79
 1380            return lookAtDir.normalized;
 81        }
 82
 83
 84        private void Awake()
 85        {
 486            model = new Model();
 487            Tr = transform;
 488            LastPosition = Vector3.up * float.MaxValue;
 89
 490            IBillboardsController controller = Environment.i.serviceLocator.Get<IBillboardsController>();
 491            controller.BillboardAdded(this);
 492        }
 93    }
 94}