Skip to content

Commit ccdf867

Browse files
authored
Merge branch 'develop' into docs-quality-week-2024-inputstatehistory
2 parents 4413a00 + c9d686d commit ccdf867

File tree

3 files changed

+497
-162
lines changed

3 files changed

+497
-162
lines changed

Packages/com.unity.inputsystem/InputSystem/Controls/ButtonControl.cs

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace UnityEngine.InputSystem.Controls
1010
/// An axis that has a trigger point beyond which it is considered to be pressed.
1111
/// </summary>
1212
/// <remarks>
13-
/// By default stored as a single bit. In that format, buttons will only yield 0
13+
/// By default, stored as a single bit. In that format, buttons will only yield 0
1414
/// and 1 as values. However, buttons return are <see cref="AxisControl"/>s and
1515
/// yield full floating-point values and may thus have a range of values. See
1616
/// <see cref="pressPoint"/> for how button presses on such buttons are handled.
@@ -46,6 +46,9 @@ public class ButtonControl : AxisControl
4646
///
4747
/// <example>
4848
/// <code>
49+
/// using UnityEngine;
50+
/// using UnityEngine.InputSystem.Controls;
51+
///
4952
/// public class MyDevice : InputDevice
5053
/// {
5154
/// [InputControl(parameters = "pressPoint=0.234")]
@@ -56,25 +59,38 @@ public class ButtonControl : AxisControl
5659
/// </code>
5760
/// </example>
5861
/// </remarks>
59-
/// <seealso cref="InputSettings.defaultButtonPressPoint"/>
60-
/// <seealso cref="pressPointOrDefault"/>
61-
/// <seealso cref="isPressed"/>
6262
public float pressPoint = -1;
6363

6464
/// <summary>
6565
/// Return <see cref="pressPoint"/> if set, otherwise return <see cref="InputSettings.defaultButtonPressPoint"/>.
6666
/// </summary>
6767
/// <value>Effective value to use for press point thresholds.</value>
68-
/// <seealso cref="InputSettings.defaultButtonPressPoint"/>
6968
public float pressPointOrDefault => pressPoint > 0 ? pressPoint : s_GlobalDefaultButtonPressPoint;
7069

