Version: 2022.1

Touch

struct in UnityEngine

切换到手册

描述

用于描述触摸屏幕的手指状态的结构。

Devices can track a number of different pieces of data about a touch on a touchscreen, including its phase of the touch lifecycle, its position and whether the touch was a single contact or several taps. Furthermore, the continuity of a touch between frame updates can be detected by the device, so a consistent ID number can be reported across frames and used to determine how a particular finger is moving.

The touch lifecycle describes the state of a touch in any given frame: Began - A user has touched their finger to the screen this frame Stationary - A finger is on the screen but the user has not moved it this frame Moved - A user moved their finger this frame Ended - A user lifted their finger from the screen this frame Cancelled - The touch was interrupted this frame Unity 使用 Touch 结构存储与单次接触相关的数据,此结构由 Input.GetTouch 函数返回。每次帧更新都需要刷新 GetTouch 调用,以便从设备获取最新触摸信息,但可以使用 fingerId 属性标识帧之间的相同触摸操作。

Note: On iOS devices, any Touch information that is being held in memory (for example, when you are part way through the touch lifecycle) will be lost if the application is minimized. This happens because iOS calls ResetTouch() and wipes all touch data from memory. The lifecycle of that touch ends there and any functionality that relies on later phases of the touch lifecycle is not executed. If you experience this problem, you should move the functionality that is not being executed into MonoBehaviour.OnApplicationFocus or MonoBehaviour.OnApplicationPause.

另请参阅:Input.GetTouchTouchPhase 枚举。

变量

altitudeAngle0 弧度值指示触笔平行于表面,pi/2 指示垂直。
azimuthAngle0 弧度值指示触笔指向沿着设备 X 轴方向。
deltaPosition自上次像素坐标更改以来的位置增量。
deltaTime自记录的 Touch 值上次更改以来经过的时间。
fingerId触摸的唯一索引。
maximumPossiblePressure平台的最大可能压力值。如果 Input.touchPressureSupported 返回 false,此属性的值将始终为 1.0f。
phase描述触摸阶段。
position触摸在屏幕空间中的位置(像素坐标)。
pressure当前应用于触摸的压力大小。1.0f 被视为平均触摸压力。如果 Input.touchPressureSupported 返回 false,此属性的值将始终为 1.0f。
radius触摸半径的估计值。加上 radiusVariance 可获得最大触摸大小,减去它可获得最小触摸大小。
radiusVariance此值确定触摸半径的精度。半径加上此值可获得最大触摸大小,减去它可获得最小触摸大小。
rawPosition触摸触点在屏幕空间中的第一个位置(像素坐标)。
tapCount点击次数。
type用于指示触摸是 Direct、Indirect(或远程)还是 Stylus 类型的值。