/// <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;
        }
    }
Пример #2
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;
        }
    }
Пример #3
0
        public void Process(ref InputInteractionContext context)
        {
            var value = context.ReadValue <Vector2>();

            if (value.sqrMagnitude > 0)
            {
                if (!context.isStarted)
                {
                    context.Started();
                }
                else
                {
                    context.PerformedAndStayStarted();
                }
            }
            else if (context.isStarted)
            {
                // Went back to below deadzone.
                context.Cancelled();
            }
        }
Пример #4
0
        public void Process(ref InputInteractionContext context)
        {
            var isActuated = context.ControlIsActuated(pressPointOrDefault);

            switch (behavior)
            {
            case PressBehavior.PressOnly:
                if (m_WaitingForRelease)
                {
                    if (context.continuous)
                    {
                        if (isActuated)
                        {
                            context.PerformedAndStayPerformed();
                        }
                        else
                        {
                            // We need to reset the action to waiting state in order to stop it from triggering
                            // continuously. However, we do not want to cancel here as that will trigger the action.
                            // So go back directly to waiting here.
                            context.Waiting();
                        }
                    }

                    m_WaitingForRelease = isActuated;
                }
                else if (isActuated)
                {
                    if (context.continuous)
                    {
                        context.PerformedAndStayPerformed();
                    }
                    else
                    {
                        context.PerformedAndGoBackToWaiting();
                    }

                    m_WaitingForRelease = true;
                }
                break;

            case PressBehavior.ReleaseOnly:
                if (m_WaitingForRelease && !isActuated)
                {
                    m_WaitingForRelease = false;
                    context.PerformedAndGoBackToWaiting();

                    // No support for continuous mode.
                }
                else if (isActuated)
                {
                    m_WaitingForRelease = true;
                }
                break;

            case PressBehavior.PressAndRelease:
                if (m_WaitingForRelease)
                {
                    if (context.continuous)
                    {
                        if (isActuated)
                        {
                            context.PerformedAndStayPerformed();
                        }
                        else
                        {
                            context.Cancelled();
                        }
                    }
                    else if (!isActuated)
                    {
                        context.Cancelled();
                    }

                    m_WaitingForRelease = isActuated;
                }
                else if (isActuated)
                {
                    if (context.continuous)
                    {
                        context.PerformedAndStayPerformed();
                    }
                    else
                    {
                        context.PerformedAndStayStarted();
                    }

                    m_WaitingForRelease = true;
                }
                break;
            }
        }