InputActionPhase.cs 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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">action</see>.
  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. public enum InputActionPhase
  18. {
  19. /// <summary>
  20. /// The action is not enabled.
  21. /// </summary>
  22. Disabled,
  23. /// <summary>
  24. /// The action is enabled and waiting for input on its associated controls.
  25. /// </summary>
  26. /// <remarks>
  27. /// This is the phase that an action goes back to once it has been <see cref="Performed"/>
  28. /// or <see cref="Canceled"/>.
  29. /// </remarks>
  30. Waiting,
  31. /// <summary>
  32. /// An associated control has been actuated such that it may lead to the action
  33. /// being triggered.
  34. /// </summary>
  35. /// <remarks>
  36. /// This phase will only be invoked if there are interactions on the respective control
  37. /// binding. Without any interactions, an action will go straight from <see cref="Waiting"/>
  38. /// into <see cref="Performed"/> and back into <see cref="Waiting"/> whenever an associated
  39. /// control changes value.
  40. ///
  41. /// An example of an interaction that uses the <see cref="Started"/> phase is <see cref="SlowTapInteraction"/>.
  42. /// When the button it is bound to is pressed, the associated action goes into the <see cref="Started"/>
  43. /// phase. At this point, the interaction does not yet know whether the button press will result in just
  44. /// a tap or will indeed result in slow tap. If the button is released before the time it takes to
  45. /// recognize a slow tap, then the action will go to <see cref="Canceled"/> and then back to <see cref="Waiting"/>.
  46. /// If, however, the button is held long enough for it to qualify as a slow tap, the action will progress
  47. /// to <see cref="Performed"/> and then go back to <see cref="Waiting"/>.
  48. ///
  49. /// <see cref="Started"/> can be useful for UI feedback. For example, in a game where the weapon can be charged,
  50. /// UI feedback can be initiated when the action is <see cref="Started"/>.
  51. /// </remarks>
  52. /// <example>
  53. /// <code>
  54. /// fireAction.started +=
  55. /// ctx =>
  56. /// {
  57. /// if (ctx.interaction is SlowTapInteraction)
  58. /// {
  59. /// weaponCharging = true;
  60. /// weaponChargeStartTime = ctx.time;
  61. /// }
  62. /// }
  63. /// fireAction.canceled +=
  64. /// ctx =>
  65. /// {
  66. /// weaponCharging = false;
  67. /// }
  68. /// fireAction.performed +=
  69. /// ctx =>
  70. /// {
  71. /// Fire();
  72. /// weaponCharging = false;
  73. /// }
  74. /// </code>
  75. /// </example>
  76. Started,
  77. /// <summary>
  78. ///
  79. /// </summary>
  80. /// <seealso cref="InputAction.performed"/>
  81. Performed,
  82. /// <summary>
  83. ///
  84. /// </summary>
  85. /// <seealso cref="InputAction.canceled"/>
  86. Canceled
  87. }
  88. }