7170
/// <summary>
72-
/// Default-initialize the control.
71+
/// Default-initialize the button control.
7372
/// </summary>
7473
/// <remarks>
75-
/// The default format for the control is <see cref="InputStateBlock.FormatBit"/>.
76-
/// The control's minimum value is set to 0 and the maximum value to 1.
74+
/// The default format for the button control is <see cref="InputStateBlock.FormatBit"/>.
75+
/// The button control's minimum value is set to 0 and the maximum value to 1.
7776
/// </remarks>
77+
/// <example>
78+
/// <code>
79+
/// using UnityEngine;
80+
/// using UnityEngine.InputSystem.Controls;
81+
///
82+
/// public class ButtonControlExample : MonoBehaviour
83+
/// {
84+
/// void Start()
85+
/// {
86+
/// var myButton = new ButtonControl();
87+
/// }
88+
///
89+
/// //...
90+
/// }
91+
/// </code>
92+
/// </example>
93+
/// <seealso cref="AxisControl"/>
7894
public ButtonControl()
7995
{
8096
m_StateBlock.format = InputStateBlock.FormatBit;
@@ -85,10 +101,39 @@ public ButtonControl()
85101
/// <summary>
86102
/// Whether the given value would be considered pressed for this button.
87103
/// </summary>
88-
/// <param name="value">Value for the button.</param>
104+
/// <param name="value">Value to check for if the button would be considered pressed or not.</param>
89105
/// <returns>True if <paramref name="value"/> crosses the threshold to be considered pressed.</returns>
90-
/// <seealso cref="pressPoint"/>
91-
/// <seealso cref="InputSettings.defaultButtonPressPoint"/>
106+
/// <remarks>
107+
/// The default format for the control is <see cref="InputStateBlock.FormatBit"/>.
108+
/// The control's minimum value is set to 0 and the maximum value to 1.
109+
/// See <see cref="InputSettings.defaultButtonPressPoint"/> for the default press point.
110+
/// </remarks>
111+
/// <example>
112+
/// <code>
113+
/// using UnityEngine;
114+
/// using UnityEngine.InputSystem.Controls;
115+
///
116+
/// public class IsValueConsideredPressedExample : MonoBehaviour
117+
/// {
118+
/// void Start()
119+
/// {
120+
/// var myButton = new ButtonControl();
121+
/// var valueToTest = 0.5f;
122+
///
123+
/// if (myButton.IsValueConsideredPressed(valueToTest))
124+
/// {
125+
/// Debug.Log("myButton is considered pressed at: " + valueToTest.ToString());
126+
/// }
127+
/// else
128+
/// {
129+
/// Debug.Log("myButton is not considered pressed at: " + valueToTest.ToString());
130+
/// }
131+
/// }
132+
///
133+
/// //...
134+
/// }
135+
/// </code>
136+
/// </example>
92137
[MethodImpl(MethodImplOptions.AggressiveInlining)]
93138
public new bool IsValueConsideredPressed(float value)
94139
{
@@ -149,9 +194,6 @@ public ButtonControl()
149194
/// ]]>
150195
/// </code>
151196
/// </example>
152-
/// <seealso cref="InputSettings.defaultButtonPressPoint"/>
153-
/// <seealso cref="pressPoint"/>
154-
/// <seealso cref="InputSystem.onAnyButtonPress"/>
155197
public bool isPressed
156198
{
157199
get
@@ -276,8 +318,8 @@ public bool wasPressedThisFrame
276318
/// {
277319
/// void Update()
278320
/// {
279-
/// bool buttonPressed = Gamepad.current.aButton.wasReleasedThisFrame;
280-
/// bool spaceKeyPressed = Keyboard.current.spaceKey.wasReleasedThisFrame;
321+
/// bool buttonReleased = Gamepad.current.aButton.wasReleasedThisFrame;
322+
/// bool spaceKeyReleased = Keyboard.current.spaceKey.wasReleasedThisFrame;
281323
/// }
282324
/// }
283325
/// </code>

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

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ namespace UnityEngine.InputSystem
2222
public class InputValue
2323
{
2424
/// <summary>
25-
/// Read the value as an object.
25+
/// Read the current 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,45 @@ public object Get()
3535
}
3636

3737
////TODO: add automatic conversions
38+
/// <summary>
39+
/// Read the current 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+
/// <see cref="InputControl.valueType"/> of the action or, if it is a composite, by the
44+
/// <see cref="InputBindingComposite.valueType"/>.
45+
/// The type depends on what type of controls the action is bound to.
46+
/// Common types are <c>float</c> and <see cref="UnityEngine.Vector2"/></typeparam>
47+
/// <exception cref="InvalidOperationException">The given type <typeparamref name="TValue"/>
48+
/// does not match the value type expected by the control or binding composite.</exception>
49+
/// <remarks>
50+
/// The following example shows how to read a value from a <see cref="PlayerInput"/> message.
51+
/// The given <c>InputValue</c> is only valid for the duration of the callback. Storing the <c>InputValue</c> references somewhere and calling Get&lt;T&gt;() later does not work correctly.
52+
/// </remarks>
53+
/// <example>
54+
/// <code>
55+
/// using UnityEngine;
56+
/// using UnityEngine.InputSystem;
57+
/// [RequireComponent(typeof(PlayerInput))]
58+
/// public class MyPlayerLogic : MonoBehaviour
59+
/// {
60+
/// private Vector2 m_Move;
61+
///
62+
/// // 'Move' input action has been triggered.
63+
/// public void OnMove(InputValue value)
64+
/// {
65+
/// // Read value from control. The type depends on what type of controls the action is bound to.
66+
/// m_Move = value.Get&lt;Vector2&gt;();
67+
/// }
68+
///
69+
/// public void Update()
70+
/// {
71+
/// // Update transform from m_Move
72+
/// }
73+
/// }
74+
/// </code>
75+
/// </example>
76+
/// <seealso cref="InputAction.CallbackContext.ReadValue{TValue}"/>
3877
public TValue Get<TValue>()
3978
where TValue : struct
4079
{
@@ -45,6 +84,34 @@ public TValue Get<TValue>()
4584
}
4685

4786
////TODO: proper message if value type isn't right
87+
/// <summary>
88+
/// Check if the action button is pressed.
89+
/// </summary>
90+
/// <remarks>
91+
/// True if the button is activated over the button threshold. False otherwise
92+
/// The following example check if a button is pressed when receiving a <see cref="PlayerInput"/> message.
93+
/// The given <c>InputValue</c> is only valid for the duration of the callback. Storing the <c>InputValue</c> references somewhere and calling Get&lt;T&gt;() later does not work correctly.
94+
/// </remarks>
95+
/// <example>
96+
/// <code>
97+
/// [RequireComponent(typeof(PlayerInput))]
98+
/// public class MyPlayerLogic : MonoBehaviour
99+
/// {
100+
/// // 'Fire' input action has been triggered.
101+
/// public void OnFire(InputValue value)
102+
/// {
103+
/// if (value.isPressed)
104+
/// FireWeapon();
105+
/// }
106+
///
107+
/// public void FireWeapon()
108+
/// {
109+
/// // Weapon firing code
110+
/// }
111+
/// }
112+
/// </code>
113+
/// </example>
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)