Skip to content

Commit 3fa0518

Browse files
Julia Schwarzkeveleigh
authored andcommitted
Fix no OnDragUpdated events from poke pointers
1 parent b7b9fb9 commit 3fa0518

File tree

3 files changed

+127
-10
lines changed

3 files changed

+127
-10
lines changed

Assets/MixedRealityToolkit.SDK/Features/UX/Scripts/Pointers/PokePointer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ private void RaiseTouchUpdated(GameObject targetObject, Vector3 touchPosition)
345345
{
346346
CoreServices.InputSystem?.RaiseOnTouchUpdated(InputSourceParent, Controller, Handedness, touchPosition);
347347
}
348+
else if (closestProximityTouchable.EventsToReceive == TouchableEventType.Pointer)
349+
{
350+
CoreServices.InputSystem?.RaisePointerDragged(this, pointerAction, Handedness, InputSourceParent);
351+
}
348352
}
349353
}
350354

Assets/MixedRealityToolkit.Tests/PlayModeTests/EventCatcherTestUtilities.cs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,51 @@ public void Dispose()
5959
}
6060
}
6161

62+
/// <summary>
63+
/// Utility for counting pointer events.
64+
/// </summary>
65+
internal class PointerEventCatcher : FocusedObjectEventCatcher<PointerEventCatcher>, IMixedRealityPointerHandler
66+
{
67+
public readonly UnityEvent OnPointerDownEvent = new UnityEvent();
68+
public readonly UnityEvent OnPointerUpEvent = new UnityEvent();
69+
public readonly UnityEvent OnPointerDraggedEvent = new UnityEvent();
70+
public readonly UnityEvent OnPointerClickedEvent = new UnityEvent();
71+
72+
public int DragEventCount = 0;
73+
74+
/// <inheritdoc />
75+
public void OnPointerClicked(MixedRealityPointerEventData eventData)
76+
{
77+
OnPointerClickedEvent.Invoke();
78+
}
79+
80+
/// <inheritdoc />
81+
public void OnPointerDown(MixedRealityPointerEventData eventData)
82+
{
83+
++EventsStarted;
84+
OnPointerDownEvent.Invoke();
85+
}
86+
87+
/// <inheritdoc />
88+
public void OnPointerDragged(MixedRealityPointerEventData eventData)
89+
{
90+
++DragEventCount;
91+
OnPointerDraggedEvent.Invoke();
92+
}
93+
94+
/// <inheritdoc />
95+
public void OnPointerUp(MixedRealityPointerEventData eventData)
96+
{
97+
++EventsCompleted;
98+
OnPointerUpEvent.Invoke();
99+
}
100+
101+
102+
}
103+
62104
/// <summary>
63105
/// Utility for counting touch events.
64106
/// </summary>
65-
/// <remarks>
66-
/// Touching an object does not imply getting focus, so use a global event handler to be independent from focus.
67-
/// </remarks>
68107
public class TouchEventCatcher : FocusedObjectEventCatcher<TouchEventCatcher>, IMixedRealityTouchHandler
69108
{
70109
public readonly UnityEvent OnTouchStartedEvent = new UnityEvent();

Assets/MixedRealityToolkit.Tests/PlayModeTests/NearInteractionTouchableTests.cs

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private T CreateTouchable<T>(Vector3 cubeDimensions) where T : BaseNearInteracti
126126
}
127127

128128

