< 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:0
Coverable lines:30
Total lines:83
Line coverage:100% (30 of 30)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Model()0%110100%
GetDataFromJSON(...)0%110100%
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;
 7
 8namespace DCL
 9{
 10    public class Billboard : BaseComponent, IBillboard
 11    {
 12        [Serializable]
 13        public class Model : BaseModel
 14        {
 1715            public bool x = true;
 1716            public bool y = true;
 1717            public bool z = true;
 18
 719            public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 20        }
 21
 22
 23        private const string COMPONENT_NAME = "billboard";
 24
 8125        public Transform Tr { get; set; }
 9426        public Transform EntityTransform { get; set; }
 3527        public Vector3 LastPosition { get; set; }
 28
 29
 730        public new Model GetModel() => (Model)model;
 31
 532        public override string componentName => COMPONENT_NAME;
 33
 34
 35        public override int GetClassId()
 36        {
 137            return (int)CLASS_ID_COMPONENT.BILLBOARD;
 38        }
 39
 40        public override IEnumerator ApplyChanges(BaseModel newModel)
 41        {
 942            if (EntityTransform == null)
 43            {
 844                yield return new WaitUntil(() => entity.gameObject != null);
 445                EntityTransform = entity.gameObject.transform;
 46            }
 947        }
 48
 49
 50        public Vector3 GetLookAtVector(Vector3 cameraPosition)
 51        {
 1552            bool hasTextShape = scene.componentsManagerLegacy.HasComponent(entity, CLASS_ID_COMPONENT.TEXT_SHAPE);
 1553            Vector3 lookAtDir = hasTextShape ? (EntityTransform.position - cameraPosition) : (cameraPosition - EntityTra
 54
 1555            Model model = (Model) this.model;
 56            // Note (Zak): This check is here to avoid normalizing twice if not needed
 1557            if (!(model.x && model.y && model.z))
 58            {
 659                lookAtDir.Normalize();
 60
 61                // Note (Zak): Model x,y,z are axis that we want to enable/disable
 62                // while lookAtDir x,y,z are the components of the look-at vector
 663                if (!model.x || model.z)
 664                    lookAtDir.y = EntityTransform.forward.y;
 665                if (!model.y)
 366                    lookAtDir.x = EntityTransform.forward.x;
 67            }
 68
 1569            return lookAtDir.normalized;
 70        }
 71
 72
 73        private void Awake()
 74        {
 475            model = new Model();
 476            Tr = transform;
 477            LastPosition = Vector3.up * float.MaxValue;
 78
 479            IBillboardsController controller = Environment.i.serviceLocator.Get<IBillboardsController>();
 480            controller.BillboardAdded(this);
 481        }
 82    }
 83}