/// <inheritdoc />
    public void Process(ref InputInteractionContext context)
    {
        switch (context.phase)
        {
        case InputActionPhase.Waiting:
        case InputActionPhase.Canceled:
            if (context.ControlIsActuated(PressPointOrDefault) &&
                Time.time >= ignoreInputUntilTime - 0.1f)
            {
                context.Started();
                if (fireImmediately)
                {
                    context.PerformedAndStayStarted();
                }
                ignoreInputUntilTime = Time.time + InitialPauseOrDefault;

                // Check input again when the time elapsed or input changed.
                context.SetTimeout(InitialPauseOrDefault);
            }
            break;

        case InputActionPhase.Started:
            if (!context.ControlIsActuated())
            {
                Cancel(ref context);
            }
            else if (Time.time >= ignoreInputUntilTime - 0.1f)
            {
                // Perform action but stay in the started phase, because we want to fire again after durationOrDefault
                context.PerformedAndStayStarted();
                ignoreInputUntilTime = Time.time + RepeatedPauseOrDefault;

                // Check input again when the time elapsed or input changed.
                context.SetTimeout(RepeatedPauseOrDefault);
            }
            break;

        case InputActionPhase.Performed:
            if (!context.ControlIsActuated(PressPointOrDefault))
            {
                Cancel(ref context);
            }
            break;

        default:
            if (!context.ControlIsActuated(PressPointOrDefault))
            {
                Cancel(ref context);
            }
            break;
        }
    }
Beispiel #2
0
        ////TODO: make sure 2d doesn't move too far

        public void Process(ref InputInteractionContext context)
        {
            if (context.timerHasExpired)
            {
                context.Canceled();
                return;
            }

            if (context.isWaiting && context.ControlIsActuated(pressPointOrDefault))
            {
                m_TapStartTime = context.time;
                // Set timeout slightly after duration so that if tap comes in exactly at the expiration
                // time, it still counts as a valid tap.
                context.Started();
                context.SetTimeout(durationOrDefault + 0.00001f);
                return;
            }

            if (context.isStarted && !context.ControlIsActuated(releasePointOrDefault))
            {
                if (context.time - m_TapStartTime <= durationOrDefault)
                {
                    context.Performed();
                }
                else
                {
                    ////REVIEW: does it matter to cancel right after expiration of 'duration' or is it enough to cancel on button up like here?
                    context.Canceled();
                }
            }
        }
Beispiel #3
0
        public void Process(ref InputInteractionContext context)
        {
            if (context.timerHasExpired)
            {
                context.Performed();
                return;
            }

            if (context.isWaiting && !context.controlHasDefaultValue)
            {
                m_TimePressed = context.time;

                context.Started();
                context.SetTimeout(durationOrDefault);

                return;
            }

            ////TODO: need to ignore releases on controls that aren't m_PressedControl
            if (context.isStarted && context.controlHasDefaultValue)
            {
                if (context.time - m_TimePressed >= durationOrDefault)
                {
                    context.Performed();
                }
                else
                {
                    context.Cancelled();
                }
            }
        }
        ////TODO: make sure 2d doesn't move too far

        public void Process(ref InputInteractionContext context)
        {
            if (context.timerHasExpired)
            {
                context.Cancelled();
                return;
            }

            if (context.isWaiting && !context.controlHasDefaultValue)
            {
                m_TapStartTime = context.time;
                context.SetTimeout(durationOrDefault);
                context.Started();
                return;
            }

            if (context.isStarted && context.controlHasDefaultValue)
            {
                if (context.time - m_TapStartTime <= durationOrDefault)
                {
                    context.Performed();
                }
                else
                {
                    ////REVIEW: does it matter to cancel right after expiration of 'duration' or is it enough to cancel on button up like here?
                    context.Cancelled();
                }
            }
        }
Beispiel #5
0
    public void Process(ref InputInteractionContext context)
    {
        var isActuated = context.ControlIsActuated(pressPointOrDefault);

        switch (context.phase)
        {
        case InputActionPhase.Waiting:
            if (isActuated)
            {
                context.Started();
                context.PerformedAndStayPerformed();
                m_lastPerformTime = context.time;
                context.SetTimeout(delay);
            }
            break;

        case InputActionPhase.Performed:
            if (!isActuated)
            {
                context.Canceled();
            }
            else
            {
                var trigger = false;
                if (!m_delayPassed)
                {
                    trigger = context.time - m_lastPerformTime >= delay;
                    if (trigger)
                    {
                        m_delayPassed = true;
                    }
                }
                else
                {
                    trigger = context.time - m_lastPerformTime >= rate;
                }
                if (trigger)
                {
                    context.PerformedAndStayPerformed();
                    m_lastPerformTime = context.time;
                    context.SetTimeout(rate);
                }
            }
            break;
        }
    }
