< Summary

Class:ECSSystems.PointerInputSystem.PointerHoverProcessor
Assembly:ECS7Plugin.Systems.PointerInput
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Systems/PointerInputSystem/PointerHoverProcessor.cs
Covered lines:0
Uncovered lines:25
Coverable lines:25
Total lines:93
Line coverage:0% (0 of 25)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ProcessPointerHover(...)0%6200%
GetPointerDownEntity(...)0%30500%
GetPointerUpEntity(...)0%30500%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Systems/PointerInputSystem/PointerHoverProcessor.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using DCL.ECS7.InternalComponents;
 3using DCL.ECSComponents;
 4using DCL.ECSRuntime;
 5using UnityEngine;
 6
 7namespace ECSSystems.PointerInputSystem
 8{
 9    internal readonly struct PointerHoverResult
 10    {
 11        public readonly long entityId;
 12        public readonly string sceneId;
 13        public readonly bool hasValue;
 14        public readonly bool hasFeedback;
 15        public readonly ActionButton buttonId;
 16        public readonly string text;
 17
 18        public PointerHoverResult(string sceneId, long entityId, bool hasFeedback, ActionButton buttonId, string text, b
 19        {
 20            this.entityId = entityId;
 21            this.sceneId = sceneId;
 22            this.hasValue = hasValue;
 23            this.hasFeedback = hasFeedback;
 24            this.buttonId = buttonId;
 25            this.text = text;
 26        }
 27
 28        public static PointerHoverResult empty =>
 29            new PointerHoverResult(null, -1, false, ActionButton.Any, null, false);
 30    }
 31
 32    internal static class PointerHoverProcessor
 33    {
 34        public static PointerHoverResult ProcessPointerHover(bool isPointerDown, RaycastHit raycastHit,
 35            IECSReadOnlyComponentsGroup<InternalColliders, PBOnPointerDown> pointerDownGroup,
 36            IECSReadOnlyComponentsGroup<InternalColliders, PBOnPointerUp> pointerUpGroup)
 37        {
 038            if (isPointerDown)
 39            {
 040                return GetPointerUpEntity(pointerUpGroup, raycastHit);
 41            }
 042            return GetPointerDownEntity(pointerDownGroup, raycastHit);
 43        }
 44
 45        private static PointerHoverResult GetPointerDownEntity(IECSReadOnlyComponentsGroup<InternalColliders, PBOnPointe
 46            RaycastHit raycastHit)
 47        {
 048            var componentGroup = pointerDownGroup.group;
 049            for (int i = 0; i < componentGroup.Count; i++)
 50            {
 051                PBOnPointerDown pointerDown = componentGroup[i].componentData2.model;
 052                IList<Collider> entityColliders = componentGroup[i].componentData1.model.colliders;
 53
 054                if (!PointerInputHelper.IsInputForEntity(raycastHit.collider, entityColliders))
 55                    continue;
 56
 057                if (!PointerInputHelper.IsValidFistanceForEntity(raycastHit.distance, pointerDown.GetMaxDistance()))
 058                    return PointerHoverResult.empty;
 59
 060                if (!pointerDown.GetShowFeedback())
 061                    return PointerHoverResult.empty;
 62
 063                return new PointerHoverResult(componentGroup[i].scene.sceneData.id, componentGroup[i].entity.entityId,
 64                    pointerDown.GetShowFeedback(), pointerDown.GetButton(), pointerDown.GetHoverText());
 65            }
 066            return PointerHoverResult.empty;
 67        }
 68
 69        private static PointerHoverResult GetPointerUpEntity(IECSReadOnlyComponentsGroup<InternalColliders, PBOnPointerU
 70            RaycastHit raycastHit)
 71        {
 072            var componentGroup = pointerUpGroup.group;
 073            for (int i = 0; i < componentGroup.Count; i++)
 74            {
 075                PBOnPointerUp pointerUp = componentGroup[i].componentData2.model;
 076                IList<Collider> entityColliders = componentGroup[i].componentData1.model.colliders;
 77
 078                if (!PointerInputHelper.IsInputForEntity(raycastHit.collider, entityColliders))
 79                    continue;
 80
 081                if (!PointerInputHelper.IsValidFistanceForEntity(raycastHit.distance, pointerUp.GetMaxDistance()))
 082                    return PointerHoverResult.empty;
 83
 084                if (!pointerUp.GetShowFeedback())
 085                    return PointerHoverResult.empty;
 86
 087                return new PointerHoverResult(componentGroup[i].scene.sceneData.id, componentGroup[i].entity.entityId,
 88                    pointerUp.GetShowFeedback(), pointerUp.GetButton(), pointerUp.GetHoverText());
 89            }
 090            return PointerHoverResult.empty;
 91        }
 92    }
 93}