From e676b0fc6a4c6bdb4b0f34dccd01ed923224805f Mon Sep 17 00:00:00 2001 From: Shariff Faleel Date: Tue, 5 Mar 2024 14:12:41 -0800 Subject: [PATCH] Refactor how colliders are processed in interactor.preproces step --- Runtime/Interaction/HPUIInteractor.cs | 14 +++++---- Runtime/Interaction/IHPUIInteractable.cs | 2 +- Tests/HPUIGestureLogicUnifiedTest.cs | 37 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Runtime/Interaction/HPUIInteractor.cs b/Runtime/Interaction/HPUIInteractor.cs index 8ce9d97..2edba82 100644 --- a/Runtime/Interaction/HPUIInteractor.cs +++ b/Runtime/Interaction/HPUIInteractor.cs @@ -64,8 +64,8 @@ public class HPUIInteractor: XRBaseInteractor, IHPUIInteractor private bool justStarted = false; private Vector3 lastInteractionPoint; private PhysicsScene physicsScene; - private RaycastHit[] sphereCastHits = new RaycastHit[25]; - private Collider[] overlapSphereHits = new Collider[25]; + private RaycastHit[] sphereCastHits = new RaycastHit[200]; + private Collider[] overlapSphereHits = new Collider[200]; /// protected override void Awake() @@ -130,6 +130,7 @@ public override void PreprocessInteractor(XRInteractionUpdateOrder.UpdatePhase u // If no movement is recorded. // Check if spherecast size is sufficient for proper cast, or if first frame since last frame poke position will be invalid. int numberOfOverlaps; + List colliders; if (justStarted || overlapSqrMagnitude < 0.001f) { @@ -141,6 +142,7 @@ public override void PreprocessInteractor(XRInteractionUpdateOrder.UpdatePhase u Physics.AllLayers, // FIXME: QueryTriggerInteraction should be allowed to be set in inpsector QueryTriggerInteraction.Ignore); + colliders = overlapSphereHits.ToList(); } else { @@ -154,7 +156,7 @@ public override void PreprocessInteractor(XRInteractionUpdateOrder.UpdatePhase u Physics.AllLayers, // FIXME: QueryTriggerInteraction should be allowed to be set in inpsector QueryTriggerInteraction.Ignore); - + colliders = sphereCastHits.Select(s => s.collider).ToList(); } lastInteractionPoint = pokeInteractionPoint; @@ -162,9 +164,9 @@ public override void PreprocessInteractor(XRInteractionUpdateOrder.UpdatePhase u for (var i = 0; i < numberOfOverlaps; ++i) { - if (interactionManager.TryGetInteractableForCollider(sphereCastHits[i].collider, out var interactable) && - interactable is IXRSelectInteractable selectable && - interactable is IXRHoverInteractable hoverable && hoverable.IsHoverableBy(this)) + if (interactionManager.TryGetInteractableForCollider(colliders[i], out var interactable) && + !validTargets.Contains(interactable) && + interactable is IHPUIInteractable hpuiInteractable && hpuiInteractable.IsHoverableBy(this)) { validTargets.Add(interactable); } diff --git a/Runtime/Interaction/IHPUIInteractable.cs b/Runtime/Interaction/IHPUIInteractable.cs index 2606834..588de6c 100644 --- a/Runtime/Interaction/IHPUIInteractable.cs +++ b/Runtime/Interaction/IHPUIInteractable.cs @@ -3,7 +3,7 @@ namespace ubco.ovilab.HPUI.Interaction { - public interface IHPUIInteractable : IXRInteractable, IXRSelectInteractable + public interface IHPUIInteractable : IXRSelectInteractable, IXRHoverInteractable { /// /// Lower z order will get higher priority. diff --git a/Tests/HPUIGestureLogicUnifiedTest.cs b/Tests/HPUIGestureLogicUnifiedTest.cs index 10dd56f..21e9d3f 100644 --- a/Tests/HPUIGestureLogicUnifiedTest.cs +++ b/Tests/HPUIGestureLogicUnifiedTest.cs @@ -425,6 +425,18 @@ void IHPUIInteractable.OnTap(HPUITapEventArgs args) Transform IXRInteractable.transform => throw new NotImplementedException(); + HoverEnterEvent IXRHoverInteractable.firstHoverEntered => throw new NotImplementedException(); + + HoverExitEvent IXRHoverInteractable.lastHoverExited => throw new NotImplementedException(); + + HoverEnterEvent IXRHoverInteractable.hoverEntered => throw new NotImplementedException(); + + HoverExitEvent IXRHoverInteractable.hoverExited => throw new NotImplementedException(); + + List IXRHoverInteractable.interactorsHovering => throw new NotImplementedException(); + + bool IXRHoverInteractable.isHovered => throw new NotImplementedException(); + event Action IXRInteractable.registered { add @@ -509,6 +521,31 @@ void IXRInteractable.ProcessInteractable(XRInteractionUpdateOrder.UpdatePhase up { throw new NotImplementedException(); } + + bool IXRHoverInteractable.IsHoverableBy(IXRHoverInteractor interactor) + { + throw new NotImplementedException(); + } + + void IXRHoverInteractable.OnHoverEntering(HoverEnterEventArgs args) + { + throw new NotImplementedException(); + } + + void IXRHoverInteractable.OnHoverEntered(HoverEnterEventArgs args) + { + throw new NotImplementedException(); + } + + void IXRHoverInteractable.OnHoverExiting(HoverExitEventArgs args) + { + throw new NotImplementedException(); + } + + void IXRHoverInteractable.OnHoverExited(HoverExitEventArgs args) + { + throw new NotImplementedException(); + } #endregion } }