Skip to content

Commit 629e3b0

Browse files
author
Julia Schwarz
committed
Fix no OnDragUpdated events from poke pointers
1 parent 852b6c4 commit 629e3b0

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
@@ -342,6 +342,10 @@ private void RaiseTouchUpdated(GameObject targetObject, Vector3 touchPosition)
342342
{
343343
CoreServices.InputSystem?.RaiseOnTouchUpdated(InputSourceParent, Controller, Handedness, touchPosition);
344344
}
345+
else if (closestProximityTouchable.EventsToReceive == TouchableEventType.Pointer)
346+
{
347+
CoreServices.InputSystem?.RaisePointerDragged(this, pointerAction, Handedness, InputSourceParent);
348+
}
345349
}
346350
}
347351

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
@@ -127,7 +127,7 @@ private T CreateTouchable<T>(Vector3 cubeDimensions) where T : BaseNearInteracti
127127
}
128128

129129

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

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

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

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

161-
using (var catcher = CreateEventCatcher(touchable))
235+
using (var catcher = CreateTouchEventCatcher(touchable))
162236
{
163237
// Touch started and completed when entering and exiting
164238
yield return PlayModeTestUtilities.MoveHandFromTo(initialHandPosition, objectPosition, numSteps, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim);
@@ -206,7 +280,7 @@ public IEnumerator NearInteractionTouchableVolumeVariant()
206280

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

209-
using (var catcher = CreateEventCatcher(touchable))
283+
using (var catcher = CreateTouchEventCatcher(touchable))
210284
{
211285
// Touch started when entering collider
212286
yield return PlayModeTestUtilities.MoveHandFromTo(initialHandPosition, objectPosition, numSteps, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim);
@@ -366,7 +440,7 @@ public IEnumerator NearInteractionTouchableOverlapQuerySaturation()
366440
touchables[i].SetBounds(new Vector2(0.5f, 0.5f));
367441
touchables[i].transform.position = objectPosition + r * radiusStart;
368442

369-
catchers[i] = CreateEventCatcher(touchables[i]);
443+
catchers[i] = CreateTouchEventCatcher(touchables[i]);
370444
}
371445

372446
yield return new WaitForFixedUpdate();
@@ -492,10 +566,10 @@ public IEnumerator NearInteractionTouchableDistance()
492566
var touchableRect = CreateTouchable<NearInteractionTouchable>(0.15f);
493567
touchableRect.SetLocalForward(touchNormal);
494568
touchableRect.SetBounds(new Vector2(0.5f, 0.5f));
495-
var catcherRect = CreateEventCatcher(touchableRect);
569+
var catcherRect = CreateTouchEventCatcher(touchableRect);
496570

497571
var touchableVolume = CreateTouchable<NearInteractionTouchableVolume>(0.15f);
498-
var catcherVolume = CreateEventCatcher(touchableVolume);
572+
var catcherVolume = CreateTouchEventCatcher(touchableVolume);
499573

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

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

0 commit comments

Comments
 (0)