Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
857e304
added a very basic mouse events sample
ritamerkl Jul 17, 2025
3cc804f
added MouseEventScript
ritamerkl Jul 24, 2025
dcf359a
added mouse events test for pen and mouse
ritamerkl Jul 24, 2025
b1cf800
add changelog
ritamerkl Jul 24, 2025
b0201e1
added defines and outsourced code duplication
ritamerkl Jul 25, 2025
bab6e35
mention editor version in changelog
ritamerkl Jul 25, 2025
c3e5dc3
remove enhanced touch enable
ritamerkl Jul 25, 2025
8f2c237
Merge branch 'develop' into mouseevents-samles-tests
ritamerkl Jul 25, 2025
167eb0f
added touch test
ritamerkl Jul 25, 2025
ff22909
added more touch tests
ritamerkl Jul 25, 2025
18b1cc8
added sending pointer data to native for OnMouse events
ritamerkl Aug 22, 2025
042bc00
Merge branch 'develop' into mouseevents-samles-tests
ritamerkl Aug 22, 2025
e4e88bb
remove build
ritamerkl Aug 26, 2025
77c89af
Merge branch 'mouseevents-samles-tests' of https://github.com/Unity-T…
ritamerkl Aug 26, 2025
6429e90
refactored OnMouseEventSample
ritamerkl Aug 26, 2025
9e161b3
added defines
ritamerkl Aug 27, 2025
937d7b6
refactored tests to send events to package queue and reuse for all po…
ritamerkl Aug 27, 2025
b9fcced
set data and trigger sending events both from package
ritamerkl Aug 29, 2025
0bef5d2
added comments to sample code + added hover sample
ritamerkl Sep 8, 2025
0a65443
refactor tests
ritamerkl Sep 12, 2025
e0f10fb
added comments
ritamerkl Sep 12, 2025
a9cff76
Update CHANGELOG.md
ritamerkl Sep 12, 2025
c870b7e
refactored to use TestCase instead of array of parameters
ritamerkl Sep 12, 2025
7b13b3e
remove define version and added custom define
ritamerkl Sep 12, 2025
1c31a39
Merge branch 'develop' into mouseevents-samles-tests
ritamerkl Sep 12, 2025
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.

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

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

private Vector3 startPosition;
private bool wasDragging => Vector3.Distance(startPosition, transform.position) > 0.01f;
private bool selected;

// This logic starts the drag operation and safes the offset of the object position to the cursor position, to preserve the relative position.
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));
startPosition = transform.position;
}

// This logic allows dragging the object.
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;
}

// This can be used to select objects. This logic allows dragging without selection.
private void OnMouseUp()
{
if (wasDragging)
return;

selected = !selected;
gameObject.GetComponent<Renderer>().material.SetColor("_Color", !selected ? Color.blue : Color.white);
}
}
2 changes: 2 additions & 0 deletions Assets/Samples/MouseEvents/OnMouseEventDragSample.cs.meta

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

Loading