////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();
                }
            }
        }
Example #2
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();
                }
            }
        }
        public void Process(ref InputInteractionContext context)
        {
            if (!context.isWaiting)
            {
                return;
            }

            var control      = context.control;
            var floatControl = control as InputControl <float>;

            if (floatControl == null)
            {
                return;
            }

            var value = floatControl.ReadValue();
            ////FIXME: we want the previously stored value here, not the value from the previous frame
            var previous  = floatControl.ReadValueFromPreviousFrame();
            var threshold = pressPointOrDefault;

            if (previous < threshold && value >= threshold)
            {
                context.Performed();
            }
        }
Example #4
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();
                }
            }
        }
        /// <summary>
        /// Determines whether the control is pointing towards the configured North, South, East, or West direction(s).
        /// </summary>
        /// <param name="context">The input control information context.</param>
        /// <returns>Returns <see langword="true"/> if pointing in "this" direction. Otherwise, returns <see langword="false"/>.</returns>
        bool IsValidDirection(ref InputInteractionContext context)
        {
            var value            = context.ReadValue <Vector2>();
            var cardinal         = CardinalUtility.GetNearestCardinal(value);
            var nearestDirection = GetNearestDirection(cardinal);

            return((nearestDirection & directions) != 0);
        }
 public void Process(ref InputInteractionContext context)
 {
     if (context.ControlIsActuated())
     {
         context.Performed();
         context.Canceled();
     }
 }
        public void Process(ref InputInteractionContext context)
        {
            var isActuated = context.ControlIsActuated(pressPointOrDefault);

            switch (behavior)
            {
            case PressBehavior.PressOnly:
                if (m_WaitingForRelease)
                {
                    if (!isActuated)
                    {
                        m_WaitingForRelease = false;
                        // 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();
                    }
                }
                else if (isActuated)
                {
                    context.Started();
                    context.Performed();
                    m_WaitingForRelease = true;
                }
                break;

            case PressBehavior.ReleaseOnly:
                if (m_WaitingForRelease && !isActuated)
                {
                    m_WaitingForRelease = false;
                    context.Performed();
                }
                else if (isActuated)
                {
                    context.Started();
                    m_WaitingForRelease = true;
                }
                break;

            case PressBehavior.PressAndRelease:
                if (m_WaitingForRelease)
                {
                    if (!isActuated)
                    {
                        context.Started();
                        context.Performed();
                    }
                    m_WaitingForRelease = isActuated;
                }
                else if (isActuated)
                {
                    context.Started();
                    context.Performed();
                    m_WaitingForRelease = true;
                }
                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;
            }
        }
Example #9
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);
            }
        }
Example #10
0
        public void Process(ref InputInteractionContext context)
        {
            var isActuated = context.ControlIsActuated(pressPointOrDefault);

            switch (behavior)
            {
            case PressBehavior.PressOnly:
                if (m_WaitingForRelease)
                {
                    if (!isActuated)
                    {
                        m_WaitingForRelease = false;
                        context.Canceled();
                    }
                }
                else if (isActuated)
                {
                    context.PerformedAndStayPerformed();
                    m_WaitingForRelease = true;
                }
                break;

            case PressBehavior.ReleaseOnly:
                if (m_WaitingForRelease && !isActuated)
                {
                    m_WaitingForRelease = false;
                    context.Performed();
                    context.Canceled();
                }
                else if (isActuated)
                {
                    context.Started();
                    m_WaitingForRelease = true;
                }
                break;

            case PressBehavior.PressAndRelease:
                if (m_WaitingForRelease)
                {
                    if (!isActuated)
                    {
                        context.Performed();
                        context.Canceled();
                    }
                    m_WaitingForRelease = isActuated;
                }
                else if (isActuated)
                {
                    context.PerformedAndStayPerformed();
                    m_WaitingForRelease = true;
                }
                break;
            }
        }
    /// <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;
        }
    }
        #pragma warning restore CS0649

        public void Process(ref InputInteractionContext context)
        {
            if (context.ControlIsActuated())
            {
                if (stayPerformed)
                {
                    context.PerformedAndStayPerformed();
                }
                else
                {
                    context.Performed();
                }
            }
        }
Example #13
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;
        }
    }
Example #14
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;
        }
    }
Example #15
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();
            }
        }
Example #16
0
        public void Process(ref InputInteractionContext context)
        {
            if (context.isWaiting && context.ControlIsActuated(pressPointOrDefault))
            {
                m_SlowTapStartTime = context.time;
                context.Started();
                return;
            }

            if (context.isStarted && !context.ControlIsActuated(pressPointOrDefault))
            {
                if (context.time - m_SlowTapStartTime >= 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();
                }
            }
        }
