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
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions Assets/Samples/MouseEvents.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Assets/Samples/MouseEvents/OnMouseEventsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.EnhancedTouch;
using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;

public class OnMouseEventsTest : MonoBehaviour
{
private Vector3 screenPoint;
private Vector3 offset;

void OnMouseDown()
{
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
float x;
float y;
if (Pointer.current != null)
{
x = Pointer.current.position.x.value;
y = Pointer.current.position.y.value;
}
else // Fallback to InputManager if InputSystem is not available
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to support InputManager on this tests? I would assume they are covered by their original tests in trunk...

{
x = Input.mousePosition.x;
y = Input.mousePosition.y;
}
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(x, y, screenPoint.z));
}

void OnMouseDrag()
{
Vector3 curScreenPoint;
if (Pointer.current != null)
curScreenPoint = new Vector3(Pointer.current.position.x.value, Pointer.current.position.y.value, screenPoint.z);
else // Fallback to InputManager if InputSystem is not available
curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);

Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}
}
2 changes: 2 additions & 0 deletions Assets/Samples/MouseEvents/OnMouseEventsTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading