Skip to content

Commit cd53351

Browse files
authored
DOCS: Update ButtonControl API docs (#2070)
1 parent 39deb60 commit cd53351

File tree

1 file changed

+58
-16
lines changed

1 file changed

+58
-16
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>

0 commit comments

Comments
 (0)