////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(); } } }
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; } }
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) { 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; } }
public void Process(ref InputInteractionContext context) { if (context.ControlIsActuated()) { context.Performed(); context.Canceled(); } }
/// <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) { 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; } }
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; } }
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) { 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(); } } }
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) { 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; }
/// <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; } }
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; } }
private void Cancel(ref InputInteractionContext context) { ignoreInputUntilTime = 0; context.Canceled(); }