-
Notifications
You must be signed in to change notification settings - Fork 330
NEW: Add InputSystemProvider for InputForUI #1679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* Add dispatch of navigation events * Fix formatting * Unifies GetEventSource() for callback context and devices * Use DispatchFromCallback and clean todos
* Update renaming of Event.CompareType * Add Next/Previous navigation events repetition Currently it doesn't deal with keys other than tab and shift+tab. Discussion needs to happen to allow configuration for this with the Input System.
| InputEventPartialProvider m_InputEventPartialProvider; | ||
|
|
||
| private Configuration _cfg; | ||
| Configuration m_Cfg; | ||
|
|
||
| private InputActionAsset _inputActionAsset; | ||
| private InputActionReference _pointAction; | ||
| private InputActionReference _moveAction; | ||
| private InputActionReference _submitAction; | ||
| private InputActionReference _cancelAction; | ||
| private InputActionReference _leftClickAction; | ||
| private InputActionReference _middleClickAction; | ||
| private InputActionReference _rightClickAction; | ||
| private InputActionReference _scrollWheelAction; | ||
| InputActionAsset m_InputActionAsset; | ||
| InputActionReference m_PointAction; | ||
| InputActionReference m_MoveAction; | ||
| InputActionReference m_SubmitAction; | ||
| InputActionReference m_CancelAction; | ||
| InputActionReference m_LeftClickAction; | ||
| InputActionReference m_MiddleClickAction; | ||
| InputActionReference m_RightClickAction; | ||
| InputActionReference m_ScrollWheelAction; | ||
|
|
||
| InputAction _nextPreviousAction; | ||
| InputAction m_NextPreviousAction; | ||
|
|
||
| List<Event> _events = new List<Event>(); | ||
| List<Event> m_Events = new List<Event>(); | ||
|
|
||
| private PointerState _mouseState; | ||
| PointerState m_MouseState; | ||
|
|
||
| private PointerState _penState; | ||
| private bool _seenPenEvents; | ||
| PointerState m_PenState; | ||
| bool m_SeenPenEvents; | ||
|
|
||
| private PointerState _touchState; | ||
| private bool _seenTouchEvents; | ||
| PointerState m_TouchState; | ||
| bool m_SeenTouchEvents; | ||
|
|
||
| private const float kSmallestReportedMovementSqrDist = 0.01f; | ||
| const float k_SmallestReportedMovementSqrDist = 0.01f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for these changes 🙏 !
jfreire-unity
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm approving this because it works. Even though I think there's opportunity to refactor this into a more readable state in a following PR. Since we're trying to fix some CI issues, I don't want to delay the merging of the code into develop.
IMO we can discuss improvements next week @jamesmcgill
|
|
||
| FocusOnRenameTextField(); | ||
| e.PreventDefault(); | ||
| e.StopPropagation(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to see this warning fix :)
lyndon-unity
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a reasonable initial implemention - some feedback comments but nothing critical to update in this PR.
| { | ||
| // Only if InputSystem is enabled in the PlayerSettings do we set it as the provider. | ||
| // This includes situations where both InputManager and InputSystem are enabled. | ||
| #if ENABLE_INPUT_SYSTEM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this ifdef be wider to exclude more of the code.
|
|
||
| EventModifiers m_EventModifiers => m_InputEventPartialProvider._eventModifiers; | ||
|
|
||
| DiscreteTime m_CurrentTime => (DiscreteTime)Time.timeAsRational; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly nervous about when this timer wraps but not something to hold up this first PR
| m_TouchState.Reset(); | ||
| m_SeenTouchEvents = false; | ||
|
|
||
| // TODO should UITK somehow override this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Could revise to say in future UITK will be able to override this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But find here since we agreed with UI team this is ok for first pass.
| direction = direction, | ||
| timestamp = currentTime, | ||
| eventSource = GetEventSource(GetActiveDeviceFromDirection(direction)), | ||
| playerId = k_DefaultPlayerId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this is a fixed value at the moment so will need updating later but fine for this PR
| return (move, axisWasPressed); | ||
| } | ||
|
|
||
| NavigationEvent.Direction ReadNextPreviousDirection() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered this returning a tuple like the prior function to avoid the use of m_NextPreviousAction directly in the DirectionNavigation function above
axesButtonWerePressed = m_NextPreviousAction.WasPressedThisFrame();
Not critical for this PR
| })); | ||
| } | ||
|
|
||
| void OnLeftClickPerformed(InputAction.CallbackContext ctx) => OnClickPerformed(ctx, GetEventSource(ctx), PointerEvent.Button.MouseLeft); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do GetEventSource call inside the above OnClickPerformed function and avoid passing as parameter?
|
|
||
| void RegisterNextPreviousAction() | ||
| { | ||
| m_NextPreviousAction = new InputAction(name: "nextPreviousAction", type: InputActionType.Button); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this separate from the actions setup in register actions ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I think I see as its a special case not in the default setup
| // The Next/Previous action is not part of the input actions asset | ||
| UnregisterNextPreviousAction(); | ||
|
|
||
| UnityEngine.Object.Destroy(m_InputActionAsset); // TODO check if this is ok |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we check this is ok ?
Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputSystemProvider.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputSystemProvider.cs
Outdated
Show resolved
Hide resolved
lyndon-unity
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a reasonable initial implemention - some feedback comments but nothing critical to update in this PR.
|
I'm unclear why the test is failing though. Seems ISX backend should be registering and it seemed to work locally for me. As James said this needs investigating |
|
cc @jamesmcgill Since all the required tests are passing, I'm going to merge this into develop even though |
Description
This adds the
InputSystemProviderimplementation for the InputForUI module.The InputForUI module was added to newer Unity Engine versions (2023.2 and above) to better abstract UI components (i.e. UI Toolkit) from the Input implementation.
This is purely an internal api artifact and should not result in any behaviour changes for users.
InputSystemProvideris responsible for providing input to UI frameworks when InputSystem is installed and enables.Changes made
Added the
InputSystemProviderclass which sits in it's own Assembly.Checklist
Before review:
Changed,Fixed,Addedsections.([case %number%](https://issuetracker.unity3d.com/issues/...)).Area_CanDoX,Area_CanDoX_EvenIfYIsTheCase,Area_WhenIDoX_AndYHappens_ThisIsTheResult.During merge:
NEW: ___.FIX: ___.DOCS: ___.CHANGE: ___.RELEASE: 1.1.0-preview.3.