docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class MultiTapInteraction

    Interaction that requires multiple taps (press and release within tapTime) spaced no more than tapDelay seconds apart. This equates to a chain of TapInteraction with a maximum delay between each tap.

    Inheritance
    object
    MultiTapInteraction
    Implements
    IInputInteraction<float>
    IInputInteraction
    Namespace: UnityEngine.InputSystem.Interactions
    Assembly: Unity.InputSystem.dll
    Syntax
    public class MultiTapInteraction : IInputInteraction<float>, IInputInteraction
    Remarks

    The interaction goes into Started on the first press and then will not trigger again until either the full tap sequence is performed (in which case the interaction triggers Performed) or the multi-tap is aborted by a timeout being hit (in which case the interaction will trigger Canceled).

    Fields

    pressPoint

    Magnitude threshold that must be crossed by an actuated control for the control to be considered pressed.

    Declaration
    public float pressPoint
    Field Value
    Type Description
    float
    Remarks

    If this is less than or equal to 0 (the default), defaultButtonPressPoint is used instead.

    See Also
    EvaluateMagnitude()

    tapCount

    The number of taps required to perform the interaction.

    Declaration
    [Tooltip("How many taps need to be performed in succession. Two means double-tap, three means triple-tap, and so on.")]
    public int tapCount
    Field Value
    Type Description
    int
    Remarks

    How many taps need to be performed in succession. Two means double-tap, three means triple-tap, and so on.

    tapDelay

    The time in seconds which is allowed to pass between taps.

    Declaration
    [Tooltip("The maximum delay (in seconds) allowed between each tap. If this time is exceeded, the multi-tap is canceled.")]
    public float tapDelay
    Field Value
    Type Description
    float
    Remarks

    If this time is exceeded, the multi-tap interaction is canceled. If this value is equal to or smaller than zero, the input system will use the duplicate value of tapTime instead.

    tapTime

    The time in seconds within which the control needs to be pressed and released to perform the interaction.

    Declaration
    [Tooltip("The maximum time (in seconds) allowed to elapse between pressing and releasing a control for it to register as a tap.")]
    public float tapTime
    Field Value
    Type Description
    float
    Remarks

    If this value is equal to or smaller than zero, the input system will use (defaultTapTime) instead.

    Methods

    Process(ref InputInteractionContext)

    Perform processing of the interaction in response to input.

    Declaration
    public void Process(ref InputInteractionContext context)
    Parameters
    Type Name Description
    InputInteractionContext context
    Remarks

    This method is called whenever a control referenced in the binding that the interaction sits on changes value. The interaction is expected to process the value change and, if applicable, call Started() and/or its related methods to initiate a state change.

    Note that if "control disambiguation" (i.e. the process where if multiple controls are bound to the same action, the system decides which control gets to drive the action at any one point) is in effect -- i.e. when either Button or Value are used but not if PassThrough is used -- inputs that the disambiguation chooses to ignore will cause this method to not be called.

    Note that this method is called on the interaction even when there are multiple interactions and the interaction is not the one currently in control of the action (because another interaction that comes before it in the list had already started the action). Each interaction will get processed independently and the action will decide when to use which interaction to drive the action as a whole.

    // Processing for an interaction that will perform the action only if a control
    // is held at least at 3/4 actuation for at least 1 second.
    public void Process(ref InputInteractionContext context)
    {
    var control = context.control;

             // See if we're currently tracking a control.
             if (m_Control != null)
             {
                 // Ignore any input on a control we're not currently tracking.
                 if (m_Control != control)
                     return;
    
                 // Check if the control is currently actuated past our 3/4 threshold.
                 var isStillActuated = context.ControlIsActuated(0.75f);
    
                 // See for how long the control has been held.
                 var actuationTime = context.time - context.startTime;
    
                 if (!isStillActuated)
                 {
                     // Control is no longer actuated above 3/4 threshold. If it was held
                     // for at least a second, perform the action. Otherwise cancel it.
    
                     if (actuationTime >= 1)
                         context.Performed();
                     else
                         context.Cancelled();
                 }
    
                 // Control changed value somewhere above 3/4 of its actuation. Doesn't
                 // matter to us so no change.
             }
             else
             {
                 // We're not already tracking a control. See if the control that just triggered
                 // is actuated at least 3/4th of its way. If so, start tracking it.
    
                 var isActuated = context.ControlIsActuated(0.75f);
                 if (isActuated)
                 {
                     m_Control = context.control;
                     context.Started();
                 }
             }
         }
    
         InputControl m_Control;
    
         public void Reset()
         {
             m_Control = null;
         }</code></pre></example>
    

    Reset()

    Reset state that the interaction may hold. This should put the interaction back in its original state equivalent to no input yet having been received.

    Declaration
    public void Reset()

    Implements

    IInputInteraction<TValue>
    IInputInteraction
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)