You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs
+68-1Lines changed: 68 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ public class InputValue
25
25
/// Read the value as an object.
26
26
/// </summary>
27
27
/// <remarks>
28
-
/// This method allocates GC memory and will thus created garbage. If used during gameplay,
28
+
/// This method allocates GC memory and will thus create garbage. If used during gameplay,
29
29
/// it will lead to GC spikes.
30
30
/// </remarks>
31
31
/// <returns>The current value in the form of a boxed object.</returns>
@@ -35,6 +35,43 @@ public object Get()
35
35
}
36
36
37
37
////TODO: add automatic conversions
38
+
/// <summary>
39
+
/// Read the value of the action.
40
+
/// </summary>
41
+
/// <returns>The current value from the action cast to the specified type.</returns>
42
+
/// <typeparam name="TValue">Type of value to read. This must correspond to the
43
+
/// expected by either <see cref="control"/> or, if it is a composite, by the
44
+
/// <see cref="InputBindingComposite"/> in use.
45
+
/// Common types are float and Vector2, and depend on the type of the associated action</typeparam>
46
+
/// <exception cref="InvalidOperationException">The given type <typeparamref name="TValue"/>
47
+
/// does not match the value type expected by the control or binding composite.</exception>
48
+
/// <remarks>
49
+
/// The following example shows how to read a value from a <see cref="PlayerInput"/> message.
50
+
///
51
+
/// <example>
52
+
/// <code>
53
+
/// [RequireComponent(typeof(PlayerInput))]
54
+
/// public class MyPlayerLogic : MonoBehaviour
55
+
/// {
56
+
/// private Vector2 m_Move;
57
+
///
58
+
/// // 'Move' input action has been triggered.
59
+
/// public void OnMove(InputValue value)
60
+
/// {
61
+
/// // Read value from control. The type depends on what type of controls the action is bound to.
62
+
/// m_Move = value.Get<Vector2>();
63
+
/// }
64
+
///
65
+
/// public void OnUpdate()
66
+
/// {
67
+
/// // Update transform from m_Move
68
+
/// }
69
+
/// }
70
+
/// </code>
71
+
/// </example>
72
+
/// The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly.
////TODO: proper message if value type isn't right
85
+
/// <summary>
86
+
/// Check if the action button is pressed
87
+
/// </summary>
88
+
/// <returns>True if the button is activated over the button threshold. False otherwise</returns>
89
+
/// <remarks>
90
+
/// The following example shows how to read a value from a <see cref="PlayerInput"/> message.
91
+
///
92
+
/// <example>
93
+
/// <code>
94
+
/// [RequireComponent(typeof(PlayerInput))]
95
+
/// public class MyPlayerLogic : MonoBehaviour
96
+
/// {
97
+
/// private bool m_Fire;
98
+
///
99
+
/// // 'Fire' input action has been triggered.
100
+
/// public void OnFire(InputValue value)
101
+
/// {
102
+
/// m_Fire = value.isPressed;
103
+
/// }
104
+
///
105
+
/// public void OnUpdate()
106
+
/// {
107
+
/// // Perform fire action if m_Fire is true
108
+
/// }
109
+
/// }
110
+
/// </code>
111
+
/// </example>
112
+
/// The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly.
0 commit comments