Skip to content

NEW: MouseEvents for InputSystem Samples & Tests #2207

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

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

ritamerkl
Copy link
Collaborator

Description

This PR adds tests and samples for the OnMouse events working with the InputSystem. The OnMouse behaviour for the InputSystem is introduced with this PR and this PR should land together (shortly after) it.

Testing status & QA

Only manual testing for the sample.

Overall Product Risks

  • Complexity: 1
  • Halo Effect: 1

Comments to reviewers

Please review together with https://github.cds.internal.unity3d.com/unity/unity/pull/73198.

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.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • 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.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

@codecov-github-com
Copy link

codecov-github-com bot commented Jul 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

@@             Coverage Diff             @@
##           develop    #2207      +/-   ##
===========================================
+ Coverage    68.11%   68.16%   +0.04%     
===========================================
  Files          367      367              
  Lines        53610    53610              
===========================================
+ Hits         36519    36544      +25     
+ Misses       17091    17066      -25     
Flag Coverage Δ
mac_2021.3_pkg 5.40% <ø> (ø)
mac_2021.3_project 70.37% <ø> (ø)
mac_2022.3_pkg 5.18% <ø> (ø)
mac_2022.3_project 65.23% <ø> (ø)
mac_6000.0_pkg 5.19% <ø> (ø)
mac_6000.0_project 68.03% <ø> (ø)
mac_6000.1_pkg 5.19% <ø> (ø)
mac_6000.1_project 68.03% <ø> (ø)
mac_6000.2_pkg 5.19% <ø> (ø)
mac_6000.2_project 68.02% <ø> (-0.01%) ⬇️
mac_trunk_pkg 5.19% <ø> (ø)
mac_trunk_project 68.08% <ø> (+0.04%) ⬆️
win_2021.3_pkg 5.41% <ø> (ø)
win_2021.3_project 70.44% <ø> (ø)
win_2022.3_pkg 5.18% <ø> (ø)
win_2022.3_project 65.31% <ø> (ø)
win_6000.0_pkg 5.19% <ø> (ø)
win_6000.0_project 68.10% <ø> (ø)
win_6000.1_pkg 5.19% <ø> (ø)
win_6000.1_project 68.10% <ø> (ø)
win_6000.2_pkg 5.19% <ø> (ø)
win_6000.2_project 68.10% <ø> (ø)
win_trunk_pkg 5.19% <ø> (ø)
win_trunk_project 68.11% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Nice work @ritamerkl ! I like the approach and the sample is of reasonable size to test the main functionality. Also really nice to have plenty of tests.

However:

  • This functionality needs to be guarded with defines in asmdef, as this will only be available from 6.3 forward AFAIK. So if I try this PR without the trunk PR, I'll get compilation errors.
  • I would like to see at least 1 test with Touch as well, particularly with more than 1 touch. Mouse and Pen are pretty similar as they are a single pointer.

Comment on lines 29 to 38
var mouse = InputSystem.AddDevice<Mouse>();

var gameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
gameObject.AddComponent<OnMouseEventsTest>();
gameObject.transform.position = Vector3.zero;
var camera = new GameObject("MainCamera").AddComponent<Camera>();
camera.transform.position = new Vector3(0, 0, -2f);
camera.tag = "MainCamera";
var vec = Camera.main.WorldToScreenPoint(gameObject.transform.position);
SetMouse(mouse, new Vector2(vec.x, vec.y), 1f);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find this boilerplate code being repeated amongst tests. Could we create a function for it or combine the tests together?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea, I did that here: b0201e1

@jfreire-unity
Copy link
Collaborator

Nice work @ritamerkl ! I like the approach and the sample is of reasonable size to test the main functionality. Also really nice to have plenty of tests.

However:

  • This functionality needs to be guarded with defines in asmdef, as this will only be available from 6.3 forward AFAIK. So if I try this PR without the trunk PR, I'll get compilation errors.
  • I would like to see at least 1 test with Touch as well, particularly with more than 1 touch. Mouse and Pen are pretty similar as they are a single pointer.

Also there's some CI failures that will need to be addressed. Not sure if it's only because of the lack of defines or if there's any impact on pointer devices functionality.

@ritamerkl
Copy link
Collaborator Author

ritamerkl commented Jul 25, 2025

WIP: working on adding touch samples (multi-touch) & parallel pointers (eg. touch&pen).

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.

2 participants