Beispiel #6
0
    /// <inheritdoc />
    public void Process(ref InputInteractionContext context)
    {
        switch (context.phase)
        {
        case InputActionPhase.Waiting:
        case InputActionPhase.Canceled:
            if (context.ControlIsActuated(PressPointOrDefault))
            {
                context.Started();
                if (fireImmediately)
                {
                    context.PerformedAndStayStarted();
                }
                context.SetTimeout(InitialPauseOrDefault);
            }
            break;

        case InputActionPhase.Started:
            if (!context.ControlIsActuated())
            {
                context.Canceled();
            }
            else
            {
                // Perform action but stay in the started phase, because we want to fire again after durationOrDefault
                context.PerformedAndStayStarted();
                // Fire again after durationOrDefault
                context.SetTimeout(RepeatedPauseOrDefault);
            }
            break;

        case InputActionPhase.Performed:
            if (!context.ControlIsActuated(PressPointOrDefault))
            {
                context.Canceled();
            }
            break;

        default:
            if (!context.ControlIsActuated(PressPointOrDefault))
            {
                context.Canceled();
            }
            break;
        }
    }
        public void Process(ref InputInteractionContext context)
        {
            if (context.timerHasExpired)
            {
                if (context.continuous)
                {
                    context.PerformedAndStayPerformed();
                }
                else
                {
                    context.PerformedAndGoBackToWaiting();
                }
                return;
            }

            switch (context.phase)
            {
            case InputActionPhase.Waiting:
                if (context.ControlIsActuated(pressPointOrDefault))
                {
                    m_TimePressed = context.time;

                    context.Started();
                    context.SetTimeout(durationOrDefault);
                }
                break;

            case InputActionPhase.Started:
                // If we've reached our hold time threshold, perform the hold.
                // We do this regardless of what state the control changed to.
                if (context.time - m_TimePressed >= durationOrDefault)
                {
                    context.PerformedAndStayPerformed();
                }
                else if (!context.ControlIsActuated())
                {
                    // Control is no longer actuated and we haven't performed a hold yet,
                    // so cancel.
                    context.Canceled();
                }
                break;

            case InputActionPhase.Performed:
                if (context.ControlIsActuated(pressPointOrDefault))
                {
                    if (context.continuous)
                    {
                        context.PerformedAndStayPerformed();
                    }
                }
                else
                {
                    context.Canceled();
                }
                break;
            }
        }
Beispiel #8
0
        public void Process(ref InputInteractionContext context)
        {
            if (context.timerHasExpired)
            {
                context.Performed();
                return;
            }

            var phase = context.phase;

            switch (phase)
            {
            case InputActionPhase.Disabled:
                break;

            case InputActionPhase.Waiting:
                if (context.ControlIsActuated())
                {
                    context.Started();
                    context.SetTimeout(float.PositiveInfinity);
                }

                break;

            case InputActionPhase.Started:
                context.PerformedAndStayPerformed();
                break;

            case InputActionPhase.Performed:
                if (context.ControlIsActuated())
                {
                    context.PerformedAndStayPerformed();
                }
                else
                {
                    ButtonControl buttonControl = context.action.controls[0] as ButtonControl;
                    Pointer       pointer       = context.action.controls[0] as Pointer;
                    if (buttonControl != null && !buttonControl.isPressed)
                    {
                        context.Canceled();
                    }
                    if (pointer != null && !pointer.IsPressed())
                    {
                        context.Canceled();
                    }
                }

                break;

            case InputActionPhase.Canceled:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(phase), phase, null);
            }
        }
    public void Process(ref InputInteractionContext context)
    {
        Vector2 stickPos = context.ReadValue <Vector2>();

        if (context.timerHasExpired)
        {
            context.Canceled();
        }

        if (stickPos.magnitude < deadZone)
        {
            hasStarted = false;
            context.Canceled();
        }
        switch (context.phase)
        {
        case InputActionPhase.Waiting:
            if (stickPos.magnitude > deadZone && !hasStarted)
            {
                context.Started();
                timeStartedMoving = context.time;
                hasStarted        = true;
            }
            break;

        case InputActionPhase.Started:
            if ((context.time - timeStartedMoving) > duration || stickPos.magnitude <= deadZone)
            {
                context.Canceled();
            }
            if (stickPos.magnitude >= smashZone)
            {
                context.Performed();
                context.SetTimeout(0.1f);
            }
            break;
        }
    }
