class in UnityEngine.UIElements
/
Inherits from:UIElements.PointerEventBase_1
/
Implemented in:UnityEngine.UIElementsModule
Sends when a pointer is pressed inside a visual element.
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<T0>
and Pointer events.
Additional resources: PointerMoveEvent, PointerUpEvent, PointerCancelEvent
// 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"); } } }
PointerDownEvent | Constructor. Avoid creating new event instances. Instead, use GetPooled() to get an instance from a pool of reusable event instances. |
Init | Resets the event members to their initial values. |
bubbles | Returns whether this event type bubbles up in the event propagation path during the BubbleUp phase. |
dispatch | Indicates whether the event is being dispatched to a visual element. An event cannot be redispatched while it being dispatched. If you need to recursively dispatch an event, it is recommended that you use a copy of the event. |
imguiEvent | The IMGUIEvent at the source of this event. The source can be null since not all events are generated by IMGUI. |
isImmediatePropagationStopped | Indicates whether StopImmediatePropagation was called for this event. |
isPropagationStopped | Returns true if StopPropagation or StopImmediatePropagation was called for this event. |
originalMousePosition | The original mouse position of the IMGUI event, before it is transformed to the current target local coordinates. |
pooled | Whether the event is allocated from a pool of events. |
propagationPhase | The current propagation phase for this event. |
target | The target visual element that received this event. Unlike currentTarget, this target does not change when the event is sent to other elements along the propagation path. |
timestamp | The time when the event was created, in milliseconds. |
tricklesDown | Returns whether this event is sent down the event propagation path during the TrickleDown phase. |
eventTypeId | See EventBase.eventTypeId. |
actionKey | Gets a boolean value that indicates whether the platform-specific action key is pressed. |
altitudeAngle | Gets the angle of the stylus relative to the surface, in radians |
altKey | Gets a boolean value that indicates whether the Alt key is pressed. |
azimuthAngle | Gets the angle of the stylus relative to the x-axis, in radians. |
button | Gets a value that indicates which mouse button was pressed or released (if any) to cause this event: 0 is the left button, 1 is the right button, 2 is the middle button. A negative value indicates that no mouse button changed state during this event. |
clickCount | Gets the number of consecutive times a down-up sequence was executed in a short amount of time with the same pointer ID and button. |
commandKey | Gets a boolean value that indicates whether the Windows/Cmd key is pressed. |
ctrlKey | Gets a boolean value that indicates whether the Ctrl key is pressed. |
currentTarget | Gets the current target of the event. |
deltaPosition | Gets the difference between the pointer's position during the previous pointer event and its position during the current pointer event. |
deltaTime | Gets the amount of time that has elapsed since the last recorded change in pointer values, in seconds. |
isPrimary | Gets a boolean value that indicates whether the pointer is a primary pointer. True means the pointer is a primary pointer. False means it isn't. |
localPosition | Gets the pointer position in the current target's coordinate system. |
modifiers | Gets flags that indicate whether modifier keys (Alt, Ctrl, Shift, Windows/Cmd) are pressed. |
penStatus | Specifies the state of the pen. For example, whether the pen is in contact with the screen or tablet, whether the pen is inverted, and whether buttons are pressed. On macOS, penStatus will not reflect changes to button mappings. |
pointerId | Gets the identifier of the pointer that sent the event. |
pointerType | Gets the type of pointer that created the event. |
position | Gets the pointer position in the panel coordinate system. |
pressedButtons | Gets a bitmask that describes the buttons that are currently pressed. |
pressure | Gets the amount of pressure currently applied by a touch. |
radius | Gets an estimate of the radius of a touch. |
radiusVariance | Gets the accuracy of the touch radius. |
shiftKey | Gets a boolean value that indicates whether the Shift key is pressed. |
tangentialPressure | Gets the pressure applied to an additional pressure-sensitive control on the stylus. |
tilt | Specifies the angle of the pen relative to the X and Y axis respectively, in radians. |
twist | Gets the rotation of the stylus around its axis, in radians. |
StopImmediatePropagation | Stops the propagation of the event to other targets, and prevents other subscribers to the event on this target to receive the event. |
StopPropagation | Stops the propagation of the event to other targets. All subscribers to the event on this target still receive the event. |
Dispose | Implementation of IDispose. |
PostDispatch | Allows subclasses to perform custom logic after the event has been dispatched. |
PreDispatch | Allows subclasses to perform custom logic before the event is dispatched. |
RegisterEventType | Registers an event class to the event type system. |
GetPooled | Gets an event from the event pool. Use this function instead of creating new events. Events obtained using this method need to be released back to the pool. You can use Dispose() to release them. |
TypeId | Retrieves the type ID for this event instance. |
GetPooled | Gets an event from the event pool and initializes it with the given values. Use this function instead of creating new events. Events obtained using this method need to be released back to the pool. You can use Dispose() to release them. |