Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

IInputActionCollection.cs 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine.InputSystem.Utilities;
  4. ////TODO: move indexer up here
  5. namespace UnityEngine.InputSystem
  6. {
  7. /// <summary>
  8. /// A collection of input actions (see <see cref="InputAction"/>).
  9. /// </summary>
  10. /// <seealso cref="InputActionMap"/>
  11. /// <seealso cref="InputActionAsset"/>
  12. public interface IInputActionCollection : IEnumerable<InputAction>
  13. {
  14. /// <summary>
  15. /// Optional mask applied to all bindings in the collection.
  16. /// </summary>
  17. /// <remarks>
  18. /// If this is not null, only bindings that match the mask will be used.
  19. ///
  20. /// Modifying this property while any of the actions in the collection are enabled will
  21. /// lead to the actions getting disabled temporarily and then re-enabled.
  22. /// </remarks>
  23. InputBinding? bindingMask { get; set; }
  24. ////REVIEW: should this allow restricting to a set of controls instead of confining it to just devices?
  25. /// <summary>
  26. /// Devices to use with the actions in this collection.
  27. /// </summary>
  28. /// <remarks>
  29. /// If this is set, actions in the collection will exclusively bind to devices
  30. /// in the given list. For example, if two gamepads are present in the system yet
  31. /// only one gamepad is listed here, then a "&lt;Gamepad&gt;/leftStick" binding will
  32. /// only bind to the gamepad in the list and not to the one that is only available
  33. /// globally.
  34. ///
  35. /// Modifying this property after bindings in the collection have already been resolved,
  36. /// will lead to <see cref="InputAction.controls"/> getting refreshed. If any of the actions
  37. /// in the collection are currently in progress (see <see cref="InputAction.phase"/>),
  38. /// the actions will remain unaffected and in progress except if the controls currently
  39. /// driving them (see <see cref="InputAction.activeControl"/>) are no longer part of any
  40. /// of the selected devices. In that case, the action is <see cref="InputAction.canceled"/>.
  41. /// </remarks>
  42. ReadOnlyArray<InputDevice>? devices { get; set; }
  43. /// <summary>
  44. /// List of control schemes defined for the set of actions.
  45. /// </summary>
  46. /// <remarks>
  47. /// Control schemes are optional and the list may be empty.
  48. /// </remarks>
  49. ReadOnlyArray<InputControlScheme> controlSchemes { get; }
  50. /// <summary>
  51. /// Check whether the given action is contained in this collection.
  52. /// </summary>
  53. /// <param name="action">An arbitrary input action.</param>
  54. /// <returns>True if the given action is contained in the collection, false if not.</returns>
  55. /// <remarks>
  56. /// Calling this method will not allocate GC memory (unlike when iterating generically
  57. /// over the collection). Also, a collection may have a faster containment check rather than
  58. /// having to search through all its actions.
  59. /// </remarks>
  60. bool Contains(InputAction action);
  61. /// <summary>
  62. /// Enable all actions in the collection.
  63. /// </summary>
  64. /// <seealso cref="InputAction.Enable"/>
  65. /// <seealso cref="InputAction.enabled"/>
  66. void Enable();
  67. /// <summary>
  68. /// Disable all actions in the collection.
  69. /// </summary>
  70. /// <seealso cref="InputAction.Disable"/>
  71. /// <seealso cref="InputAction.enabled"/>
  72. void Disable();
  73. }
  74. /// <summary>
  75. /// An extended version of <see cref="IInputActionCollection"/>.
  76. /// </summary>
  77. /// <remarks>
  78. /// This interface will be merged into <see cref="IInputActionCollection"/> in a future (major) version.
  79. /// </remarks>
  80. public interface IInputActionCollection2 : IInputActionCollection
  81. {
  82. /// <summary>
  83. /// Iterate over all bindings in the collection of actions.
  84. /// </summary>
  85. /// <seealso cref="InputActionMap.bindings"/>
  86. /// <seealso cref="InputAction.bindings"/>
  87. /// <seealso cref="InputActionAsset.bindings"/>
  88. IEnumerable<InputBinding> bindings { get; }
  89. /// <summary>
  90. /// Find an <see cref="InputAction"/> in the collection by its <see cref="InputAction.name"/> or
  91. /// by its <see cref="InputAction.id"/> (in string form).
  92. /// </summary>
  93. /// <param name="actionNameOrId">Name of the action as either a "map/action" combination (e.g. "gameplay/fire") or
  94. /// a simple name. In the former case, the name is split at the '/' slash and the first part is used to find
  95. /// a map with that name and the second part is used to find an action with that name inside the map. In the
  96. /// latter case, all maps are searched in order and the first action that has the given name in any of the maps
  97. /// is returned. Note that name comparisons are case-insensitive.
  98. ///
  99. /// Alternatively, the given string can be a GUID as given by <see cref="InputAction.id"/>.</param>
  100. /// <param name="throwIfNotFound">If <c>true</c>, instead of returning <c>null</c> when the action
  101. /// cannot be found, throw <c>ArgumentException</c>.</param>
  102. /// <returns>The action with the corresponding name or <c>null</c> if no matching action could be found.</returns>
  103. /// <exception cref="ArgumentNullException"><paramref name="actionNameOrId"/> is <c>null</c>.</exception>
  104. /// <exception cref="ArgumentException">Thrown if <paramref name="throwIfNotFound"/> is true and the
  105. /// action could not be found. -Or- If <paramref name="actionNameOrId"/> contains a slash but is missing
  106. /// either the action or the map name.</exception>
  107. InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false);
  108. /// <summary>
  109. /// Find the index of the first binding that matches the given mask.
  110. /// </summary>
  111. /// <param name="mask">A binding. See <see cref="InputBinding.Matches"/> for details.</param>
  112. /// <param name="action">Receives the action on which the binding was found. If none was found,
  113. /// will be set to <c>null</c>.</param>
  114. /// <returns>Index into <see cref="InputAction.bindings"/> of <paramref name="action"/> of the binding
  115. /// that matches <paramref name="mask"/>. If no binding matches, will return -1.</returns>
  116. /// <remarks>
  117. /// For details about matching bindings by a mask, see <see cref="InputBinding.Matches"/>.
  118. ///
  119. /// <example>
  120. /// <code>
  121. /// var index = playerInput.actions.FindBinding(
  122. /// new InputBinding { path = "&lt;Gamepad&gt;/buttonSouth" },
  123. /// out var action);
  124. ///
  125. /// if (index != -1)
  126. /// Debug.Log($"The A button is bound to {action}");
  127. /// </code>
  128. /// </example>
  129. /// </remarks>
  130. /// <seealso cref="InputBinding.Matches"/>
  131. /// <seealso cref="bindings"/>
  132. int FindBinding(InputBinding mask, out InputAction action);
  133. }
  134. }