Skip to content

Commit 6a129dc

Browse files
authored
Merge branch 'develop' into isxb-1269-fix-inputactions-processor-in-the-inspector
2 parents b92def3 + 6798213 commit 6a129dc

File tree

13 files changed

+900
-243
lines changed

13 files changed

+900
-243
lines changed

Packages/com.unity.inputsystem/DocCodeSamples.Tests.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "Unity.InputSystem.DocCodeSamples",
3+
"rootNamespace": "",
4+
"references": [
5+
"GUID:75469ad4d38634e559750d17036d5f7c"
6+
],
7+
"includePlatforms": [],
8+
"excludePlatforms": [],
9+
"allowUnsafeCode": false,
10+
"overrideReferences": true,
11+
"precompiledReferences": [],
12+
"autoReferenced": false,
13+
"defineConstraints": [],
14+
"versionDefines": [],
15+
"noEngineReferences": false
16+
}

Packages/com.unity.inputsystem/DocCodeSamples.Tests/DocCodeSamples.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using UnityEngine;
2+
using UnityEngine.InputSystem;
3+
4+
namespace DocCodeSamples.Tests
5+
{
6+
internal class GamepadExample : MonoBehaviour
7+
{
8+
void Start()
9+
{
10+
// Print all connected gamepads
11+
Debug.Log(string.Join("\n", Gamepad.all));
12+
}
13+
14+
void Update()
15+
{
16+
var gamepad = Gamepad.current;
17+
18+
// No gamepad connected.
19+
if (gamepad == null)
20+
{
21+
return;
22+
}
23+
24+
// Check if "Button North" was pressed this frame
25+
if (gamepad.buttonNorth.wasPressedThisFrame)
26+
{
27+
Debug.Log("Button North was pressed");
28+
}
29+
30+
// Check if the button control is being continuously actuated and read its value
31+
if (gamepad.rightTrigger.IsActuated())
32+
{
33+
Debug.Log("Right trigger value: " + gamepad.rightTrigger.ReadValue());
34+
}
35+
36+
// Read left stick value and perform some code based on the value
37+
Vector2 move = gamepad.leftStick.ReadValue();
38+
{
39+
// Use the Vector2 move for the game logic here
40+
}
41+
42+
// Creating haptic feedback while "Button South" is pressed and stopping it when released.
43+
if (gamepad.buttonSouth.wasPressedThisFrame)
44+
{
45+
gamepad.SetMotorSpeeds(0.2f, 1.0f);
46+
}
47+
else if (gamepad.buttonSouth.wasReleasedThisFrame)
48+
{
49+
gamepad.ResetHaptics();
50+
}
51+
}
52+
}
53+
}

Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadExample.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using UnityEngine;
2+
using UnityEngine.InputSystem;
3+
4+
namespace DocCodeSamples.Tests
5+
{
6+
internal class GamepadHapticsExample : MonoBehaviour
7+
{
8+
bool hapticsArePaused = false;
9+
10+
void Update()
11+
{
12+
var gamepad = Gamepad.current;
13+
14+
// No gamepad connected, no need to continue.
15+
if (gamepad == null)
16+
return;
17+
18+
float leftTrigger = gamepad.leftTrigger.ReadValue();
19+
float rightTrigger = gamepad.rightTrigger.ReadValue();
20+
21+
// Only set motor speeds if haptics were not paused and if trigger is actuated.
22+
// Both triggers must be actuated past 0.2f to start haptics.
23+
if (!hapticsArePaused &&
24+
(gamepad.leftTrigger.IsActuated() || gamepad.rightTrigger.IsActuated()))
25+
gamepad.SetMotorSpeeds(
26+
leftTrigger < 0.2f ? 0.0f : leftTrigger,
27+
rightTrigger < 0.2f ? 0.0f : rightTrigger);
28+
29+
// Toggle haptics "playback" when "Button South" is pressed.
30+
// Notice that if you release the triggers after pausing,
31+
// and press the button again, haptics will resume.
32+
if (gamepad.buttonSouth.wasPressedThisFrame)
33+
{
34+
if (hapticsArePaused)
35+
gamepad.ResumeHaptics();
36+
else
37+
gamepad.PauseHaptics();
38+
39+
hapticsArePaused = !hapticsArePaused;
40+
}
41+
42+
// Notice that if you release the triggers after pausing,
43+
// and press the Start button, haptics will be reset.
44+
if (gamepad.startButton.wasPressedThisFrame)
45+
gamepad.ResetHaptics();
46+
}
47+
}
48+
}

Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadHapticsExample.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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)