Skip to content

Conversation

@jamesmcgill
Copy link
Collaborator

Description

This adds the InputSystemProvider implementation 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.

InputSystemProvider is responsible for providing input to UI frameworks when InputSystem is installed and enables.

Changes made

Added the InputSystemProvider class which sits in it's own Assembly.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • FogBugz ticket attached, example ([case %number%](https://issuetracker.unity3d.com/issues/...)).
    • FogBugz is marked as "Resolved" with next release version correctly set.
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

Dmytro Ivanov and others added 30 commits April 12, 2023 16:48
* 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.
Comment on lines 15 to 41
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;
Copy link
Collaborator

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 🙏 !

Copy link
Collaborator

@jfreire-unity jfreire-unity left a 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();
Copy link
Collaborator

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 :)

Copy link
Collaborator

@lyndon-unity lyndon-unity left a 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
Copy link
Collaborator

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;
Copy link
Collaborator

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?
Copy link
Collaborator

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

Copy link
Collaborator

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,
Copy link
Collaborator

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()
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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 ?

Copy link
Collaborator

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
Copy link
Collaborator

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 ?

Copy link
Collaborator

@lyndon-unity lyndon-unity left a 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.

@lyndon-unity
Copy link
Collaborator

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

@jfreire-unity
Copy link
Collaborator

cc @jamesmcgill Since all the required tests are passing, I'm going to merge this into develop even though trunk tests currently fail as discussed with @lyndon-unity today to speed up the release process.

@jfreire-unity jfreire-unity merged commit 32aee68 into develop May 23, 2023
@jfreire-unity jfreire-unity deleted the dmytro/common-input-api-for-ui branch May 23, 2023 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants