Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Packages/com.unity.inputsystem/DocCodeSamples.Tests.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Unity.InputSystem.DocCodeSamples",
"rootNamespace": "",
"references": [
"GUID:75469ad4d38634e559750d17036d5f7c"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using UnityEngine;
using UnityEngine.InputSystem;

namespace DocCodeSamples.Tests
{
internal class GamepadExample : MonoBehaviour
{
void Start()
{
// Print all connected gamepads
Debug.Log(string.Join("\n", Gamepad.all));
}

void Update()
{
var gamepad = Gamepad.current;

// No gamepad connected.
if (gamepad == null)
{
return;
}

// Check if "Button North" was pressed this frame
if (gamepad.buttonNorth.wasPressedThisFrame)
{
Debug.Log("Button North was pressed");
}

// Check if the button control is being continuously actuated and read its value
if (gamepad.rightTrigger.IsActuated())
{
Debug.Log("Right trigger value: " + gamepad.rightTrigger.ReadValue());
}

// Read left stick value and perform some code based on the value
Vector2 move = gamepad.leftStick.ReadValue();
{
// Use the Vector2 move for the game logic here
}

// Creating haptic feedback while "Button South" is pressed and stopping it when released.
if (gamepad.buttonSouth.wasPressedThisFrame)
{
gamepad.SetMotorSpeeds(0.2f, 1.0f);
}
else if (gamepad.buttonSouth.wasReleasedThisFrame)
{
gamepad.ResetHaptics();
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using UnityEngine;
using UnityEngine.InputSystem;

namespace DocCodeSamples.Tests
{
internal class GamepadHapticsExample : MonoBehaviour
{
bool hapticsArePaused = false;

void Update()
{
var gamepad = Gamepad.current;

// No gamepad connected, no need to continue.
if (gamepad == null)
return;

float leftTrigger = gamepad.leftTrigger.ReadValue();
float rightTrigger = gamepad.rightTrigger.ReadValue();

// Only set motor speeds if haptics were not paused and if trigger is actuated.
// Both triggers must be actuated past 0.2f to start haptics.
if (!hapticsArePaused &&
(gamepad.leftTrigger.IsActuated() || gamepad.rightTrigger.IsActuated()))
gamepad.SetMotorSpeeds(
leftTrigger < 0.2f ? 0.0f : leftTrigger,
rightTrigger < 0.2f ? 0.0f : rightTrigger);

// Toggle haptics "playback" when "Button South" is pressed.
// Notice that if you release the triggers after pausing,
// and press the button again, haptics will resume.
if (gamepad.buttonSouth.wasPressedThisFrame)
{
if (hapticsArePaused)
gamepad.ResumeHaptics();
else
gamepad.PauseHaptics();

hapticsArePaused = !hapticsArePaused;
}

// Notice that if you release the triggers after pausing,
// and press the Start button, haptics will be reset.
if (gamepad.startButton.wasPressedThisFrame)
gamepad.ResetHaptics();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading