Skip to content
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.

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

public class OnMouseEventSample : MonoBehaviour
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the intent here is to serve as a sample (and maybe also our own way to manually test or debug this), I would suggest that we have all the supported implicit script mouse event callback functions present in this file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

E.g. missing OnMouseOver, OnMouseEnter, OnMouseExit, OnMouseUp, OnMouseUpAsButton

{
private Vector3 screenPoint;
private Vector3 offset;

void OnMouseDown()
{
if (Pointer.current == null)
return;

screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
float x = Pointer.current.position.x.value;
float y = Pointer.current.position.y.value;
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(x, y, screenPoint.z));
}

void OnMouseDrag()
{
if (Pointer.current == null)
return;

Vector3 curScreenPoint = new Vector3(Pointer.current.position.x.value, Pointer.current.position.y.value, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}
}
2 changes: 2 additions & 0 deletions Assets/Samples/MouseEvents/OnMouseEventSample.cs.meta

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

Loading