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) { 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) { 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.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(); } }
////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.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.ControlIsActuated()) { context.Performed(); context.Canceled(); } }
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); } }
#pragma warning restore CS0649 public void Process(ref InputInteractionContext context) { if (context.ControlIsActuated()) { if (stayPerformed) { context.PerformedAndStayPerformed(); } else { context.Performed(); } } }
/// <inheritdoc /> public void Process(ref InputInteractionContext context) { if (context.timerHasExpired) { context.Performed(); 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)) { context.Canceled(); } 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) { 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) { 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(); 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) { 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; } }
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; } }