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