Skip to content

Commit 6ff8dc2

Browse files
authored
Merge branch 'develop' into isxb-1129-new-control-scheme-device-index
2 parents e9ad9b0 + 6798213 commit 6ff8dc2

File tree

9 files changed

+266
-80
lines changed

9 files changed

+266
-80
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.

0 commit comments

Comments
 (0)