Class UIInputModule
Base class for input modules that send UI input.
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit.UI
Syntax
[DefaultExecutionOrder(-200)]
public abstract class UIInputModule : BaseInputModule
Remarks
Multiple input modules may be placed on the same event system. In such a setup, the modules will synchronize with each other.
Properties
clickSpeed
The maximum time (in seconds) between two mouse presses for it to be consecutive click.
Declaration
public float clickSpeed { get; set; }
Property Value
Type | Description |
---|---|
Single |
moveDeadzone
The absolute value required by a move action on either axis required to trigger a move event.
Declaration
public float moveDeadzone { get; set; }
Property Value
Type | Description |
---|---|
Single |
repeatDelay
The Initial delay (in seconds) between an initial move action and a repeated move action.
Declaration
public float repeatDelay { get; set; }
Property Value
Type | Description |
---|---|
Single |
repeatRate
The speed (in seconds) that the move action repeats itself once repeating.
Declaration
public float repeatRate { get; set; }
Property Value
Type | Description |
---|---|
Single |
trackedDeviceDragThresholdMultiplier
Scales the pixelDragThreshold, for tracked devices, to make selection easier.
Declaration
public float trackedDeviceDragThresholdMultiplier { get; set; }
Property Value
Type | Description |
---|---|
Single |
trackedScrollDeltaMultiplier
Scales the scrollDelta in event data, for tracked devices, to scroll at an expected speed.
Declaration
public float trackedScrollDeltaMultiplier { get; set; }
Property Value
Type | Description |
---|---|
Single |
uiCamera
The Camera that Unity uses to perform ray casts when determining the screen space location of a tracked device cursor.
Declaration
public Camera uiCamera { get; set; }
Property Value
Type | Description |
---|---|
Camera |
Methods
ActivateModule()
Called by EventSystem
when the input module is made current.
Declaration
public override void ActivateModule()
Overrides
DoProcess()
Process the current tick for the module.
Declaration
protected virtual void DoProcess()
Remarks
Executed once per Update call. Override for custom processing.
See Also
IsPointerOverGameObject(Int32)
Is the pointer with the given ID over an EventSystem object?
Declaration
public override bool IsPointerOverGameObject(int pointerId)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pointerId | ID of the XR device pointer, mouse pointer or touch registered with the UIInputModule.
Meaning this should correspond to either PointerEventData. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the given pointer is currently hovering over a |
Overrides
Remarks
The pointer IDs are generated at runtime by the UIInputModule as devices are registered. Calling this method without any parameters will attempt to use the Left Mouse Button and will likely result in unexpected behavior. A negative pointerId value will be interpreted as "any pointer" and will return true if any XR pointer is currently over a GameObject. Note: The IDs used to check for interaction are not the same as standard InputDevice device IDs.
Examples
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.XR.Interaction.Toolkit.UI;
public class ClickExample : MonoBehaviour
{
[SerializeField]
UIInputModule inputModule;
private void OnEnable()
{
if (inputModule != null)
{
inputModule.pointerClick += OnDeviceButtonClick;
}
}
private void OnDisable()
{
if (inputModule != null)
{
inputModule.pointerClick -= OnDeviceButtonClick;
}
}
// This method will fire after registering with the UIInputModule callbacks. The UIInputModule will
// pass the PointerEventData for the device responsible for triggering the callback and can be used to
// find the pointerId registered with the EventSystem for that device-specific event.
private void OnDeviceButtonClick(GameObject selected, PointerEventData pointerData)
{
if (EventSystem.current.IsPointerOverGameObject(pointerData.pointerId))
{
Debug.Log($"Clicked on {EventSystem.current.currentSelectedGameObject}", this);
}
}
}
Process()
Declaration
public override void Process()
Overrides
SendUpdateEventToSelectedObject()
Sends an update event to the currently selected object.
Declaration
protected bool SendUpdateEventToSelectedObject()
Returns
Type | Description |
---|---|
Boolean | Returns whether the update event was used by the selected object. |
Update()
See MonoBehaviour.
Declaration
protected virtual void Update()
Remarks
Processing is postponed from earlier in the frame (EventSystem has a
script execution order of -1000
) until this Update to allow other systems to
update the poses that will be used to generate the ray casts used by this input module.
For Ray Interactor, it must wait until after the Controller pose updates and Locomotion
moves the Rig in order to generate the current sample points used to create the rays used
for this frame. Those positions will be determined during DoProcess().
Ray Interactor needs the UI ray casts to be completed by the time XRInteractionManager
calls into GetValidTargets(List<IXRInteractable>) since that is dependent on
whether a UI hit was closer than a 3D hit. This processing must therefore be done
between Locomotion and PreprocessInteractor(XRInteractionUpdateOrder.UpdatePhase) to minimize latency.
Events
beginDrag
This occurs when a drag first occurs on an element.
Declaration
public event Action<GameObject, PointerEventData> beginDrag
Event Type
Type | Description |
---|---|
Action<GameObject, PointerEventData> |
cancel
This occurs when the cancel button is pressed.
Declaration
public event Action<GameObject, BaseEventData> cancel
Event Type
Type | Description |
---|---|
Action<GameObject, BaseEventData> |
drag
This occurs every frame while dragging an element.
Declaration
public event Action<GameObject, PointerEventData> drag
Event Type
Type | Description |
---|---|
Action<GameObject, PointerEventData> |
drop
This occurs when a dragged element is dropped on a drop handler.
Declaration
public event Action<GameObject, PointerEventData> drop
Event Type
Type | Description |
---|---|
Action<GameObject, PointerEventData> |
endDrag
This occurs on the last frame an element is dragged.
Declaration
public event Action<GameObject, PointerEventData> endDrag
Event Type
Type | Description |
---|---|
Action<GameObject, PointerEventData> |
finalizeRaycastResults
Calls the methods in its invocation list after the input module collects a list of type RaycastResult, but before the results are used. Note that not all fields of the event data are still valid or up to date at this point in the UI event processing. This event can be used to read, modify, or reorder results. After the event, the first result in the list with a non-null GameObject will be used.
Declaration
public event Action<PointerEventData, List<RaycastResult>> finalizeRaycastResults
Event Type
Type | Description |
---|---|
Action<PointerEventData, List<RaycastResult>> |
initializePotentialDrag
This occurs when a potential drag occurs on an element.
Declaration
public event Action<GameObject, PointerEventData> initializePotentialDrag
Event Type
Type | Description |
---|---|
Action<GameObject, PointerEventData> |
move
This occurs when the move axis is activated.
Declaration
public event Action<GameObject, AxisEventData> move
Event Type
Type | Description |
---|---|
Action<GameObject, AxisEventData> |
pointerClick
This occurs when a select button click occurs while a UI pointer is hovering an element.
Declaration
public event Action<GameObject, PointerEventData> pointerClick
Event Type
Type | Description |
---|---|
Action<GameObject, PointerEventData> |
pointerDown
This occurs when a select button down occurs while a UI pointer is hovering an element. This event is executed using ExecuteEvents.ExecuteHierarchy when sent to the target element.
Declaration
public event Action<GameObject, PointerEventData> pointerDown
Event Type
Type | Description |
---|---|
Action<GameObject, PointerEventData> |
pointerEnter
This occurs when a UI pointer enters an element.
Declaration
public event Action<GameObject, PointerEventData> pointerEnter
Event Type
Type | Description |
---|---|
Action<GameObject, PointerEventData> |
pointerExit
This occurs when a UI pointer exits an element.
Declaration
public event Action<GameObject, PointerEventData> pointerExit
Event Type
Type | Description |
---|---|
Action<GameObject, PointerEventData> |
pointerMove
This occurs while a UI pointer is moving over elements.
Declaration
public event Action<GameObject, PointerEventData> pointerMove
Event Type
Type | Description |
---|---|
Action<GameObject, PointerEventData> |
Remarks
This may induce performance penalties due to the frequency in which this event gets called and should be used with that consideration in mind. Only invoked in Unity 2021.1 and newer.
pointerUp
This occurs when a select button up occurs while a UI pointer is hovering an element.
Declaration
public event Action<GameObject, PointerEventData> pointerUp
Event Type
Type | Description |
---|---|
Action<GameObject, PointerEventData> |
scroll
This occurs when an element is scrolled This event is executed using ExecuteEvents.ExecuteHierarchy when sent to the target element.
Declaration
public event Action<GameObject, PointerEventData> scroll
Event Type
Type | Description |
---|---|
Action<GameObject, PointerEventData> |
submit
This occurs when the submit button is pressed.
Declaration
public event Action<GameObject, BaseEventData> submit
Event Type
Type | Description |
---|---|
Action<GameObject, BaseEventData> |
updateSelected
This occurs on update for the currently selected object.
Declaration
public event Action<GameObject, BaseEventData> updateSelected
Event Type
Type | Description |
---|---|
Action<GameObject, BaseEventData> |