Skip to content

Commit 05d23b8

Browse files
committed
Updated InputValue documentation
Updated InputValue documentation
1 parent 59c7c40 commit 05d23b8

File tree

1 file changed

+68
-1
lines changed
  • Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput

1 file changed

+68
-1
lines changed

Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class InputValue
2525
/// Read the value as an object.
2626
/// </summary>
2727
/// <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,
2929
/// it will lead to GC spikes.
3030
/// </remarks>
3131
/// <returns>The current value in the form of a boxed object.</returns>
@@ -35,6 +35,43 @@ public object Get()
3535
}
3636

3737
////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&lt;Vector2&gt;();
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&lt;T&gt;() later does not work correctly.
73+
/// </remarks>
74+
/// <seealso cref="CallbackContext.ReadValue{TValue}"/>
3875
public TValue Get<TValue>()
3976
where TValue : struct
4077
{
@@ -45,6 +82,36 @@ public TValue Get<TValue>()
4582
}
4683

4784
////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&lt;T&gt;() later does not work correctly.
113+
/// </remarks>
114+
/// <seealso cref="ButtonControl.pressPointOrDefault"/>
48115
public bool isPressed => Get<float>() >= ButtonControl.s_GlobalDefaultButtonPressPoint;
49116

50117
internal InputAction.CallbackContext? m_Context;

0 commit comments

Comments
 (0)