< Summary

Class:DCL.Components.AvatarOnPointerDown
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/UUIDComponent/AvatarOnPointerDown.cs
Covered lines:11
Uncovered lines:41
Coverable lines:52
Total lines:124
Line coverage:21.1% (11 of 52)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetActionButton()0%2100%
SetHoverState(...)0%30500%
OnDisable()0%4.943040%
Awake()0%110100%
OnDestroy()0%220100%
Initialize(...)0%12300%
IsAtHoverDistance(...)0%2100%
IsVisible()0%2100%
ShouldReportEvent(...)0%12300%
Report(...)0%30500%
GetEventType()0%2100%
ReEnableOnInfoCardClosed(...)0%2.52050%
SetColliderEnabled(...)0%110100%
GetTransform()0%2100%
OnPoolRelease()0%2100%
OnPoolGet()0%2100%

File(s)

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

#LineLine coverage
 1using DCL.Interface;
 2using UnityEngine;
 3using DCL.Helpers;
 4using DCL.Models;
 5using Ray = UnityEngine.Ray;
 6
 7namespace DCL.Components
 8{
 9    public class AvatarOnPointerDown : MonoBehaviour, IPointerEvent, IPoolLifecycleHandler, IAvatarOnPointerDownCollider
 10    {
 11        public new Collider collider;
 12        private OnPointerEvent.Model model;
 13        private OnPointerEventHandler eventHandler;
 014        public IDCLEntity entity { get; private set; }
 15        public event System.Action OnPointerDownReport;
 16        public event System.Action OnPointerEnterReport;
 17        public event System.Action OnPointerExitReport;
 18        private bool isHovering = false;
 19
 020        public WebInterface.ACTION_BUTTON GetActionButton() { return model.GetActionButton(); }
 21
 22        public void SetHoverState(bool state)
 23        {
 024            bool isHoveringDirty = state != isHovering;
 025            isHovering = state;
 026            eventHandler.SetFeedbackState(model.showFeedback, state, model.button, model.hoverText);
 027            if (!isHoveringDirty)
 028                return;
 029            if (isHovering)
 030                OnPointerEnterReport?.Invoke();
 31            else
 032                OnPointerExitReport?.Invoke();
 033        }
 34
 35        private void OnDisable()
 36        {
 66337            if (!isHovering)
 66338                return;
 039            isHovering = false;
 040            OnPointerExitReport?.Invoke();
 041        }
 42
 132243        void Awake() { CommonScriptableObjects.playerInfoCardVisibleState.OnChange += ReEnableOnInfoCardClosed; }
 44
 45        void OnDestroy()
 46        {
 66147            CommonScriptableObjects.playerInfoCardVisibleState.OnChange -= ReEnableOnInfoCardClosed;
 66148            eventHandler?.Dispose();
 66149            CollidersManager.i.RemoveEntityCollider(entity, collider);
 66150        }
 51
 52        public void Initialize(OnPointerEvent.Model model, IDCLEntity entity)
 53        {
 054            this.model = model;
 055            this.entity = entity;
 56
 057            if (eventHandler == null)
 058                eventHandler = new OnPointerEventHandler();
 59
 060            eventHandler?.SetColliders(entity);
 061            CollidersManager.i.AddOrUpdateEntityCollider(entity, collider);
 062        }
 63
 064        public bool IsAtHoverDistance(float distance) { return distance <= model.distance; }
 65
 066        public bool IsVisible() { return true; }
 67
 68        public bool ShouldReportEvent(WebInterface.ACTION_BUTTON buttonId, HitInfo hit)
 69        {
 070            return IsAtHoverDistance(hit.distance) &&
 71                   (model.button == "ANY" || buttonId.ToString() == model.button);
 72        }
 73
 74        public void Report(WebInterface.ACTION_BUTTON buttonId, Ray ray, HitInfo hit)
 75        {
 076            if (!enabled)
 077                return;
 78
 079            if (ShouldReportEvent(buttonId, hit))
 80            {
 081                string meshName = null;
 82
 083                if (hit.collider != null)
 084                    meshName = eventHandler.GetMeshName(hit.collider);
 85
 086                WebInterface.ReportOnPointerDownEvent(
 87                    buttonId,
 88                    entity.scene.sceneData.id,
 89                    model.uuid,
 90                    entity.entityId,
 91                    meshName,
 92                    ray,
 93                    hit.point,
 94                    hit.normal,
 95                    hit.distance);
 96
 097                eventHandler.SetFeedbackState(model.showFeedback, false, model.button, model.hoverText);
 098                enabled = false;
 99
 0100                OnPointerDownReport?.Invoke();
 101            }
 0102        }
 103
 0104        public PointerEventType GetEventType() { return PointerEventType.DOWN; }
 105
 106        void ReEnableOnInfoCardClosed(bool newState, bool prevState)
 107        {
 4108            if (enabled || newState)
 4109                return;
 110
 0111            enabled = true;
 0112        }
 113        public void SetColliderEnabled(bool newEnabledState)
 114        {
 2115            collider.enabled = newEnabledState;
 2116        }
 117
 0118        public Transform GetTransform() { return transform; }
 119
 0120        public void OnPoolRelease() { eventHandler.Dispose(); }
 121
 0122        public void OnPoolGet() { }
 123    }
 124}