| | 1 | | using System.Collections.Generic; |
| | 2 | | using DCL.ECS7.InternalComponents; |
| | 3 | | using DCL.ECSComponents; |
| | 4 | | using DCL.ECSRuntime; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace 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 | | { |
| 2 | 20 | | this.entityId = entityId; |
| 2 | 21 | | this.sceneId = sceneId; |
| 2 | 22 | | this.hasValue = hasValue; |
| 2 | 23 | | this.hasFeedback = hasFeedback; |
| 2 | 24 | | this.buttonId = buttonId; |
| 2 | 25 | | this.text = text; |
| 2 | 26 | | } |
| | 27 | |
|
| | 28 | | public static PointerHoverResult empty => |
| 2 | 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 | | { |
| | 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 | | } |