< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PointerHoverResult(...)0%110100%

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        {
 220            this.entityId = entityId;
 221            this.sceneId = sceneId;
 222            this.hasValue = hasValue;
 223            this.hasFeedback = hasFeedback;
 224            this.buttonId = buttonId;
 225            this.text = text;
 226        }
 27
 28        public static PointerHoverResult empty =>
 229            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        {
 38            if (isPointerDown)
 39            {
 40                return GetPointerUpEntity(pointerUpGroup, raycastHit);
 41            }
 42            return GetPointerDownEntity(pointerDownGroup, raycastHit);
 43        }
 44
 45        private static PointerHoverResult GetPointerDownEntity(IECSReadOnlyComponentsGroup<InternalColliders, PBOnPointe
 46            RaycastHit raycastHit)
 47        {
 48            var componentGroup = pointerDownGroup.group;
 49            for (int i = 0; i < componentGroup.Count; i++)
 50            {
 51                PBOnPointerDown pointerDown = componentGroup[i].componentData2.model;
 52                IList<Collider> entityColliders = componentGroup[i].componentData1.model.colliders;
 53
 54                if (!PointerInputHelper.IsInputForEntity(raycastHit.collider, entityColliders))
 55                    continue;
 56
 57                if (!PointerInputHelper.IsValidFistanceForEntity(raycastHit.distance, pointerDown.GetMaxDistance()))
 58                    return PointerHoverResult.empty;
 59
 60                if (!pointerDown.GetShowFeedback())
 61                    return PointerHoverResult.empty;
 62
 63                return new PointerHoverResult(componentGroup[i].scene.sceneData.id, componentGroup[i].entity.entityId,
 64                    pointerDown.GetShowFeedback(), pointerDown.GetButton(), pointerDown.GetHoverText());
 65            }
 66            return PointerHoverResult.empty;
 67        }
 68
 69        private static PointerHoverResult GetPointerUpEntity(IECSReadOnlyComponentsGroup<InternalColliders, PBOnPointerU
 70            RaycastHit raycastHit)
 71        {
 72            var componentGroup = pointerUpGroup.group;
 73            for (int i = 0; i < componentGroup.Count; i++)
 74            {
 75                PBOnPointerUp pointerUp = componentGroup[i].componentData2.model;
 76                IList<Collider> entityColliders = componentGroup[i].componentData1.model.colliders;
 77
 78                if (!PointerInputHelper.IsInputForEntity(raycastHit.collider, entityColliders))
 79                    continue;
 80
 81                if (!PointerInputHelper.IsValidFistanceForEntity(raycastHit.distance, pointerUp.GetMaxDistance()))
 82                    return PointerHoverResult.empty;
 83
 84                if (!pointerUp.GetShowFeedback())
 85                    return PointerHoverResult.empty;
 86
 87                return new PointerHoverResult(componentGroup[i].scene.sceneData.id, componentGroup[i].entity.entityId,
 88                    pointerUp.GetShowFeedback(), pointerUp.GetButton(), pointerUp.GetHoverText());
 89            }
 90            return PointerHoverResult.empty;
 91        }
 92    }
 93}