Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ however, it has to be formatted properly to pass verification tests.
- Fixed "MissingReferenceException" errors when closing an in-game dropdown field [ISXB-1081](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1081).
- Fixed potential crash on Mac when using stale references to deleted InputDevice objects [ISXB-606](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-606).
- Fixed conditional compilation for non-editor analytics on platforms not enabling analytics.
- Fixed simulated touch input not working with PlayerInput component [ISXB-483](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-483)

### Changed
- Renamed editor Resources directories to PackageResources to fix package validation warnings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Users;
using UnityEngine.InputSystem.Utilities;
#if UNITY_EDITOR
using UnityEditor;
Expand Down Expand Up @@ -236,6 +237,14 @@ private void OnDeviceChange(InputDevice device, InputDeviceChange change)
}
}
}

private void TryPerformUserPairingOfSimulatedTouchscreen()
{
using (InputActionRebindingExtensions.DeferBindingResolution())
{
InputUser.PerformPairingWithDevice(simulatedTouchscreen, m_PlayerInput.user);
}
}

protected void OnEnable()
{
Expand Down Expand Up @@ -264,6 +273,28 @@ protected void OnEnable()

InputSystem.onDeviceChange += m_OnDeviceChange;
InputSystem.onEvent += m_OnEvent;

// In case there's a PlayerInput component in the scene, we want to pair the simulated touchscreen to
// the PlayerInput user. The touchscreen device does not queue events so we need to pair it to the user.
m_PlayerInput = PlayerInput.s_AllActivePlayersCount > 0 ? PlayerInput.s_AllActivePlayers[0] : null;
if (m_PlayerInput)
{
TryPerformUserPairingOfSimulatedTouchscreen();
InputUser.onChange += PairSimulatedTouchscreenOnChange;
}
}
private void PairSimulatedTouchscreenOnChange(InputUser user, InputUserChange change, InputDevice device)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the reported issue also an issue when not using control schemes or does it only surface when the control schemes are present? Basically what would the intended behavior be in case a user was using a real mouse and a real touch screen at the same time? I would expect ping ponging effects on pointer. So maybe this is different since one want to avoid that and the current system do not support reasoning about sources of synthesised events...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the reported issue also an issue when not using control schemes or does it only surface when the control schemes are present?

I didn't test this without control schemes, as they essentially control the PlayerInput use device pairing mechanism (which uses input events). And the problem is pairing mechanism was not taking into account the simulated touchscreen, because it doesn't generate input events.

Basically what would the intended behavior be in case a user was using a real mouse and a real touch screen at the same time? I would expect ping ponging effects on pointer

Yes that would be the behavior. But for this case, mouse (or pen) doesn't exist as its driving the simulated touchscreen. Also the ping pong only ocurrs if "Auto-switch" in PlayerInput is selected. Unless I'm misunderstanding something.

I'm confused with what you mean with this. Can you clarify?

So maybe this is different since one want to avoid that and the current system do not support reasoning about sources of synthesised events...

{
if (change == InputUserChange.ControlSchemeChanged)
{
// When the control scheme is changed, we pair the simulated touchscreen in case
// the new control scheme has action bindings that can be used in it.
// E.g. UI/Point action with touch/position binding is set to Keyboard&Mouse control scheme.
if (!user.pairedDevices.ContainsReference(simulatedTouchscreen))
{
TryPerformUserPairingOfSimulatedTouchscreen();
}
}
}

protected void OnDisable()
Expand All @@ -284,6 +315,8 @@ protected void OnDisable()

InputSystem.onDeviceChange -= m_OnDeviceChange;
InputSystem.onEvent -= m_OnEvent;
if(m_PlayerInput)
InputUser.onChange -= PairSimulatedTouchscreenOnChange;
}

private unsafe void UpdateTouch(int touchIndex, int pointerIndex, TouchPhase phase, InputEventPtr eventPtr = default)
Expand Down Expand Up @@ -356,6 +389,7 @@ private unsafe void UpdateTouch(int touchIndex, int pointerIndex, TouchPhase pha
[NonSerialized] private Action<InputEventPtr, InputDevice> m_OnEvent;

internal static TouchSimulation s_Instance;
private PlayerInput m_PlayerInput;

#if UNITY_EDITOR
static TouchSimulation()
Expand Down