PointerDownEvent
Sends when a pointer is pressed inside a visual element.
Read time 4 minutesLast updated 2 days ago
Definition
- Type: Class
- Namespace: UnityEngine.UIElements
- Assembly: UnityEngine.UIElementsModule
- Inherits from: PointerEventBase<PointerDownEvent>
- Implements: IDisposable, IPointerEvent
public sealed class PointerDownEvent : PointerEventBase<PointerDownEvent>, IDisposable, IPointerEvent
Remarks
In a runtime UI, a is sent each time a user touches the screen or presses a mouse button.
PointerDownEventIn an Editor UI, a 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 . Releasing all mouse buttons and pressing a mouse button again sends a new .
PointerDownEventPointerDownEventPointerDownEventA follows the default pointer event propagation path. It trickles down, bubbles up, and is cancellable.
PointerDownEventDisabled elements don't receive this event.
For information about how the relates to other pointer events, refer to PointerEventBase<T> and Pointer events.
PointerDownEventExamples
// 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 |
|---|---|
| Init | Resets the event members to their initial values. |