////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();
                }
            }
        }
        ////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.ControlIsActuated())
            {
                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.SetTimeout(durationOrDefault + 0.00001f);
                context.Started();
                return;
            }

            if (context.isStarted && !context.ControlIsActuated())
            {
                if (context.time - m_TapStartTime <= durationOrDefault)
                {
                    context.PerformedAndGoBackToWaiting();
                }
                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();
                }
            }
        }
        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.Cancelled();
                }
                break;

            case InputActionPhase.Performed:
                if (context.ControlIsActuated(pressPointOrDefault))
                {
                    if (context.continuous)
                    {
                        context.PerformedAndStayPerformed();
                    }
                }
                else
                {
                    context.Cancelled();
                }
                break;
            }
        }
Example #4
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();
                }
            }
        }
Example #5
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();
            }
        }
        public void Process(ref InputInteractionContext context)
        {
            if (context.isWaiting && context.ControlIsActuated())
            {
                m_SlowTapStartTime = context.time;
                context.Started();
                return;
            }

            if (context.isStarted && !context.ControlIsActuated())
            {
                if (context.time - m_SlowTapStartTime >= durationOrDefault)
                {
                    context.PerformedAndGoBackToWaiting();
                }
                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();
                }
            }
        }
Example #7
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;
            }
        }
        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.Cancelled();
                return;
            }

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

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

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