129-
private TouchEventCatcher CreateEventCatcher(BaseNearInteractionTouchable touchable)
129+
private TouchEventCatcher CreateTouchEventCatcher(BaseNearInteractionTouchable touchable)
130130
{
131131
var catcher = TouchEventCatcher.Create(touchable.gameObject);
132132

@@ -142,6 +142,80 @@ private TouchEventCatcher CreateEventCatcher(BaseNearInteractionTouchable toucha
142142
return catcher;
143143
}
144144

145+
146+
private PointerEventCatcher CreatePointerEventCatcher(BaseNearInteractionTouchable touchable)
147+
{
148+
var catcher = PointerEventCatcher.Create(touchable.gameObject);
149+
catcher.OnPointerDownEvent.AddListener(() =>
150+
{
151+
touchable.GetComponent<Renderer>().material = pokeMaterial;
152+
});
153+
catcher.OnPointerUpEvent.AddListener(() =>
154+
{
155+
touchable.GetComponent<Renderer>().material = idleMaterial;
156+
});
157+
158+
return catcher;
159+
}
160+
161+
/// <summary>
162+
/// Test that NearInteractionTouchable can raise pointer events
163+
/// </summary>
164+
/// <returns></returns>
165+
[UnityTest]
166+
public IEnumerator NearInteractionTouchablePointerEvents()
167+
{
168+
var touchable = CreateTouchable<NearInteractionTouchable>(objectScale);
169+
touchable.SetLocalForward(touchNormal);
170+
touchable.SetBounds(new Vector2(0.5f, 0.5f));
171+
touchable.EventsToReceive = TouchableEventType.Pointer;
172+
173+
yield return new WaitForFixedUpdate();
174+
yield return null;
175+
176+
yield return PlayModeTestUtilities.ShowHand(Handedness.Right, inputSim);
177+
178+
using (var catcher = CreatePointerEventCatcher(touchable))
179+
{
180+
// Touch started and completed when entering and exiting
181+
yield return PlayModeTestUtilities.MoveHandFromTo(initialHandPosition, objectPosition, numSteps, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim);
182+
Assert.AreEqual(1, catcher.EventsStarted);
183+
Assert.AreEqual(0, catcher.EventsCompleted);
184+
yield return PlayModeTestUtilities.MoveHandFromTo(objectPosition, rightPosition, numSteps, ArticulatedHandPose.GestureId.Pinch, Handedness.Right, inputSim);
185+
Assert.AreEqual(1, catcher.EventsStarted);
186+
Assert.AreEqual(1, catcher.EventsCompleted);
187+
Assert.Greater(catcher.DragEventCount, 0);
188+
189+
// Touch started and completed when entering and exiting behind the plane
190+
yield return PlayModeTestUtilities.MoveHandFromTo(initialHandPosition, objectPosition, numSteps, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim);
191+
Assert.AreEqual(2, catcher.EventsStarted);
192+
Assert.AreEqual(1, catcher.EventsCompleted);
193+
yield return PlayModeTestUtilities.MoveHandFromTo(objectPosition, backPosition, numSteps, ArticulatedHandPose.GestureId.Pinch, Handedness.Right, inputSim);
194+
Assert.AreEqual(2, catcher.EventsStarted);
195+
Assert.AreEqual(2, catcher.EventsCompleted);
196+
Assert.Greater(catcher.DragEventCount, 1);
197+
int dragEventCount = catcher.DragEventCount;
198+
199+
// No touch when moving at behind the plane
200+
yield return PlayModeTestUtilities.MoveHandFromTo(backPosition, rightPosition, numSteps, ArticulatedHandPose.GestureId.Pinch, Handedness.Right, inputSim);
201+
Assert.AreEqual(2, catcher.EventsStarted);
202+
Assert.AreEqual(2, catcher.EventsCompleted);
203+
Assert.AreEqual(dragEventCount, catcher.DragEventCount, "No drag events should fire when poke pointer moving behind plane");
204+
205+
206+
// No touch when moving outside the bounds
207+
yield return PlayModeTestUtilities.MoveHandFromTo(initialHandPosition + outOfBoundsOffset, objectPosition + outOfBoundsOffset, numSteps, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim);
208+
yield return PlayModeTestUtilities.MoveHandFromTo(objectPosition + outOfBoundsOffset, rightPosition, numSteps, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim);
209+
Assert.AreEqual(2, catcher.EventsStarted);
210+
Assert.AreEqual(2, catcher.EventsCompleted);
211+
Assert.AreEqual(dragEventCount, catcher.DragEventCount, "No drag events should fire when poke pointer moving outside bounds");
212+
}
213+
214+
yield return PlayModeTestUtilities.HideHand(Handedness.Right, inputSim);
215+
216+
UnityEngine.Object.Destroy(touchable.gameObject);
217+
}
218+
145219
/// <summary>
146220
/// Test creates an object with NearInteractionTouchable
147221
/// </summary>
@@ -157,7 +231,7 @@ public IEnumerator NearInteractionTouchableVariant()
157231

158232
yield return PlayModeTestUtilities.ShowHand(Handedness.Right, inputSim);
159233

160-
using (var catcher = CreateEventCatcher(touchable))
234+
using (var catcher = CreateTouchEventCatcher(touchable))
161235
{
162236
// Touch started and completed when entering and exiting
163237
yield return PlayModeTestUtilities.MoveHand(initialHandPosition, objectPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim);
@@ -205,7 +279,7 @@ public IEnumerator NearInteractionTouchableVolumeVariant()
205279

206280
yield return PlayModeTestUtilities.ShowHand(Handedness.Right, inputSim);
207281

208-
using (var catcher = CreateEventCatcher(touchable))
282+
using (var catcher = CreateTouchEventCatcher(touchable))
209283
{
210284
// Touch started when entering collider
211285
yield return PlayModeTestUtilities.MoveHand(initialHandPosition, objectPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim);
@@ -365,7 +439,7 @@ public IEnumerator NearInteractionTouchableOverlapQuerySaturation()
365439
touchables[i].SetBounds(new Vector2(0.5f, 0.5f));
366440
touchables[i].transform.position = objectPosition + r * radiusStart;
367441

368-
catchers[i] = CreateEventCatcher(touchables[i]);
442+
catchers[i] = CreateTouchEventCatcher(touchables[i]);
369443
}
370444

371445
yield return new WaitForFixedUpdate();
@@ -491,10 +565,10 @@ public IEnumerator NearInteractionTouchableDistance()
491565
var touchableRect = CreateTouchable<NearInteractionTouchable>(0.15f);
492566
touchableRect.SetLocalForward(touchNormal);
493567
touchableRect.SetBounds(new Vector2(0.5f, 0.5f));
494-
var catcherRect = CreateEventCatcher(touchableRect);
568+
var catcherRect = CreateTouchEventCatcher(touchableRect);
495569

496570
var touchableVolume = CreateTouchable<NearInteractionTouchableVolume>(0.15f);
497-
var catcherVolume = CreateEventCatcher(touchableVolume);
571+
var catcherVolume = CreateTouchEventCatcher(touchableVolume);
498572

499573
var canvas = UnityUiUtilities.CreateCanvas(0.002f);
500574
var touchableUI = canvas.GetComponent<NearInteractionTouchableUnityUI>();
@@ -634,7 +708,7 @@ public IEnumerator NearInteractionTouchableSetTouchableCollider()
634708
BoxCollider newBoxCollider = cube2.GetComponent<BoxCollider>();
635709
newBoxCollider.size = new Vector3(4, 2, 1.2f);
636710

637-
using (var catcher = CreateEventCatcher(nearIT))
711+
using (var catcher = CreateTouchEventCatcher(nearIT))
638712
{
639713
// Touch started and completed when entering and exiting the collider
640714
yield return rightHand.Move(new Vector3(0, 0, 0.4f));

0 commit comments

Comments
 (0)