< Summary

Class:DCL.Components.OnPointerHoverEvent
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/UUIDComponent/OnPointerHoverEvent.cs
Covered lines:25
Uncovered lines:2
Coverable lines:27
Total lines:82
Line coverage:92.5% (25 of 27)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Model()0%110100%
GetDataFromJSON(...)0%110100%
Initialize(...)0%220100%
SetHoverState(...)0%2100%
SetEventColliders(...)0%110100%
IsVisible()0%5.125083.33%
IsAtHoverDistance(...)0%110100%
ApplyChanges(...)0%220100%
OnDestroy()0%220100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections;
 3using DCL.Controllers;
 4using DCL.Helpers;
 5using DCL.Models;
 6
 7namespace DCL.Components
 8{
 9    public class OnPointerHoverEvent : UUIDComponent, IPointerEvent
 10    {
 11        [Serializable]
 12        public new class Model : UUIDComponent.Model
 13        {
 1914            public float distance = 10f;
 15
 16            public override BaseModel GetDataFromJSON(string json)
 17            {
 1918                return Utils.SafeFromJson<Model>(json);
 19            }
 20        }
 21
 22        internal OnPointerEventColliders pointerEventColliders;
 23
 24        public override void Initialize(IParcelScene scene, IDCLEntity entity)
 25        {
 1926            base.Initialize(scene, entity);
 27
 1928            if (model == null)
 1929                model = new Model();
 30
 1931            pointerEventColliders = new OnPointerEventColliders();
 1932            SetEventColliders(entity);
 33
 1934            entity.OnShapeUpdated -= SetEventColliders;
 1935            entity.OnShapeUpdated += SetEventColliders;
 1936        }
 37
 038        public virtual void SetHoverState(bool hoverState) { }
 39
 40        void SetEventColliders(IDCLEntity entity)
 41        {
 3142            pointerEventColliders.Initialize(entity);
 3143        }
 44
 45        public bool IsVisible()
 46        {
 747            if (entity == null)
 048                return false;
 49
 750            bool isVisible = false;
 51
 752            if (entity.meshesInfo != null &&
 53                entity.meshesInfo.renderers != null &&
 54                entity.meshesInfo.renderers.Length > 0)
 55            {
 756                isVisible = entity.meshesInfo.renderers[0].enabled;
 57            }
 58
 759            return isVisible;
 60        }
 61
 62        public bool IsAtHoverDistance(float distance)
 63        {
 764            Model model = this.model as Model;
 765            return distance <= model.distance;
 66        }
 67
 68        public override IEnumerator ApplyChanges(BaseModel newModel)
 69        {
 1970            this.model = newModel ?? new Model();
 1971            return null;
 72        }
 73
 74        void OnDestroy()
 75        {
 1976            if (entity != null)
 1977                entity.OnShapeUpdated -= SetEventColliders;
 78
 1979            pointerEventColliders.Dispose();
 1980        }
 81    }
 82}