From 7bce98b41494db9268bad013c0e4634597de15c2 Mon Sep 17 00:00:00 2001 From: Ahmed Shariff Date: Tue, 9 Jan 2024 20:46:42 -0800 Subject: [PATCH] Swipe now called gesture --- Editor/HPUIBaseInteractableEditor.cs | 2 +- Editor/HPUIInteractorEditor.cs | 2 +- Runtime/Interaction/HPUIBaseInteractable.cs | 18 +-- Runtime/Interaction/HPUIEvents.cs | 22 ++-- Runtime/Interaction/HPUIInteractor.cs | 10 +- Runtime/Interaction/IHPUIInteractable.cs | 6 +- Runtime/Interaction/IHPUIInteractor.cs | 4 +- .../Logic/HPUIGestureLogicDistributed.cs | 52 ++++---- .../Logic/HPUIGestureLogicUnified.cs | 58 ++++----- Tests/HPUIGestureLogicUnifiedTest.cs | 114 +++++++++--------- 10 files changed, 144 insertions(+), 144 deletions(-) diff --git a/Editor/HPUIBaseInteractableEditor.cs b/Editor/HPUIBaseInteractableEditor.cs index 5fc0029..3a7df49 100644 --- a/Editor/HPUIBaseInteractableEditor.cs +++ b/Editor/HPUIBaseInteractableEditor.cs @@ -10,7 +10,7 @@ public class HPUIBaseInteractableEditor: XRBaseInteractableEditor { private HPUIBaseInteractable t; protected List eventProperties; - protected virtual List EventPropertyNames => new List() { "tapEvent", "swipeEvent" }; + protected virtual List EventPropertyNames => new List() { "tapEvent", "gestureEvent" }; protected bool hpuiInteractablesExpanded; diff --git a/Editor/HPUIInteractorEditor.cs b/Editor/HPUIInteractorEditor.cs index 8af4924..ba793d2 100644 --- a/Editor/HPUIInteractorEditor.cs +++ b/Editor/HPUIInteractorEditor.cs @@ -10,7 +10,7 @@ public class HPUIInteractorEditor: XRBaseInteractorEditor { private HPUIInteractor t; protected List eventProperties; - protected List eventPropertyNames = new List() { "tapEvent", "swipeEvent"}; + protected List eventPropertyNames = new List() { "tapEvent", "gestureEvent"}; protected bool hpuiInteractablesExpanded; diff --git a/Runtime/Interaction/HPUIBaseInteractable.cs b/Runtime/Interaction/HPUIBaseInteractable.cs index eb10a48..044a809 100644 --- a/Runtime/Interaction/HPUIBaseInteractable.cs +++ b/Runtime/Interaction/HPUIBaseInteractable.cs @@ -40,12 +40,12 @@ public Handedness Handedness public HPUITapEvent TapEvent { get => tapEvent; set => tapEvent = value; } [SerializeField] - private HPUISwipeEvent swipeEvent = new HPUISwipeEvent(); + private HPUIGestureEvent gestureEvent = new HPUIGestureEvent(); /// - /// Event triggered on swipe + /// Event triggered on gesture /// - public HPUISwipeEvent SwipeEvent { get => swipeEvent; set => swipeEvent = value; } + public HPUIGestureEvent GestureEvent { get => gestureEvent; set => gestureEvent = value; } private Vector2 surfaceBounds, surfaceOrigin; @@ -127,20 +127,20 @@ public void OnTap(HPUITapEventArgs args) } /// - public void OnSwipe(HPUISwipeEventArgs args) + public void OnGesture(HPUIGestureEventArgs args) { - swipeEvent?.Invoke(args); + gestureEvent?.Invoke(args); } /// - public bool HandlesGestureState(HPUIGestureState state) + public bool HandlesGesture(HPUIGesture state) { switch (state) { - case HPUIGestureState.Tap: { + case HPUIGesture.Tap: { return TapEvent.GetPersistentEventCount() > 0; } - case HPUIGestureState.Swipe: { - return SwipeEvent.GetPersistentEventCount() > 0; + case HPUIGesture.Gesture: { + return GestureEvent.GetPersistentEventCount() > 0; } default: throw new InvalidOperationException($"Gesture state {state} is not handled by {typeof(HPUIBaseInteractable)}"); diff --git a/Runtime/Interaction/HPUIEvents.cs b/Runtime/Interaction/HPUIEvents.cs index 0cdc7fb..cccb864 100644 --- a/Runtime/Interaction/HPUIEvents.cs +++ b/Runtime/Interaction/HPUIEvents.cs @@ -5,26 +5,26 @@ namespace ubco.ovilab.HPUI.Interaction { - public enum HPUIGestureState + public enum HPUIGesture { None, - Tap, Swipe, + Tap, Gesture, Custom // TODO: Custom gestures? } - public enum HPUISwipeState + public enum HPUIGestureState { Started, Updated, Stopped, Invalid } #region events classes - public class HPUIGestureEvent: UnityEvent + public class HPUIInteractionEvent: UnityEvent {} /// /// Event data associated with an gesture interaction on HPUI /// - public class HPUIGestureEventArgs: BaseInteractionEventArgs + public class HPUIInteractionEventArgs: BaseInteractionEventArgs { /// /// The Interactor associated with the interaction event. @@ -58,19 +58,19 @@ public class HPUITapEvent: UnityEvent /// /// Event data associated with an tap gesture interaction on HPUI /// - public class HPUITapEventArgs: HPUIGestureEventArgs + public class HPUITapEventArgs: HPUIInteractionEventArgs {} [Serializable] - public class HPUISwipeEvent: UnityEvent + public class HPUIGestureEvent: UnityEvent {} /// - /// Event data associated with an swipe gesture interaction on HPUI + /// Event data associated with a gesture interaction on HPUI /// - public class HPUISwipeEventArgs: HPUIGestureEventArgs + public class HPUIGestureEventArgs: HPUIInteractionEventArgs { - public HPUISwipeState State { get; private set; } + public HPUIGestureState State { get; private set; } public float TimeDelta { get; private set; } public float StartTime { get; private set; } public Vector2 StartPosition { get; private set; } @@ -83,7 +83,7 @@ public override void SetParams(IHPUIInteractor interactor, IHPUIInteractable int throw new InvalidOperationException("Call overloaded method!"); } - public void SetParams(IHPUIInteractor interactor, IHPUIInteractable interactable, HPUISwipeState state, float timeDelta, float startTime, + public void SetParams(IHPUIInteractor interactor, IHPUIInteractable interactable, HPUIGestureState state, float timeDelta, float startTime, Vector2 startPosition, Vector2 cumilativeDirection, float cumilativeDistance, Vector2 deltaDirection) { base.SetParams(interactor, interactable); diff --git a/Runtime/Interaction/HPUIInteractor.cs b/Runtime/Interaction/HPUIInteractor.cs index a617042..8f6fd6c 100644 --- a/Runtime/Interaction/HPUIInteractor.cs +++ b/Runtime/Interaction/HPUIInteractor.cs @@ -35,12 +35,12 @@ public class HPUIInteractor: XRPokeInteractor, IHPUIInteractor public HPUITapEvent TapEvent { get => tapEvent; set => tapEvent = value; } [SerializeField] - private HPUISwipeEvent swipeEvent = new HPUISwipeEvent(); + private HPUIGestureEvent gestureEvent = new HPUIGestureEvent(); /// - /// Event triggered on swipe + /// Event triggered on gesture /// - public HPUISwipeEvent SwipeEvent { get => swipeEvent; set => swipeEvent = value; } + public HPUIGestureEvent GestureEvent { get => gestureEvent; set => gestureEvent = value; } protected IHPUIGestureLogic gestureLogic; private List validTargets = new List(); @@ -116,9 +116,9 @@ public void OnTap(HPUITapEventArgs args) } /// - public void OnSwipe(HPUISwipeEventArgs args) + public void OnGesture(HPUIGestureEventArgs args) { - swipeEvent?.Invoke(args); + gestureEvent?.Invoke(args); } #endregion } diff --git a/Runtime/Interaction/IHPUIInteractable.cs b/Runtime/Interaction/IHPUIInteractable.cs index 63fff44..26644b7 100644 --- a/Runtime/Interaction/IHPUIInteractable.cs +++ b/Runtime/Interaction/IHPUIInteractable.cs @@ -27,12 +27,12 @@ public interface IHPUIInteractable : IXRInteractable, IXRSelectInteractable /// happens while this interactable is selected, it'll be passed to /// the next selected interactable in the priority list. /// - bool HandlesGestureState(HPUIGestureState state); + bool HandlesGesture(HPUIGesture gesture); /// - /// This is called when a swipe event occurs on the interactable. + /// This is called when a gesture event occurs on the interactable. /// - void OnSwipe(HPUISwipeEventArgs args); + void OnGesture(HPUIGestureEventArgs args); } } diff --git a/Runtime/Interaction/IHPUIInteractor.cs b/Runtime/Interaction/IHPUIInteractor.cs index 7a5cefc..57e97d4 100644 --- a/Runtime/Interaction/IHPUIInteractor.cs +++ b/Runtime/Interaction/IHPUIInteractor.cs @@ -10,9 +10,9 @@ public interface IHPUIInteractor: IXRInteractor, IXRSelectInteractor void OnTap(HPUITapEventArgs args); /// - /// This is called when a swipe event occurs on the interactable. + /// This is called when a gesture event occurs on the interactable. /// - void OnSwipe(HPUISwipeEventArgs args); + void OnGesture(HPUIGestureEventArgs args); } } diff --git a/Runtime/Interaction/Logic/HPUIGestureLogicDistributed.cs b/Runtime/Interaction/Logic/HPUIGestureLogicDistributed.cs index cafe829..500dfdc 100644 --- a/Runtime/Interaction/Logic/HPUIGestureLogicDistributed.cs +++ b/Runtime/Interaction/Logic/HPUIGestureLogicDistributed.cs @@ -15,7 +15,7 @@ public class HPUIGestureLogicDistributed: IHPUIGestureLogic private float previousTime; private LinkedPool hpuiTapEventArgsPool = new LinkedPool(() => new HPUITapEventArgs()); - private LinkedPool hpuiSwipeEventArgsPool = new LinkedPool(() => new HPUISwipeEventArgs()); + private LinkedPool hpuiGestureEventArgsPool = new LinkedPool(() => new HPUIGestureEventArgs()); private float tapTimeThreshold, tapDistanceThreshold; private IHPUIInteractor interactor; @@ -41,7 +41,7 @@ public void OnSelectEntering(IHPUIInteractable interactable) } HPUIInteractionState state = GenericPool.Get(); - state.SetParams(HPUIGestureState.Tap, + state.SetParams(HPUIGesture.Tap, Time.time, interactable.ComputeInteractorPostion(interactor)); states.Add(interactable, state); @@ -61,7 +61,7 @@ public void OnSelectExiting(IHPUIInteractable interactable) { switch (state.gestureState) { - case HPUIGestureState.Tap: + case HPUIGesture.Tap: using (hpuiTapEventArgsPool.Get(out HPUITapEventArgs tapEventArgs)) { tapEventArgs.SetParams(interactor, interactable); @@ -69,14 +69,14 @@ public void OnSelectExiting(IHPUIInteractable interactable) interactor.OnTap(tapEventArgs); } break; - case HPUIGestureState.Swipe: - using (hpuiSwipeEventArgsPool.Get(out HPUISwipeEventArgs swipeEventArgs)) + case HPUIGesture.Gesture: + using (hpuiGestureEventArgsPool.Get(out HPUIGestureEventArgs gestureEventArgs)) { - swipeEventArgs.SetParams(interactor, interactable, - HPUISwipeState.Stopped, Time.time - state.startTime, state.startTime, state.startPosition, + gestureEventArgs.SetParams(interactor, interactable, + HPUIGestureState.Stopped, Time.time - state.startTime, state.startTime, state.startPosition, state.cumilativeDirection, state.cumilativeDistance, state.delta); - interactable.OnSwipe(swipeEventArgs); - interactor.OnSwipe(swipeEventArgs); + interactable.OnGesture(gestureEventArgs); + interactor.OnGesture(gestureEventArgs); } break; @@ -105,31 +105,31 @@ public void Update() switch (state.gestureState) { - case HPUIGestureState.Tap: + case HPUIGesture.Tap: if (timeDelta > tapTimeThreshold || state.cumilativeDirection.magnitude > tapDistanceThreshold) { - state.gestureState = HPUIGestureState.Swipe; - using (hpuiSwipeEventArgsPool.Get(out HPUISwipeEventArgs swipeEventArgs)) + state.gestureState = HPUIGesture.Gesture; + using (hpuiGestureEventArgsPool.Get(out HPUIGestureEventArgs gestureEventArgs)) { - swipeEventArgs.SetParams(interactor, hpuiInteractable, - HPUISwipeState.Started, timeDelta, state.startTime, state.startPosition, + gestureEventArgs.SetParams(interactor, hpuiInteractable, + HPUIGestureState.Started, timeDelta, state.startTime, state.startPosition, state.cumilativeDirection, state.cumilativeDistance, state.delta); - hpuiInteractable.OnSwipe(swipeEventArgs); - interactor.OnSwipe(swipeEventArgs); + hpuiInteractable.OnGesture(gestureEventArgs); + interactor.OnGesture(gestureEventArgs); } } break; - case HPUIGestureState.Swipe: - using (hpuiSwipeEventArgsPool.Get(out HPUISwipeEventArgs swipeEventArgs)) + case HPUIGesture.Gesture: + using (hpuiGestureEventArgsPool.Get(out HPUIGestureEventArgs gestureEventArgs)) { - swipeEventArgs.SetParams(interactor, hpuiInteractable, - HPUISwipeState.Updated, timeDelta, state.startTime, state.startPosition, + gestureEventArgs.SetParams(interactor, hpuiInteractable, + HPUIGestureState.Updated, timeDelta, state.startTime, state.startPosition, state.cumilativeDirection, state.cumilativeDistance, state.delta); - hpuiInteractable.OnSwipe(swipeEventArgs); - interactor.OnSwipe(swipeEventArgs); + hpuiInteractable.OnGesture(gestureEventArgs); + interactor.OnGesture(gestureEventArgs); } break; - case HPUIGestureState.Custom: + case HPUIGesture.Custom: // TODO: custom gestures throw new NotImplementedException(); } @@ -146,13 +146,13 @@ public void Update() public void Dispose() { hpuiTapEventArgsPool.Dispose(); - hpuiSwipeEventArgsPool.Dispose(); + hpuiGestureEventArgsPool.Dispose(); states.Clear(); } class HPUIInteractionState { - public HPUIGestureState gestureState; + public HPUIGesture gestureState; public float startTime; public Vector2 startPosition; public Vector2 previousPosition; @@ -160,7 +160,7 @@ class HPUIInteractionState public Vector2 cumilativeDirection; public float cumilativeDistance; - public HPUIInteractionState SetParams(HPUIGestureState gestureState, float startTime, Vector2 startPosition) + public HPUIInteractionState SetParams(HPUIGesture gestureState, float startTime, Vector2 startPosition) { this.gestureState = gestureState; this.startTime = startTime; diff --git a/Runtime/Interaction/Logic/HPUIGestureLogicUnified.cs b/Runtime/Interaction/Logic/HPUIGestureLogicUnified.cs index 010fd86..29d9982 100644 --- a/Runtime/Interaction/Logic/HPUIGestureLogicUnified.cs +++ b/Runtime/Interaction/Logic/HPUIGestureLogicUnified.cs @@ -13,7 +13,7 @@ namespace ubco.ovilab.HPUI.Interaction public class HPUIGestureLogicUnified: IHPUIGestureLogic { private LinkedPool hpuiTapEventArgsPool = new LinkedPool(() => new HPUITapEventArgs()); - private LinkedPool hpuiSwipeEventArgsPool = new LinkedPool(() => new HPUISwipeEventArgs()); + private LinkedPool hpuiGestureEventArgsPool = new LinkedPool(() => new HPUIGestureEventArgs()); private float tapTimeThreshold, tapDistanceThreshold; private IHPUIInteractor interactor; @@ -28,7 +28,7 @@ public class HPUIGestureLogicUnified: IHPUIGestureLogic private IHPUIInteractable activePriorityInteractable, currentTrackingInteractable; private Dictionary activeInteractables = new Dictionary(); - private HPUIGestureState interactorGestureState = HPUIGestureState.None; + private HPUIGesture interactorGestureState = HPUIGesture.None; /// /// Initializes a new instance of the with the thrshold values. @@ -51,9 +51,9 @@ public void OnSelectEntering(IHPUIInteractable interactable) activeInteractablesCount += 1; - if (interactorGestureState == HPUIGestureState.None) + if (interactorGestureState == HPUIGesture.None) { - interactorGestureState = HPUIGestureState.Tap; + interactorGestureState = HPUIGesture.Tap; startTime = Time.time; } @@ -105,7 +105,7 @@ private void ComputeActivePriorityInteractable() // events. For targets selected withing the window, first // prioritize the zOrder, then the time. IHPUIInteractable interactableToBeActive = activeInteractables - .Where(kvp => kvp.Key.HandlesGestureState(interactorGestureState) && kvp.Value.validTarget) + .Where(kvp => kvp.Key.HandlesGesture(interactorGestureState) && kvp.Value.validTarget) .OrderBy(kvp => kvp.Key.zOrder) .ThenBy(kvp => kvp.Value.startTime) .FirstOrDefault().Key; @@ -130,7 +130,7 @@ public void OnSelectExiting(IHPUIInteractable interactable) { switch (interactorGestureState) { - case HPUIGestureState.Tap: + case HPUIGesture.Tap: using (hpuiTapEventArgsPool.Get(out HPUITapEventArgs tapEventArgs)) { ComputeActivePriorityInteractable(); @@ -139,8 +139,8 @@ public void OnSelectExiting(IHPUIInteractable interactable) interactor.OnTap(tapEventArgs); } break; - case HPUIGestureState.Swipe: - using (hpuiSwipeEventArgsPool.Get(out HPUISwipeEventArgs swipeEventArgs)) + case HPUIGesture.Gesture: + using (hpuiGestureEventArgsPool.Get(out HPUIGestureEventArgs gestureEventArgs)) { HPUIInteractionState state; if (activePriorityInteractable != null) @@ -151,11 +151,11 @@ public void OnSelectExiting(IHPUIInteractable interactable) { state = HPUIInteractionState.empty; } - swipeEventArgs.SetParams(interactor, activePriorityInteractable, - HPUISwipeState.Stopped, timeDelta, state.startTime, state.startPosition, + gestureEventArgs.SetParams(interactor, activePriorityInteractable, + HPUIGestureState.Stopped, timeDelta, state.startTime, state.startPosition, cumilativeDirection, cumilativeDistance, delta); - activePriorityInteractable?.OnSwipe(swipeEventArgs); - interactor.OnSwipe(swipeEventArgs); + activePriorityInteractable?.OnGesture(gestureEventArgs); + interactor.OnGesture(gestureEventArgs); } break; @@ -176,7 +176,7 @@ public void OnSelectExiting(IHPUIInteractable interactable) protected void Reset() { activeInteractablesCount = 0; - interactorGestureState = HPUIGestureState.None; + interactorGestureState = HPUIGesture.None; activeInteractables.Clear(); activePriorityInteractable = null; lowestTargetZIndex = int.MaxValue; @@ -188,7 +188,7 @@ protected void Reset() /// public void Update() { - if (interactorGestureState == HPUIGestureState.None) + if (interactorGestureState == HPUIGesture.None) { return; } @@ -210,12 +210,12 @@ public void Update() switch(interactorGestureState) { - case HPUIGestureState.Tap: + case HPUIGesture.Tap: if (timeDelta > tapTimeThreshold || cumilativeDistance > tapDistanceThreshold) { - interactorGestureState = HPUIGestureState.Swipe; + interactorGestureState = HPUIGesture.Gesture; ComputeActivePriorityInteractable(); - using (hpuiSwipeEventArgsPool.Get(out HPUISwipeEventArgs swipeEventArgs)) + using (hpuiGestureEventArgsPool.Get(out HPUIGestureEventArgs gestureEventArgs)) { HPUIInteractionState state; if (activePriorityInteractable != null) @@ -226,16 +226,16 @@ public void Update() { state = HPUIInteractionState.empty; } - swipeEventArgs.SetParams(interactor, activePriorityInteractable, - HPUISwipeState.Started, timeDelta, state.startTime, state.startPosition, + gestureEventArgs.SetParams(interactor, activePriorityInteractable, + HPUIGestureState.Started, timeDelta, state.startTime, state.startPosition, cumilativeDirection, cumilativeDistance, delta); - activePriorityInteractable?.OnSwipe(swipeEventArgs); - interactor.OnSwipe(swipeEventArgs); + activePriorityInteractable?.OnGesture(gestureEventArgs); + interactor.OnGesture(gestureEventArgs); } } break; - case HPUIGestureState.Swipe: - using (hpuiSwipeEventArgsPool.Get(out HPUISwipeEventArgs swipeEventArgs)) + case HPUIGesture.Gesture: + using (hpuiGestureEventArgsPool.Get(out HPUIGestureEventArgs gestureEventArgs)) { HPUIInteractionState state; if (activePriorityInteractable != null) @@ -246,14 +246,14 @@ public void Update() { state = HPUIInteractionState.empty; } - swipeEventArgs.SetParams(interactor, activePriorityInteractable, - HPUISwipeState.Updated, timeDelta, state.startTime, state.startPosition, + gestureEventArgs.SetParams(interactor, activePriorityInteractable, + HPUIGestureState.Updated, timeDelta, state.startTime, state.startPosition, cumilativeDirection, cumilativeDistance, delta); - activePriorityInteractable?.OnSwipe(swipeEventArgs); - interactor.OnSwipe(swipeEventArgs); + activePriorityInteractable?.OnGesture(gestureEventArgs); + interactor.OnGesture(gestureEventArgs); } break; - case HPUIGestureState.Custom: + case HPUIGesture.Custom: // TODO: custom gestures throw new NotImplementedException(); } @@ -267,7 +267,7 @@ public void Dispose() { Reset(); hpuiTapEventArgsPool.Dispose(); - hpuiSwipeEventArgsPool.Dispose(); + hpuiGestureEventArgsPool.Dispose(); } class HPUIInteractionState diff --git a/Tests/HPUIGestureLogicUnifiedTest.cs b/Tests/HPUIGestureLogicUnifiedTest.cs index 92d2bdc..da81ded 100644 --- a/Tests/HPUIGestureLogicUnifiedTest.cs +++ b/Tests/HPUIGestureLogicUnifiedTest.cs @@ -13,9 +13,9 @@ public class HPUIGestureLogicUnifiedTest { const float TapTimeThreshold = 0.4f; const int TapDistanceThreshold = 1; - private IHPUIInteractable lastTapInteractable, lastSwipeInteractable; + private IHPUIInteractable lastTapInteractable, lastGestureInteractable; private int tapsCount = 0; - private int swipesCount = 0; + private int gesturesCount = 0; void OnTapCallback(HPUITapEventArgs args) { @@ -23,19 +23,19 @@ void OnTapCallback(HPUITapEventArgs args) lastTapInteractable = args.interactableObject; } - void OnSwipeCallback(HPUISwipeEventArgs args) + void OnGestureCallback(HPUIGestureEventArgs args) { - swipesCount += 1; + gesturesCount += 1; Debug.Log($"{args.interactableObject}"); - lastSwipeInteractable = args.interactableObject; + lastGestureInteractable = args.interactableObject; } private void Reset() { tapsCount = 0; - swipesCount = 0; + gesturesCount = 0; lastTapInteractable = null; - lastSwipeInteractable = null; + lastGestureInteractable = null; } // A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use @@ -44,7 +44,7 @@ private void Reset() public IEnumerator HPUIGestureLogicUnifiedTest_SimpleTap() { Reset(); - TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnSwipeCallback); + TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnGestureCallback); IHPUIGestureLogic logic = new HPUIGestureLogicUnified(new HPUIInteractor(), TapTimeThreshold, TapDistanceThreshold); // First tap logic.OnSelectEntering(i1); @@ -53,7 +53,7 @@ public IEnumerator HPUIGestureLogicUnifiedTest_SimpleTap() logic.Update(); logic.OnSelectExiting(i1); Assert.AreEqual(tapsCount, 1); - Assert.AreEqual(swipesCount, 0); + Assert.AreEqual(gesturesCount, 0); // Second tap logic.OnSelectEntering(i1); @@ -62,14 +62,14 @@ public IEnumerator HPUIGestureLogicUnifiedTest_SimpleTap() logic.Update(); logic.OnSelectExiting(i1); Assert.AreEqual(tapsCount, 2); - Assert.AreEqual(swipesCount, 0); + Assert.AreEqual(gesturesCount, 0); } [UnityTest] - public IEnumerator HPUIGestureLogicUnifiedTest_SimpleSwipe() + public IEnumerator HPUIGestureLogicUnifiedTest_SimpleGesture() { Reset(); - TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnSwipeCallback); + TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnGestureCallback); IHPUIGestureLogic logic = new HPUIGestureLogicUnified(new HPUIInteractor(), TapTimeThreshold, TapDistanceThreshold); // Tap and hold @@ -79,7 +79,7 @@ public IEnumerator HPUIGestureLogicUnifiedTest_SimpleSwipe() logic.Update(); logic.OnSelectExiting(i1); Assert.AreEqual(tapsCount, 0); - Assert.Greater(swipesCount, 0); + Assert.Greater(gesturesCount, 0); // Move logic.OnSelectEntering(i1); @@ -88,15 +88,15 @@ public IEnumerator HPUIGestureLogicUnifiedTest_SimpleSwipe() logic.Update(); logic.OnSelectExiting(i1); Assert.AreEqual(tapsCount, 0); - Assert.Greater(swipesCount, 0); + Assert.Greater(gesturesCount, 0); } [Test] public void HPUIGestureLogicUnifiedTest_TwoItem_tap_time() { Reset(); - TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnSwipeCallback); - TestHPUIInteractable i2 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnSwipeCallback); + TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnGestureCallback); + TestHPUIInteractable i2 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnGestureCallback); IHPUIGestureLogic logic = new HPUIGestureLogicUnified(new HPUIInteractor(), TapTimeThreshold, TapDistanceThreshold); // Tap 1-2---1-2 @@ -106,7 +106,7 @@ public void HPUIGestureLogicUnifiedTest_TwoItem_tap_time() logic.OnSelectExiting(i1); logic.OnSelectExiting(i2); Assert.AreEqual(tapsCount, 1); - Assert.AreEqual(swipesCount, 0); + Assert.AreEqual(gesturesCount, 0); Assert.AreEqual(lastTapInteractable, i1); Assert.AreEqual(i1.tapCalled, 1); Assert.AreEqual(i2.tapCalled, 0); @@ -121,7 +121,7 @@ public void HPUIGestureLogicUnifiedTest_TwoItem_tap_time() logic.OnSelectExiting(i2); logic.OnSelectExiting(i1); Assert.AreEqual(tapsCount, 1); - Assert.AreEqual(swipesCount, 0); + Assert.AreEqual(gesturesCount, 0); Assert.AreEqual(lastTapInteractable, i1); Assert.AreEqual(i1.tapCalled, 1); Assert.AreEqual(i2.tapCalled, 0); @@ -131,8 +131,8 @@ public void HPUIGestureLogicUnifiedTest_TwoItem_tap_time() public void HPUIGestureLogicUnifiedTest_TwoItem_tap_zOrder() { Reset(); - TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnSwipeCallback); - TestHPUIInteractable i2 = new TestHPUIInteractable(1, true, true, OnTapCallback, OnSwipeCallback); + TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnGestureCallback); + TestHPUIInteractable i2 = new TestHPUIInteractable(1, true, true, OnTapCallback, OnGestureCallback); IHPUIGestureLogic logic = new HPUIGestureLogicUnified(new HPUIInteractor(), TapTimeThreshold, TapDistanceThreshold); // Tap 1-2---1-2 @@ -142,7 +142,7 @@ public void HPUIGestureLogicUnifiedTest_TwoItem_tap_zOrder() logic.OnSelectExiting(i1); logic.OnSelectExiting(i2); Assert.AreEqual(tapsCount, 1); - Assert.AreEqual(swipesCount, 0); + Assert.AreEqual(gesturesCount, 0); Assert.AreEqual(lastTapInteractable, i1); Assert.AreEqual(i1.tapCalled, 1); Assert.AreEqual(i2.tapCalled, 0); @@ -157,18 +157,18 @@ public void HPUIGestureLogicUnifiedTest_TwoItem_tap_zOrder() logic.OnSelectExiting(i2); logic.OnSelectExiting(i1); Assert.AreEqual(tapsCount, 1); - Assert.AreEqual(swipesCount, 0); + Assert.AreEqual(gesturesCount, 0); Assert.AreEqual(lastTapInteractable, i1); Assert.AreEqual(i1.tapCalled, 1); Assert.AreEqual(i2.tapCalled, 0); } [UnityTest] - public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_swipe() + public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_gesture() { Reset(); - TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnSwipeCallback); - TestHPUIInteractable i2 = new TestHPUIInteractable(1, true, true, OnTapCallback, OnSwipeCallback); + TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnGestureCallback); + TestHPUIInteractable i2 = new TestHPUIInteractable(1, true, true, OnTapCallback, OnGestureCallback); IHPUIGestureLogic logic = new HPUIGestureLogicUnified(new HPUIInteractor(), TapTimeThreshold, TapDistanceThreshold); logic.OnSelectEntering(i2); @@ -179,19 +179,19 @@ public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_swipe() logic.OnSelectExiting(i1); logic.OnSelectExiting(i2); Assert.AreEqual(tapsCount, 0); - Assert.Greater(swipesCount, 0); - Assert.AreEqual(lastSwipeInteractable, i1); + Assert.Greater(gesturesCount, 0); + Assert.AreEqual(lastGestureInteractable, i1); Assert.Greater(i1.swipCalled, 0); Assert.AreEqual(i2.swipCalled, 0); } // Anything ouside the priority window should not get selected [UnityTest] - public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_swipe_priority_window() + public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_gesture_priority_window() { Reset(); - TestHPUIInteractable i1 = new TestHPUIInteractable(1, true, true, OnTapCallback, OnSwipeCallback); - TestHPUIInteractable i2 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnSwipeCallback); + TestHPUIInteractable i1 = new TestHPUIInteractable(1, true, true, OnTapCallback, OnGestureCallback); + TestHPUIInteractable i2 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnGestureCallback); IHPUIGestureLogic logic = new HPUIGestureLogicUnified(new HPUIInteractor(), TapTimeThreshold, TapDistanceThreshold); logic.OnSelectEntering(i1); @@ -205,19 +205,19 @@ public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_swipe_priority_window() logic.OnSelectExiting(i1); logic.OnSelectExiting(i2); Assert.AreEqual(tapsCount, 0); - Assert.Greater(swipesCount, 0); - Assert.AreEqual(lastSwipeInteractable, i1); + Assert.Greater(gesturesCount, 0); + Assert.AreEqual(lastGestureInteractable, i1); Assert.Greater(i1.swipCalled, 0); Assert.AreEqual(i2.swipCalled, 0); } // When an event is not handled, hand over to next item in the priority list [UnityTest] - public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_swipe_handle_events() + public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_gesture_handle_events() { Reset(); - TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnSwipeCallback); - TestHPUIInteractable i2 = new TestHPUIInteractable(0, false, false, OnTapCallback, OnSwipeCallback); + TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnGestureCallback); + TestHPUIInteractable i2 = new TestHPUIInteractable(0, false, false, OnTapCallback, OnGestureCallback); IHPUIGestureLogic logic = new HPUIGestureLogicUnified(new HPUIInteractor(), TapTimeThreshold, TapDistanceThreshold); logic.OnSelectEntering(i2); @@ -227,14 +227,14 @@ public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_swipe_handle_events() logic.OnSelectExiting(i1); logic.OnSelectExiting(i2); Assert.AreEqual(tapsCount, 1); - Assert.AreEqual(swipesCount, 0); + Assert.AreEqual(gesturesCount, 0); Assert.AreEqual(lastTapInteractable, i1); Reset(); i1.Reset(); i2.Reset(); logic.OnSelectEntering(i2); - // even though this is coming in second, this should get the swipe + // even though this is coming in second, this should get the gesture logic.OnSelectEntering(i1); logic.Update(); yield return new WaitForSeconds(1); @@ -242,19 +242,19 @@ public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_swipe_handle_events() logic.OnSelectExiting(i1); logic.OnSelectExiting(i2); Assert.AreEqual(tapsCount, 0); - Assert.Greater(swipesCount, 0); - Assert.AreEqual(lastSwipeInteractable, i1); + Assert.Greater(gesturesCount, 0); + Assert.AreEqual(lastGestureInteractable, i1); Assert.AreEqual(i2.swipCalled, 0); Assert.Greater(i1.swipCalled, 0); } //There can be instances where the event is not hanled by any interactable [UnityTest] - public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_swipe_no_handle_events() + public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_gesture_no_handle_events() { Reset(); - TestHPUIInteractable i1 = new TestHPUIInteractable(0, false, false, OnTapCallback, OnSwipeCallback); - TestHPUIInteractable i2 = new TestHPUIInteractable(0, false, false, OnTapCallback, OnSwipeCallback); + TestHPUIInteractable i1 = new TestHPUIInteractable(0, false, false, OnTapCallback, OnGestureCallback); + TestHPUIInteractable i2 = new TestHPUIInteractable(0, false, false, OnTapCallback, OnGestureCallback); IHPUIGestureLogic logic = new HPUIGestureLogicUnified(new HPUIInteractor(), TapTimeThreshold, TapDistanceThreshold); // Tap not handled by any interactable @@ -267,9 +267,9 @@ public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_swipe_no_handle_events() logic.OnSelectExiting(i1); logic.OnSelectExiting(i2); Assert.AreEqual(tapsCount, 0); - Assert.AreEqual(swipesCount, 0); + Assert.AreEqual(gesturesCount, 0); - // Swipe not handled by any interactable + // Gesture not handled by any interactable Reset(); i1.Reset(); i2.Reset(); @@ -281,28 +281,28 @@ public IEnumerator HPUIGestureLogicUnifiedTest_TwoItem_swipe_no_handle_events() logic.OnSelectExiting(i1); logic.OnSelectExiting(i2); Assert.AreEqual(tapsCount, 0); - Assert.AreEqual(swipesCount, 0); + Assert.AreEqual(gesturesCount, 0); } class TestHPUIInteractable : IHPUIInteractable { public Vector2 interactorPosition; - public bool handlesTap, handlesSwipe; + public bool handlesTap, handlesGesture; public System.Action onTapCallback; - public System.Action onSwipeCallback; + public System.Action onGestureCallback; public int tapCalled = 0; public int swipCalled = 0; - public TestHPUIInteractable(int zOrder, bool handlesTap, bool handlesSwipe, Action onTapCallback = null, Action onSwipeCallback = null) + public TestHPUIInteractable(int zOrder, bool handlesTap, bool handlesGesture, Action onTapCallback = null, Action onGestureCallback = null) { this.zOrder = zOrder; this.handlesTap = handlesTap; - this.handlesSwipe = handlesSwipe; + this.handlesGesture = handlesGesture; if (onTapCallback != null) this.onTapCallback = onTapCallback; - if (onSwipeCallback != null) - this.onSwipeCallback = onSwipeCallback; + if (onGestureCallback != null) + this.onGestureCallback = onGestureCallback; Reset(); } @@ -320,22 +320,22 @@ Vector2 IHPUIInteractable.ComputeInteractorPostion(IXRInteractor interactor) return interactorPosition; } - bool IHPUIInteractable.HandlesGestureState(HPUIGestureState state) + bool IHPUIInteractable.HandlesGesture(HPUIGesture state) { switch (state) { - case HPUIGestureState.Tap: + case HPUIGesture.Tap: return handlesTap; - case HPUIGestureState.Swipe: - return handlesSwipe; + case HPUIGesture.Gesture: + return handlesGesture; default: throw new InvalidOperationException($"Gesture state {state} is not handled"); } } - void IHPUIInteractable.OnSwipe(HPUISwipeEventArgs args) + void IHPUIInteractable.OnGesture(HPUIGestureEventArgs args) { swipCalled += 1; - onSwipeCallback?.Invoke(args); + onGestureCallback?.Invoke(args); } void IHPUIInteractable.OnTap(HPUITapEventArgs args)