No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InputActionPhase.cs 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using UnityEngine.InputSystem.Interactions;
  2. ////REVIEW: this goes beyond just actions; is there a better name? just InputPhase?
  3. ////REVIEW: what about opening up phases completely to interactions and allow them to come up with whatever custom phases?
  4. namespace UnityEngine.InputSystem
  5. {
  6. /// <summary>
  7. /// Trigger phase of an <see cref="InputAction"/>.
  8. /// </summary>
  9. /// <remarks>
  10. /// Actions can be triggered in steps. For example, a <see cref="SlowTapInteraction">
  11. /// 'slow tap'</see> will put an action into <see cref="Started"/> phase when a button
  12. /// the action is bound to is pressed. At that point, however, the action still
  13. /// has to wait for the expiration of a timer in order to make it a 'slow tap'. If
  14. /// the button is release before the timer expires, the action will be <see cref="Canceled"/>
  15. /// whereas if the button is held long enough, the action will be <see cref="Performed"/>.
  16. /// </remarks>
  17. /// <seealso cref="InputAction.phase"/>
  18. /// <seealso cref="InputAction.CallbackContext.phase"/>
  19. /// <seealso cref="InputAction.started"/>
  20. /// <seealso cref="InputAction.performed"/>
  21. /// <seealso cref="InputAction.canceled"/>
  22. public enum InputActionPhase
  23. {
  24. /// <summary>
  25. /// The action is not enabled.
  26. /// </summary>
  27. Disabled,
  28. /// <summary>
  29. /// The action is enabled and waiting for input on its associated controls.
  30. ///
  31. /// This is the phase that an action goes back to once it has been <see cref="Performed"/>
  32. /// or <see cref="Canceled"/>.
  33. /// </summary>
  34. Waiting,
  35. /// <summary>
  36. /// An associated control has been actuated such that it may lead to the action
  37. /// being triggered. Will lead to <see cref="InputAction.started"/> getting called.
  38. ///
  39. /// This phase will only be invoked if there are interactions on the respective control
  40. /// binding. Without any interactions, an action will go straight from <see cref="Waiting"/>
  41. /// into <see cref="Performed"/> and back into <see cref="Waiting"/> whenever an associated
  42. /// control changes value.
  43. ///
  44. /// An example of an interaction that uses the <see cref="Started"/> phase is <see cref="SlowTapInteraction"/>.
  45. /// When the button it is bound to is pressed, the associated action goes into the <see cref="Started"/>
  46. /// phase. At this point, the interaction does not yet know whether the button press will result in just
  47. /// a tap or will indeed result in slow tap. If the button is released before the time it takes to
  48. /// recognize a slow tap, then the action will go to <see cref="Canceled"/> and then back to <see cref="Waiting"/>.
  49. /// If, however, the button is held long enough for it to qualify as a slow tap, the action will progress
  50. /// to <see cref="Performed"/> and then go back to <see cref="Waiting"/>.
  51. ///
  52. /// <see cref="Started"/> can be useful for UI feedback. For example, in a game where the weapon can be charged,
  53. /// UI feedback can be initiated when the action is <see cref="Started"/>.
  54. ///
  55. /// <example>
  56. /// <code>
  57. /// fireAction.started +=
  58. /// ctx =>
  59. /// {
  60. /// if (ctx.interaction is SlowTapInteraction)
  61. /// {
  62. /// weaponCharging = true;
  63. /// weaponChargeStartTime = ctx.time;
  64. /// }
  65. /// }
  66. /// fireAction.canceled +=
  67. /// ctx =>
  68. /// {
  69. /// weaponCharging = false;
  70. /// }
  71. /// fireAction.performed +=
  72. /// ctx =>
  73. /// {
  74. /// Fire();
  75. /// weaponCharging = false;
  76. /// }
  77. /// </code>
  78. /// </example>
  79. ///
  80. /// By default, an action is started as soon as a control moves away from its default value. This is
  81. /// the case for both <see cref="InputActionType.Button"/> actions (which, however, does not yet have to mean
  82. /// that the button press threshold has been reached; see <see cref="InputSettings.defaultButtonPressPoint"/>)
  83. /// and <see cref="InputActionType.Value"/> actions. <see cref="InputActionType.PassThrough"/> does not use
  84. /// the <c>Started</c> phase and instead goes straight to <see cref="Performed"/>.
  85. ///
  86. /// For <see cref="InputActionType.Value"/> actions, <c>Started</c> will immediately be followed by <see cref="Performed"/>.
  87. ///
  88. /// Note that interactions (see <see cref="IInputInteraction"/>) can alter how an action does or does not progress through
  89. /// the phases.
  90. /// </summary>
  91. Started,
  92. /// <summary>
  93. /// The action has been performed. Leads to <see cref="InputAction.performed"/> getting called.
  94. ///
  95. /// By default, a <see cref="InputActionType.Button"/> action performs when a control crosses the button
  96. /// press threshold (see <see cref="InputSettings.defaultButtonPressPoint"/>), a <see cref="InputActionType.Value"/>
  97. /// action performs on any value change that isn't the default value, and a <see cref="InputActionType.PassThrough"/>
  98. /// action performs on any value change including going back to the default value.
  99. ///
  100. /// Note that interactions (see <see cref="IInputInteraction"/>) can alter how an action does or does not progress through
  101. /// the phases.
  102. ///
  103. /// For a given action, finding out whether it was performed in the current frame can be done with <see cref="InputAction.WasPerformedThisFrame"/>.
  104. ///
  105. /// <example>
  106. /// <code>
  107. /// action.WasPerformedThisFrame();
  108. /// </code>
  109. /// </example>
  110. /// </summary>
  111. Performed,
  112. /// <summary>
  113. /// The action has stopped. Leads to <see cref="InputAction.canceled"/> getting called.
  114. ///
  115. /// By default, a <see cref="InputActionType.Button"/> action cancels when a control falls back below the button
  116. /// press threshold (see <see cref="InputSettings.defaultButtonPressPoint"/>) and a <see cref="InputActionType.Value"/>
  117. /// action cancels when a control moves back to its default value. A <see cref="InputActionType.PassThrough"/> action
  118. /// does not generally cancel based on input on its controls.
  119. ///
  120. /// An action will also get canceled when it is disabled while in progress (see <see cref="InputAction.Disable"/>).
  121. /// Also, when an <see cref="InputDevice"/> that is
  122. ///
  123. /// Note that interactions (see <see cref="IInputInteraction"/>) can alter how an action does or does not progress through
  124. /// the phases.
  125. /// </summary>
  126. Canceled
  127. }
  128. }