Skip to content

Commit 170c471

Browse files
committed
Fixed UUM-77364. Requires trunk PR (same branch name).
1 parent 58bd3ec commit 170c471

File tree

8 files changed

+92
-7
lines changed

8 files changed

+92
-7
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33

44
namespace UnityEngine.InputSystem.UI
55
{
6-
// AxisEventData has no ToString. But that's the only thing we add so keeping
7-
// it internal.
8-
internal class ExtendedAxisEventData : AxisEventData
6+
// AxisEventData has no ToString. Also added device info. Keeping
7+
// it internal for now.
8+
internal class ExtendedAxisEventData : AxisEventData, INavigationEventData
99
{
10+
/// <summary>
11+
/// The <see cref="InputDevice"/> that generated the axis input.
12+
/// </summary>
13+
/// <seealso cref="Keyboard"/>
14+
/// <seealso cref="Gamepad"/>
15+
public InputDevice device { get; set; }
16+
1017
public ExtendedAxisEventData(EventSystem eventSystem)
1118
: base(eventSystem)
1219
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#if PACKAGE_DOCS_GENERATION || UNITY_INPUT_SYSTEM_ENABLE_UI
2+
using UnityEngine.EventSystems;
3+
4+
namespace UnityEngine.InputSystem.UI
5+
{
6+
// A BaseEventData with added device info.
7+
internal class ExtendedSubmitCancelEventData : BaseEventData, INavigationEventData
8+
{
9+
/// <summary>
10+
/// The <see cref="InputDevice"/> that generated the axis input.
11+
/// </summary>
12+
public InputDevice device { get; set; }
13+
14+
public ExtendedSubmitCancelEventData(EventSystem eventSystem)
15+
: base(eventSystem)
16+
{
17+
}
18+
}
19+
}
20+
#endif

Packages/com.unity.inputsystem/InputSystem/Plugins/UI/ExtendedSubmitCancelEventData.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#if PACKAGE_DOCS_GENERATION || UNITY_INPUT_SYSTEM_ENABLE_UI
2+
3+
namespace UnityEngine.InputSystem.UI
4+
{
5+
internal interface INavigationEventData
6+
{
7+
/// <summary>
8+
/// The <see cref="InputDevice"/> that generated the axis input.
9+
/// </summary>
10+
public InputDevice device { get; }
11+
}
12+
}
13+
#endif

Packages/com.unity.inputsystem/InputSystem/Plugins/UI/INavigationEventData.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ internal void ProcessNavigation(ref NavigationModel navigationState)
861861

862862
if (allow)
863863
{
864-
var eventData = m_NavigationState.eventData;
864+
var eventData = m_NavigationState.eventData as ExtendedAxisEventData;
865865
if (eventData == null)
866866
{
867867
eventData = new ExtendedAxisEventData(eventSystem);
@@ -871,6 +871,7 @@ internal void ProcessNavigation(ref NavigationModel navigationState)
871871

872872
eventData.moveVector = moveVector;
873873
eventData.moveDir = moveDirection;
874+
eventData.device = navigationState.device;
874875

875876
if (IsMoveAllowed(eventData))
876877
{
@@ -903,7 +904,16 @@ internal void ProcessNavigation(ref NavigationModel navigationState)
903904
var submitAction = m_SubmitAction?.action;
904905
var cancelAction = m_CancelAction?.action;
905906

906-
var data = GetBaseEventData();
907+
var data = m_SubmitCancelState.eventData as ExtendedSubmitCancelEventData;
908+
if (data == null)
909+
{
910+
data = new ExtendedSubmitCancelEventData(eventSystem);
911+
m_SubmitCancelState.eventData = data;
912+
}
913+
data.Reset();
914+
915+
data.device = m_SubmitCancelState.device;
916+
907917
if (cancelAction != null && cancelAction.WasPerformedThisFrame())
908918
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.cancelHandler);
909919
if (!data.used && submitAction != null && submitAction.WasPerformedThisFrame())
@@ -1393,7 +1403,7 @@ public InputActionReference move
13931403
public InputActionReference submit
13941404
{
13951405
get => m_SubmitAction;
1396-
set => SwapAction(ref m_SubmitAction, value, m_ActionsHooked, null);
1406+
set => SwapAction(ref m_SubmitAction, value, m_ActionsHooked, m_OnSubmitCancelDelegate);
13971407
}
13981408

13991409
/// <summary>
@@ -1433,7 +1443,7 @@ public InputActionReference submit
14331443
public InputActionReference cancel
14341444
{
14351445
get => m_CancelAction;
1436-
set => SwapAction(ref m_CancelAction, value, m_ActionsHooked, null);
1446+
set => SwapAction(ref m_CancelAction, value, m_ActionsHooked, m_OnSubmitCancelDelegate);
14371447
}
14381448

14391449
/// <summary>
@@ -2245,6 +2255,12 @@ private void OnMoveCallback(InputAction.CallbackContext context)
22452255
{
22462256
////REVIEW: should we poll this? or set the action to not be pass-through? (ps4 controller is spamming this action)
22472257
m_NavigationState.move = context.ReadValue<Vector2>();
2258+
m_NavigationState.device = context.control.device;
2259+
}
2260+
2261+
private void OnSubmitCancelCallback(InputAction.CallbackContext context)
2262+
{
2263+
m_SubmitCancelState.device = context.control.device;
22482264
}
22492265

22502266
private void OnTrackedDeviceOrientationCallback(InputAction.CallbackContext context)
@@ -2441,6 +2457,13 @@ public override Vector2 ConvertPointerEventScrollDeltaToTicks(Vector2 scrollDelt
24412457

24422458
#endif
24432459

2460+
#if UNITY_INPUT_SYSTEM_INPUT_MODULE_NON_KEYBOARD
2461+
public override bool IsNonKeyboardNavigationEvent(BaseEventData eventData)
2462+
{
2463+
return eventData is INavigationEventData eed && eed.device is not Keyboard;
2464+
}
2465+
#endif
2466+
24442467
private void HookActions()
24452468
{
24462469
if (m_ActionsHooked)
@@ -2458,6 +2481,8 @@ private void HookActions()
24582481
m_OnScrollWheelDelegate = OnScrollCallback;
24592482
if (m_OnMoveDelegate == null)
24602483
m_OnMoveDelegate = OnMoveCallback;
2484+
if (m_OnSubmitCancelDelegate == null)
2485+
m_OnSubmitCancelDelegate = OnSubmitCancelCallback;
24612486
if (m_OnTrackedDeviceOrientationDelegate == null)
24622487
m_OnTrackedDeviceOrientationDelegate = OnTrackedDeviceOrientationCallback;
24632488
if (m_OnTrackedDevicePositionDelegate == null)
@@ -2479,6 +2504,8 @@ private void SetActionCallbacks(bool install)
24792504
m_ActionsHooked = install;
24802505
SetActionCallback(m_PointAction, m_OnPointDelegate, install);
24812506
SetActionCallback(m_MoveAction, m_OnMoveDelegate, install);
2507+
SetActionCallback(m_SubmitAction, m_OnSubmitCancelDelegate, install);
2508+
SetActionCallback(m_CancelAction, m_OnSubmitCancelDelegate, install);
24822509
SetActionCallback(m_LeftClickAction, m_OnLeftClickDelegate, install);
24832510
SetActionCallback(m_RightClickAction, m_OnRightClickDelegate, install);
24842511
SetActionCallback(m_MiddleClickAction, m_OnMiddleClickDelegate, install);
@@ -2594,6 +2621,7 @@ private struct InputActionReferenceState
25942621

25952622
private Action<InputAction.CallbackContext> m_OnPointDelegate;
25962623
private Action<InputAction.CallbackContext> m_OnMoveDelegate;
2624+
private Action<InputAction.CallbackContext> m_OnSubmitCancelDelegate;
25972625
private Action<InputAction.CallbackContext> m_OnLeftClickDelegate;
25982626
private Action<InputAction.CallbackContext> m_OnRightClickDelegate;
25992627
private Action<InputAction.CallbackContext> m_OnMiddleClickDelegate;
@@ -2611,6 +2639,7 @@ private struct InputActionReferenceState
26112639

26122640
// Navigation-type input.
26132641
private NavigationModel m_NavigationState;
2642+
private SubmitCancelModel m_SubmitCancelState;
26142643

26152644
[NonSerialized] private GameObject m_LocalMultiPlayerRoot;
26162645

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@ internal struct NavigationModel
1010
public MoveDirection lastMoveDirection;
1111
public float lastMoveTime;
1212
public AxisEventData eventData;
13+
public InputDevice device;
1314

1415
public void Reset()
1516
{
1617
move = Vector2.zero;
1718
}
1819
}
20+
21+
internal struct SubmitCancelModel
22+
{
23+
public BaseEventData eventData;
24+
public InputDevice device;
25+
}
1926
}
2027
#endif

Packages/com.unity.inputsystem/InputSystem/Unity.InputSystem.asmdef

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@
9292
"expression": "6000.0.11",
9393
"define": "UNITY_INPUT_SYSTEM_INPUT_MODULE_SCROLL_DELTA"
9494
},
95+
{
96+
"name": "Unity",
97+
"expression": "6000.1.0b2",
98+
"define": "UNITY_INPUT_SYSTEM_INPUT_MODULE_NON_KEYBOARD"
99+
},
95100
{
96101
"name": "Unity",
97102
"expression": "6000.0.15",

0 commit comments

Comments
 (0)