Example #17
0
 public void Process(ref InputInteractionContext context)
 {
     if (context.isWaiting && context.ControlIsActuated())
     {
         context.Started();
         startTime = Time.time;
     }
     else if (context.isStarted && !context.ControlIsActuated())
     {
         var duration = Time.time - startTime;
         if (duration > minDuration &&
             duration < maxDuration)
         {
             // Interaction has been completed.
             context.Performed();
         }
         else
         {
             context.Canceled();
         }
     }
 }
    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;
        }
    }
Example #19
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;
            }
        }
 private void Cancel(ref InputInteractionContext context)
 {
     ignoreInputUntilTime = 0;
     context.Canceled();
 }
 public void Process(ref InputInteractionContext context)
 {
 }
        /// <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;
            }
        }
Example #23
0
        public void Process(ref InputInteractionContext context)
        {
            var actuation = context.ComputeMagnitude();

            switch (behavior)
            {
            case PressBehavior.PressOnly:
                if (m_WaitingForRelease)
                {
                    if (actuation <= releasePointOrDefault)
                    {
                        m_WaitingForRelease = false;
                        context.Canceled();
                    }
                }
                else if (actuation >= pressPointOrDefault)
                {
                    m_WaitingForRelease = true;
                    // Stay performed until release.
                    context.PerformedAndStayPerformed();
                }
                else if (actuation > 0 && !context.isStarted)
                {
                    context.Started();
                }
                break;

            case PressBehavior.ReleaseOnly:
                if (m_WaitingForRelease)
                {
                    if (actuation <= releasePointOrDefault)
                    {
                        m_WaitingForRelease = false;
                        context.Performed();
                        context.Canceled();
                    }
                }
                else if (actuation >= pressPointOrDefault)
                {
                    m_WaitingForRelease = true;
                    if (!context.isStarted)
                    {
                        context.Started();
                    }
                }
                else
                {
                    var started = context.isStarted;
                    if (actuation > 0 && !started)
                    {
                        context.Started();
                    }
                    else if (Mathf.Approximately(0, actuation) && started)
                    {
                        context.Canceled();
                    }
                }
                break;

            case PressBehavior.PressAndRelease:
                if (m_WaitingForRelease)
                {
                    if (actuation <= releasePointOrDefault)
                    {
                        m_WaitingForRelease = false;
                        context.Performed();
                        if (Mathf.Approximately(0, actuation))
                        {
                            context.Canceled();
                        }
                    }
                }
                else if (actuation >= pressPointOrDefault)
                {
                    m_WaitingForRelease = true;
                    context.PerformedAndStayPerformed();
                }
                else
                {
                    var started = context.isStarted;
                    if (actuation > 0 && !started)
                    {
                        context.Started();
                    }
                    else if (Mathf.Approximately(0, actuation) && started)
                    {
                        context.Canceled();
                    }
                }
                break;
            }
        }
Example #24
0
        /// <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;
            }
        }
        /// <inheritdoc />
        public void Process(ref InputInteractionContext context)
        {
            var isActuated = context.ControlIsActuated(pressPointOrDefault);

            if (!isActuated)
            {
                switch (m_State)
                {
                case State.Centered:
                    return;

                case State.StartedInvalidDirection:
                case State.StartedValidDirection:
                    m_State = State.Centered;
                    context.Canceled();
                    return;

                default:
                    Assert.IsTrue(false, $"Unhandled {nameof(State)}={m_State}");
                    return;
                }
            }

            var isValidDirection = IsValidDirection(ref context);

            if (m_State == State.Centered)
            {
                m_State = isValidDirection ? State.StartedValidDirection : State.StartedInvalidDirection;
                if (isValidDirection)
                {
                    context.PerformedAndStayPerformed();
                }
                m_WasValidDirection = isValidDirection;

                return;
            }

            switch (sweepBehavior)
            {
            case SweepBehavior.Locked:
                break;

            case SweepBehavior.AllowReentry:
                if (m_WasValidDirection && !isValidDirection && m_State == State.StartedValidDirection)
                {
                    context.Canceled();
                }
                else if (!m_WasValidDirection && isValidDirection && m_State == State.StartedValidDirection)
                {
                    context.PerformedAndStayPerformed();
                }

                break;

            case SweepBehavior.DisallowReentry:
                if (m_WasValidDirection && !isValidDirection && m_State == State.StartedValidDirection)
                {
                    context.Canceled();
                }

                break;

            case SweepBehavior.HistoryIndependent:
                if (m_WasValidDirection && !isValidDirection)
                {
                    context.Canceled();
                }
                else if (!m_WasValidDirection && isValidDirection)
                {
                    context.PerformedAndStayPerformed();
                }

                break;

            default:
                Assert.IsTrue(false, $"Unhandled {nameof(SweepBehavior)}={sweepBehavior}");
                break;
            }

            m_WasValidDirection = isValidDirection;
        }
Example #26
0
 public void Process(ref InputInteractionContext context)
 {
     throw new System.NotImplementedException();
 }