Class TouchControl
A control representing a touch contact.
Inherited Members
Namespace: UnityEngine.InputSystem.Controls
Assembly: Unity.InputSystem.dll
Syntax
public class TouchControl : InputControl<TouchState>
Remarks
Note that unlike most other control types, TouchControls
do not have
a flexible memory layout. They are hardwired to TouchState and
will not work correctly with a different memory layouts. Additional fields may
be appended to the struct but what's there in the struct has to be located
at exactly those memory addresses.
Constructors
TouchControl()
Default-initialize the touch control.
Declaration
public TouchControl()
Remarks
Sets the format to "TOUC"
.
Properties
delta
Screen-space motion delta of the touch.
Declaration
public DeltaControl delta { get; set; }
Property Value
Type | Description |
---|---|
DeltaControl | Control representing the screen-space motion delta of the touch. |
Remarks
This is either supplied directly by the underlying platform or computed on the fly by Touchscreen from the last known position of the touch.
Note that deltas have behaviors attached to them different from most other controls. See delta for details.
See Also
displayIndex
Gets the index of the display that was touched. https://docs.unity3d.com/ScriptReference/Display.html
Declaration
public IntegerControl displayIndex { get; set; }
Property Value
Type | Description |
---|---|
IntegerControl |
indirectTouch
Whether the touch comes from a source other than direct contact with the touch surface.
Declaration
public ButtonControl indirectTouch { get; set; }
Property Value
Type | Description |
---|---|
ButtonControl | Control indicating whether the touch was generated indirectly. |
Remarks
Indirect touches can be generated with a stylus, for example.
isInProgress
Whether a touch on the control is currently is progress.
Declaration
public bool isInProgress { get; }
Property Value
Type | Description |
---|---|
bool | If true, a touch is in progress, i.e. has a phase of Began, Moved, or Canceled. |
phase
Current phase of the touch.
Declaration
public TouchPhaseControl phase { get; set; }
Property Value
Type | Description |
---|---|
TouchPhaseControl | Control representing the current phase of the touch. |
Remarks
This will be None if no touch has been registered on the control yet or if the control has been reset to its default state.
See Also
position
Absolute screen-space position on the touch surface.
Declaration
public Vector2Control position { get; set; }
Property Value
Type | Description |
---|---|
Vector2Control | Control representing the screen-space of the touch. |
See Also
press
Button that indicates whether there is currently an ongoing touch contact on the control. When touch is ongoing, button will be 1, otherwise button will be 0.
Declaration
public TouchPressControl press { get; set; }
Property Value
Type | Description |
---|---|
TouchPressControl | Control representing an ongoing touch contact. |
Remarks
This control simply monitors phase and will read as 1 whenever the phase is Began, Moved, or Stationary.
See Also
pressure
Normalized pressure of the touch against the touch surface.
Declaration
public AxisControl pressure { get; set; }
Property Value
Type | Description |
---|---|
AxisControl | Control representing the pressure level of the touch. |
Remarks
Not all touchscreens are pressure-sensitive. If unsupported, this control will remain at default value.
In general, touch pressure is supported on mobile platforms only.
Note that it is possible for the value to go above 1 even though it is considered normalized. The reason is that calibration on the system can put the maximum pressure point below the physically supported maximum value.
See Also
radius
Screen-space radius of the touch.
Declaration
public Vector2Control radius { get; set; }
Property Value
Type | Description |
---|---|
Vector2Control | Control representing the horizontal and vertical extents of the touch contact. |
Remarks
If supported by the device, this reports the size of the touch contact based on its
position center point. If not supported, this will be default(Vector2)
.
See Also
startPosition
Screen-space position where the touch started.
Declaration
public Vector2Control startPosition { get; set; }
Property Value
Type | Description |
---|---|
Vector2Control | Control representing the start position of the touch. |
See Also
startTime
Time in seconds on the same timeline as Time.realTimeSinceStartup
when the touch began.
Declaration
public DoubleControl startTime { get; set; }
Property Value
Type | Description |
---|---|
DoubleControl | Control representing the start time of the touch. |
Remarks
See Also
tap
Whether the touch has performed a tap.
Declaration
public ButtonControl tap { get; set; }
Property Value
Type | Description |
---|---|
ButtonControl | Control that indicates whether the touch has tapped the screen. |
Remarks
A tap is defined as a touch that begins and ends within defaultTapTime and stays within tapRadius of its startPosition. If this is the case for a touch, this button is set to 1 at the time the touch goes to phase Ended.
The button resets to 0 only when another touch is started on the control or when the control is reset.
See Also
tapCount
Number of times that the touch has been tapped in succession.
Declaration
public IntegerControl tapCount { get; set; }
Property Value
Type | Description |
---|---|
IntegerControl | Control that indicates how many taps have been performed one after the other. |
Remarks
Successive taps have to come within multiTapDelayTime for them to increase the tap count. I.e. if a new tap finishes within that time after startTime of the previous touch, the tap count is increased by one. If more than multiTapDelayTime passes after a tap with no successive tap, the tap count is reset to zero.
touchId
The ID of the touch contact as reported by the underlying system.
Declaration
public IntegerControl touchId { get; set; }
Property Value
Type | Description |
---|---|
IntegerControl | Control reading out the ID of the touch. |
Remarks
Each touch contact that is made with the screen receives its own unique ID which is normally assigned by the underlying platform.
Note a platform may reuse touch IDs after their respective touches have finished. This means that the guarantee of uniqueness is only made with respect to currently ongoing touches.
See Also
Methods
FinishSetup()
Perform final initialization tasks after the control hierarchy has been put into place.
Declaration
protected override void FinishSetup()
Overrides
Remarks
This method can be overridden to perform control- or device-specific setup work. The most common use case is for looking up child controls and storing them in local getters.
public class MyDevice : InputDevice
{
public ButtonControl button { get; private set; }
public AxisControl axis { get; private set; }
protected override void OnFinishSetup()
{
// Cache controls in getters.
button = GetChildControl("button");
axis = GetChildControl("axis");
}
}</code></pre></example>
ReadUnprocessedValueFromState(void*)
Declaration
public override TouchState ReadUnprocessedValueFromState(void* statePtr)
Parameters
Type | Name | Description |
---|---|---|
void* | statePtr |
Returns
Type | Description |
---|---|
TouchState |
Overrides
WriteValueIntoState(TouchState, void*)
Declaration
public override void WriteValueIntoState(TouchState value, void* statePtr)
Parameters
Type | Name | Description |
---|---|---|
TouchState | value | |
void* | statePtr |