Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


PointerDownEvent

Sends when a pointer is pressed inside a visual element.
Read time 4 minutesLast updated 2 days ago

Definition

public sealed class PointerDownEvent : PointerEventBase<PointerDownEvent>, IDisposable, IPointerEvent

Remarks

In a runtime UI, a
PointerDownEvent
is sent each time a user touches the screen or presses a mouse button.
In an Editor UI, a
PointerDownEvent
is sent when a user initially touches the screen or presses a mouse button. However, If the user presses additional mouse buttons (right or middle) without releasing the initial one, the PointerMoveEvents is sent not the
PointerDownEvent
. Releasing all mouse buttons and pressing a mouse button again sends a new
PointerDownEvent
.
A
PointerDownEvent
follows the default pointer event propagation path. It trickles down, bubbles up, and is cancellable.
Disabled elements don't receive this event.
For information about how the
PointerDownEvent
relates to other pointer events, refer to PointerEventBase<T> and Pointer events.

Examples

// This example creates a ClickDetector class to detect a click sequence.namespace UnityEngine.UIElements{ public class ClickDetector : VisualElement { public ClickDetector() { RegisterCallback<PointerDownEvent>(ProcessEvent); RegisterCallback<PointerMoveEvent>(ProcessEvent); RegisterCallback<PointerUpEvent>(ProcessEvent); } private void ProcessEvent<TEvent>(PointerEventBase<TEvent> evt) where TEvent : PointerEventBase<TEvent>, new() { if (evt.eventTypeId == PointerDownEvent.TypeId() && evt.button == 0) { StartClickTracking(evt); } else if (evt.eventTypeId == PointerMoveEvent.TypeId()) { // Button 1 was pressed while another button was already pressed. if (evt.button == 0 && (evt.pressedButtons & 1) == 1) { StartClickTracking(evt); } // Button 1 is released while another button is still pressed. else if (evt.button == 0 && (evt.pressedButtons & 1) == 0) { SendClickEvent(evt); } // Pointer movement detected or button state changed. else { UpdateClickStatus(evt); } } else if (evt.eventTypeId == PointerUpEvent.TypeId() && evt.button == 0) { SendClickEvent(evt); } } private void StartClickTracking(IPointerEvent evt) { Debug.Log("Starting click sequence"); } private void UpdateClickStatus(IPointerEvent evt) { Debug.Log("Tracking"); } private void SendClickEvent(IPointerEvent evt) { Debug.Log("Completed click"); } }}

Constructors

Constructor

Description

PointerDownEvent()Constructor. Avoid creating new event instances. Instead, use GetPooled() to get an instance from a pool of reusable event instances.

Methods

Method

Description

InitResets the event members to their initial values.

Inheritance

Inherited Members