Skip to content

Commit 8d4a8f1

Browse files
authored
FIX: Correctly implemented IsPointerOverGameObject method for `Inpu… (#879)
1 parent 975e589 commit 8d4a8f1

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

Assets/Tests/InputSystem/Plugins/UITests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public IEnumerator MouseActions_CanDriveUI()
163163
// Reset initial selection
164164
leftChildReceiver.Reset();
165165

166+
Assert.That(eventSystem.IsPointerOverGameObject(), Is.False);
166167
// Move mouse over left child.
167168
InputSystem.QueueStateEvent(mouse, new MouseState { position = new Vector2(100, 100) });
168169
InputSystem.Update();
@@ -172,6 +173,7 @@ public IEnumerator MouseActions_CanDriveUI()
172173
Assert.That(leftChildReceiver.events[0].type, Is.EqualTo(EventType.Enter));
173174
leftChildReceiver.Reset();
174175
Assert.That(rightChildReceiver.events, Is.Empty);
176+
Assert.That(eventSystem.IsPointerOverGameObject(), Is.True);
175177

176178
// Check basic down/up
177179
InputSystem.QueueStateEvent(mouse, new MouseState { position = new Vector2(100, 100), buttons = 1 << (int)MouseButton.Left });
@@ -248,6 +250,7 @@ public IEnumerator MouseActions_CanDriveUI()
248250
Assert.That(rightChildReceiver.events, Has.Count.EqualTo(1));
249251
Assert.That(rightChildReceiver.events[0].type, Is.EqualTo(EventType.Scroll));
250252
rightChildReceiver.Reset();
253+
Assert.That(eventSystem.IsPointerOverGameObject(), Is.True);
251254
}
252255

253256
unsafe void SetTouchState(TouchscreenState state, int index, TouchState touch)
@@ -311,6 +314,11 @@ public IEnumerator TouchActions_CanDriveUIAndDistinguishMultipleTouches()
311314
leftChildReceiver.Reset();
312315
Assert.That(rightChildReceiver.events, Is.Empty);
313316

317+
Assert.That(eventSystem.IsPointerOverGameObject(), Is.False);
318+
Assert.That(eventSystem.IsPointerOverGameObject(1), Is.True);
319+
Assert.That(eventSystem.IsPointerOverGameObject(2), Is.False);
320+
Assert.That(eventSystem.IsPointerOverGameObject(3), Is.False);
321+
314322
InputSystem.QueueDeltaStateEvent(touchScreen.touches[0], new TouchState()
315323
{
316324
touchId = 1,
@@ -344,6 +352,11 @@ public IEnumerator TouchActions_CanDriveUIAndDistinguishMultipleTouches()
344352
rightChildReceiver.Reset();
345353
Assert.That(leftChildReceiver.events, Is.Empty);
346354

355+
Assert.That(eventSystem.IsPointerOverGameObject(), Is.False);
356+
Assert.That(eventSystem.IsPointerOverGameObject(1), Is.True);
357+
Assert.That(eventSystem.IsPointerOverGameObject(2), Is.True);
358+
Assert.That(eventSystem.IsPointerOverGameObject(3), Is.False);
359+
347360
InputSystem.QueueDeltaStateEvent(touchScreen.touches[1], new TouchState()
348361
{
349362
touchId = 2,
@@ -392,6 +405,11 @@ public IEnumerator TouchActions_CanDriveUIAndDistinguishMultipleTouches()
392405
leftChildReceiver.Reset();
393406
Assert.That(rightChildReceiver.events, Is.Empty);
394407

408+
Assert.That(eventSystem.IsPointerOverGameObject(), Is.False);
409+
Assert.That(eventSystem.IsPointerOverGameObject(1), Is.True);
410+
Assert.That(eventSystem.IsPointerOverGameObject(2), Is.True);
411+
Assert.That(eventSystem.IsPointerOverGameObject(3), Is.False);
412+
395413
// release right button
396414
// NOTE: The UI behavior is a bit funky here, as it cannot properly handle selection state for multiple
397415
// objects. As a result, only releasing the left button will receive a click in this setup.
@@ -420,6 +438,11 @@ public IEnumerator TouchActions_CanDriveUIAndDistinguishMultipleTouches()
420438
Assert.That((rightChildReceiver.events[0].data as PointerEventData).button, Is.EqualTo(PointerEventData.InputButton.Left));
421439
rightChildReceiver.Reset();
422440
Assert.That(leftChildReceiver.events, Is.Empty);
441+
442+
Assert.That(eventSystem.IsPointerOverGameObject(), Is.False);
443+
Assert.That(eventSystem.IsPointerOverGameObject(1), Is.True);
444+
Assert.That(eventSystem.IsPointerOverGameObject(2), Is.True);
445+
Assert.That(eventSystem.IsPointerOverGameObject(3), Is.False);
423446
}
424447

425448
[UnityTest]

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ however, it has to be formatted properly to pass verification tests.
1212
### Fixed
1313

1414
- Fixed a bug where the Input Settings Window might throw exceptions after assembly reload.
15+
- Correctly implemented `IsPointerOverGameObject` method for `InputSystemUIInputModule`.
1516

1617
## [1.0.0-preview] - 2019-9-20
1718

Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ public override void ActivateModule()
3434
eventSystem.SetSelectedGameObject(toSelect, GetBaseEventData());
3535
}
3636

37+
public override bool IsPointerOverGameObject(int pointerId)
38+
{
39+
foreach (var state in mouseStates)
40+
{
41+
if (state.touchId == pointerId)
42+
return state.pointerTarget != null;
43+
}
44+
return false;
45+
}
46+
3747
private RaycastResult PerformRaycast(PointerEventData eventData)
3848
{
3949
if (eventData == null)
@@ -705,7 +715,7 @@ int GetTrackedDeviceIndexForCallbackContext(InputAction.CallbackContext context)
705715
int GetMouseDeviceIndexForCallbackContext(InputAction.CallbackContext context)
706716
{
707717
Debug.Assert(context.action.type == InputActionType.PassThrough, $"Pointer actions should be pass-through actions, so the UI can properly distinguish multiple pointing devices/fingers. Please set the action type of '{context.action.name}' to 'Pass-Through'.");
708-
var touchId = 0;
718+
var touchId = PointerInputModule.kMouseLeftId;
709719
if (context.control.parent is TouchControl)
710720
touchId = ((TouchControl)context.control.parent).touchId.ReadValue();
711721

Packages/com.unity.inputsystem/InputSystem/Plugins/UI/MouseModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ public void CopyFrom(PointerEventData eventData)
354354
private MouseButtonModel m_RightButton;
355355
private MouseButtonModel m_MiddleButton;
356356

357+
internal GameObject pointerTarget => m_InternalData.pointerTarget;
358+
357359
private InternalData m_InternalData;
358360
}
359361
}

0 commit comments

Comments
 (0)