Struct Touch | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    Struct Touch

    A high-level representation of a touch which automatically keeps track of a touch over time.

    Namespace: UnityEngine.InputSystem.EnhancedTouch
    Syntax
    public struct Touch : IEquatable<Touch>
    Remarks

    This API obsoletes the need for manually keeping tracking of touch IDs (touchId) and touch phases (phase) in order to tell one touch apart from another.

    Also, this class protects against losing touches. If a touch is shorter-lived than a single input update, Touchscreen may overwrite it with a new touch coming in in the same update whereas this class will retain all changes that happened on the touchscreen in any particular update.

    The API makes a distinction between "fingers" and "touches". A touch refers to one contact state change event, i.e. a finger beginning to touch the screen (Began), moving on the screen (Moved), or being lifted off the screen (Ended or Canceled). A finger, on the other hand, always refers to the Nth contact on the screen.

    A Touch instance is a struct which only contains a reference to the actual data which is stored in unmanaged memory.

    Properties

    activeFingers

    Declaration
    public static ReadOnlyArray<Finger> activeFingers { get; }
    Property Value
    Type Description
    ReadOnlyArray<Finger>

    activeTouches

    All touches that are either on-going as of the current frame or have ended in the current frame.

    Declaration
    public static ReadOnlyArray<Touch> activeTouches { get; }
    Property Value
    Type Description
    ReadOnlyArray<Touch>
    Remarks

    Note that the fact that ended touches are being kept around until the end of a frame means that this array may have more touches than the total number of concurrent touches supported by the system.

    delta

    Declaration
    public Vector2 delta { get; }
    Property Value
    Type Description
    Vector2

    finger

    Declaration
    public Finger finger { get; }
    Property Value
    Type Description
    Finger

    fingers

    Declaration
    public static ReadOnlyArray<Finger> fingers { get; }
    Property Value
    Type Description
    ReadOnlyArray<Finger>
    Remarks

    The length of this array will always correspond to the maximum number of concurrent touches supported by the system.

    history

    History for this specific touch.

    Declaration
    public TouchHistory history { get; }
    Property Value
    Type Description
    TouchHistory
    Remarks

    Unlike touchHistory, this gives the history of this touch only.

    isInProgress

    Declaration
    public bool isInProgress { get; }
    Property Value
    Type Description
    System.Boolean

    isTap

    Declaration
    public bool isTap { get; }
    Property Value
    Type Description
    System.Boolean

    maxHistoryLengthPerFinger

    The amount of history kept for each single touch.

    Declaration
    public static int maxHistoryLengthPerFinger { get; }
    Property Value
    Type Description
    System.Int32
    Remarks

    By default, this is zero meaning that no history information is kept for touches. Setting this to Int32.maxValue will cause all history from the beginning to the end of a touch being kept.

    phase

    Declaration
    public TouchPhase phase { get; }
    Property Value
    Type Description
    TouchPhase

    pressure

    Declaration
    public float pressure { get; }
    Property Value
    Type Description
    System.Single

    radius

    Declaration
    public Vector2 radius { get; }
    Property Value
    Type Description
    Vector2

    screen

    Declaration
    public Touchscreen screen { get; }
    Property Value
    Type Description
    Touchscreen

    screenPosition

    Declaration
    public Vector2 screenPosition { get; }
    Property Value
    Type Description
    Vector2

    screens

    Declaration
    public static IEnumerable<Touchscreen> screens { get; }
    Property Value
    Type Description
    System.Collections.Generic.IEnumerable<Touchscreen>

    startScreenPosition

    Declaration
    public Vector2 startScreenPosition { get; }
    Property Value
    Type Description
    Vector2

    startTime

    Declaration
    public double startTime { get; }
    Property Value
    Type Description
    System.Double

    tapCount

    Declaration
    public int tapCount { get; }
    Property Value
    Type Description
    System.Int32

    time

    Declaration
    public double time { get; }
    Property Value
    Type Description
    System.Double

    touchId

    Declaration
    public int touchId { get; }
    Property Value
    Type Description
    System.Int32

    valid

    Whether this touch record holds valid data.

    Declaration
    public bool valid { get; }
    Property Value
    Type Description
    System.Boolean
    Remarks

    This is true only if the struct instance has been obtained ...

    Methods

    Equals(Object)

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    System.Object obj
    Returns
    Type Description
    System.Boolean
    Overrides
    System.ValueType.Equals(System.Object)

    Equals(Touch)

    Declaration
    public bool Equals(Touch other)
    Parameters
    Type Name Description
    Touch other
    Returns
    Type Description
    System.Boolean

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    System.Int32
    Overrides
    System.ValueType.GetHashCode()

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String
    Overrides
    System.ValueType.ToString()

    Events

    onFingerDown

    Declaration
    public static event Action<Finger> onFingerDown
    Event Type
    Type Description
    System.Action<Finger>

    onFingerMove

    Declaration
    public static event Action<Finger> onFingerMove
    Event Type
    Type Description
    System.Action<Finger>

    onFingerUp

    Declaration
    public static event Action<Finger> onFingerUp
    Event Type
    Type Description
    System.Action<Finger>
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023