-
Notifications
You must be signed in to change notification settings - Fork 326
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
base: develop
Are you sure you want to change the base?
Changes from 4 commits
857e304
3cc804f
dcf359a
b1cf800
b0201e1
bab6e35
c3e5dc3
8f2c237
167eb0f
ff22909
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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; | ||
|
||
private void Start() | ||
{ | ||
EnhancedTouchSupport.Enable(); | ||
} | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.