Class VirtualMouseInput
A component that creates a virtual Mouse device and drives its input from gamepad-style inputs. This effectively adds a software mouse cursor.
Inherited Members
Namespace: UnityEngine .InputSystem .UI
Assembly: Unity.InputSystem.dll
Syntax
[AddComponentMenu("Input/Virtual Mouse")]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.inputsystem@1.8/manual/UISupport.html#virtual-mouse-cursor-control")]
public class VirtualMouseInput : MonoBehaviour
Remarks
This component can be used with UIs that are designed for mouse input, i.e. need to be operated with a cursor.
By hooking up the Input
Note that this component does not actually trigger UI input itself. Instead, it creates a virtual Mouse
device which can then be picked up elsewhere (such as by Input
Also note that if there is a Mouse added by the platform, it is not impacted by this component. More specifically, the system mouse cursor will not be moved or otherwise used by this component.
Input from the component is visible in the same frame as the source input on its actions by virtue of using Change(Input
Properties
backButtonAction
Optional button input that determines when forward
Declaration
public InputActionProperty backButtonAction { get; set; }
Property Value
Type | Description |
---|---|
Input |
Input for forward |
See Also
cursorGraphic
The UI graphic element that represents the mouse cursor.
Declaration
public Graphic cursorGraphic { get; set; }
Property Value
Type | Description |
---|---|
Graphic | Graphic element for the software mouse cursor. |
Remarks
If cursor
Also, this UI component implicitly determines the Canvas
that defines the screen area for the cursor.
The canvas that this graphic is on will be looked up using GetComponentInParent
and then the Canvas.pixelRect
of the canvas is used as the bounds for the cursor motion range.
See Also
cursorMode
Determines which cursor representation to use. If this is set to Software
Declaration
public VirtualMouseInput.CursorMode cursorMode { get; set; }
Property Value
Type | Description |
---|---|
Virtual |
Whether the system mouse cursor (if present) should be made to correspond with the virtual mouse position. |
Remarks
Note that regardless of which mode is used for the cursor, mouse input is expected to be picked up from virtual
Note that if Hardware
See Also
cursorSpeed
How many pixels per second the cursor travels in one axis when the respective axis from
stick
Declaration
public float cursorSpeed { get; set; }
Property Value
Type | Description |
---|---|
float | Mouse speed in pixels per second. |
See Also
cursorTransform
Optional transform that will be updated to correspond to the current mouse position.
Declaration
public RectTransform cursorTransform { get; set; }
Property Value
Type | Description |
---|---|
Rect |
Transform to update with mouse position. |
Remarks
This is useful for having a UI object that directly represents the mouse cursor. Simply add both the
VirtualMouseInput
component and an Image
component and hook the RectTransform
component for the UI object into here. The object as a whole will then follow the generated mouse cursor
motion.
See Also
forwardButtonAction
Optional button input that determines when forward
Declaration
public InputActionProperty forwardButtonAction { get; set; }
Property Value
Type | Description |
---|---|
Input |
Input for forward |
See Also
leftButtonAction
Optional button input that determines when left
Declaration
public InputActionProperty leftButtonAction { get; set; }
Property Value
Type | Description |
---|---|
Input |
Input for left |
See Also
middleButtonAction
Optional button input that determines when middle
Declaration
public InputActionProperty middleButtonAction { get; set; }
Property Value
Type | Description |
---|---|
Input |
Input for middle |
See Also
rightButtonAction
Optional button input that determines when right
Declaration
public InputActionProperty rightButtonAction { get; set; }
Property Value
Type | Description |
---|---|
Input |
Input for right |
See Also
scrollSpeed
Multiplier for values received from scroll
Declaration
public float scrollSpeed { get; set; }
Property Value
Type | Description |
---|---|
float | Multiplier for scroll values. |
See Also
scrollWheelAction
Optional Vector2 value input that determines the value of scroll on
virtual
Declaration
public InputActionProperty scrollWheelAction { get; set; }
Property Value
Type | Description |
---|---|
Input |
Input for scroll. |
Remarks
In case you want to only bind vertical scrolling, simply have a Vector2Composite
with only Up
and Down
bound and Left
and Right
deleted or bound to nothing.
See Also
stickAction
The Vector2 stick input that drives the mouse cursor, i.e. position on
virtual
Declaration
public InputActionProperty stickAction { get; set; }
Property Value
Type | Description |
---|---|
Input |
Stick input that drives cursor position. |
Remarks
This should normally be bound to controls such as left
See Also
virtualMouse
The virtual mouse device that the component feeds with input.
Declaration
public Mouse virtualMouse { get; }
Property Value
Type | Description |
---|---|
Mouse | Instance of virtual mouse or |
Remarks
This is only initialized after the component has been enabled for the first time. Note that when subsequently disabling the component, the property will continue to return the mouse device but the device will not be added to the system while the component is not enabled.
See Also
Methods
OnDisable()
Declaration
protected void OnDisable()
See Also
OnEnable()
Declaration
protected void OnEnable()