Beispiel #10
0
        public void Process(ref InputInteractionContext context)
        {
            switch (context.phase)
            {
            case InputActionPhase.Waiting:
                if (context.ControlIsActuated(pressPointOrDefault))
                {
                    if (m_TimePressed <= 0)
                    {
                        m_TimePressed = context.time;
                        context.SetTimeout(durationOrDefault);
                    }
                    else if (context.time - m_TimePressed >= durationOrDefault)
                    {
                        context.Started();
                    }
                }
                else
                {
                    Reset();
                }
                break;

            case InputActionPhase.Started:
                if (!context.ControlIsActuated())
                {
                    context.Performed();
                    Reset();
                }
                break;

            case InputActionPhase.Performed:
                context.Canceled();
                break;
            }
        }
        /// <inheritdoc />
        public void Process(ref InputInteractionContext context)
        {
            if (context.timerHasExpired)
            {
                // We use timers multiple times but no matter what, if they expire it means
                // that we didn't get input in time.
                context.Canceled();
                return;
            }

            switch (m_CurrentTapPhase)
            {
            case TapPhase.None:
                if (context.ControlIsActuated(pressPointOrDefault))
                {
                    m_CurrentTapPhase     = TapPhase.WaitingForNextRelease;
                    m_CurrentTapStartTime = context.time;
                    context.Started();
                    context.SetTimeout(tapTimeOrDefault);
                }
                break;

            case TapPhase.WaitingForNextRelease:
                if (!context.ControlIsActuated(pressPointOrDefault))
                {
                    if (context.time - m_CurrentTapStartTime <= tapTimeOrDefault)
                    {
                        ++m_CurrentTapCount;
                        if (m_CurrentTapCount >= tapCount)
                        {
                            context.Performed();
                        }
                        else
                        {
                            m_CurrentTapPhase    = TapPhase.WaitingForNextPress;
                            m_LastTapReleaseTime = context.time;
                            context.SetTimeout(tapDelayOrDefault);
                        }
                    }
                    else
                    {
                        context.Canceled();
                    }
                }
                break;

            case TapPhase.WaitingForNextPress:
                if (context.ControlIsActuated(pressPointOrDefault))
                {
                    if (context.time - m_LastTapReleaseTime <= tapDelayOrDefault)
                    {
                        m_CurrentTapPhase     = TapPhase.WaitingForNextRelease;
                        m_CurrentTapStartTime = context.time;
                        context.SetTimeout(tapTimeOrDefault);
                    }
                    else
                    {
                        context.Canceled();
                    }
                }
                break;
            }
        }
        /// <inheritdoc />
        public void Process(ref InputInteractionContext context)
        {
            if (context.timerHasExpired)
            {
                // We use timers multiple times but no matter what, if they expire it means
                // that we didn't get input in time.
                context.Canceled();
                return;
            }

            switch (m_CurrentTapPhase)
            {
            case TapPhase.None:
                if (context.ControlIsActuated(pressPointOrDefault))
                {
                    m_CurrentTapPhase     = TapPhase.WaitingForNextRelease;
                    m_CurrentTapStartTime = context.time;
                    context.Started();

                    var maxTapTime        = tapTimeOrDefault;
                    var maxDelayInBetween = tapDelayOrDefault;
                    context.SetTimeout(maxTapTime);

                    // We'll be using multiple timeouts so set a total completion time that
                    // effects the result of InputAction.GetTimeoutCompletionPercentage()
                    // such that it accounts for the total time we allocate for the interaction
                    // rather than only the time of one single timeout.
                    context.SetTotalTimeoutCompletionTime(maxTapTime * tapCount + (tapCount - 1) * maxDelayInBetween);
                }
                break;

            case TapPhase.WaitingForNextRelease:
                if (!context.ControlIsActuated(releasePointOrDefault))
                {
                    if (context.time - m_CurrentTapStartTime <= tapTimeOrDefault)
                    {
                        ++m_CurrentTapCount;
                        if (m_CurrentTapCount >= tapCount)
                        {
                            context.Performed();
                        }
                        else
                        {
                            m_CurrentTapPhase    = TapPhase.WaitingForNextPress;
                            m_LastTapReleaseTime = context.time;
                            context.SetTimeout(tapDelayOrDefault);
                        }
                    }
                    else
                    {
                        context.Canceled();
                    }
                }
                break;

            case TapPhase.WaitingForNextPress:
                if (context.ControlIsActuated(pressPointOrDefault))
                {
                    if (context.time - m_LastTapReleaseTime <= tapDelayOrDefault)
                    {
                        m_CurrentTapPhase     = TapPhase.WaitingForNextRelease;
                        m_CurrentTapStartTime = context.time;
                        context.SetTimeout(tapTimeOrDefault);
                    }
                    else
                    {
                        context.Canceled();
                    }
                }
                break;
            }
        }