Meorge / JoyConUnityInputSystem

9 stars 4 forks source link

Nintendo Switch Controllers for Unity Input System

This is a prototype for Nintendo Switch controller Bluetooth support for the new Unity Input System, brought to compatibility with the latest versions of Unity and its InputSystem package.

Installation

Using the Unity Package Manager, add the package from the following git URL: https://forge.icube.unistra.fr/invirtuo/stereolab.git?path=/Packages/fr.icube.gaia.stereolab.

Notes

Supported controllers

Supported features

Device data analysis

General data about the connected Switch controllers can be found in the menu Windows/Switch Controller Debugger/Joycon Device Data. This however doesn't include the input data, which can be found instead Windows/Analysis/Input Debugger (as well as the input data of every other controller).

Input

HD Rumble: WIP

High-band and low-band amplitude and frequency for the left and right Joy-Cons (or, in the case of the Pro Controller, the left and right sides of the controller) can be set with the SwitchControllerHID.Rumble() method.

Example:

var rumbleProfile = new SwitchControllerRumbleProfile
    {
        lowBandFrequencyL = 160f,
        lowBandAmplitudeL = 0.1f,
        lowBandFrequencyR = 150f,
        lowBandAmplitudeR = 0.5f,

        highBandFrequencyL = 200f,
        highBandAmplitudeL = 0.8f,
        highBandFrequencyR = 150f,
        highBandAmplitudeR = 1.0f
    };

controller.Rumble(rumbleProfile);

The HD Rumble features can be tested Windows/Switch Controller Debugger/Joycon Rumble Playground

Gyroscope and acceleration (partial)

Once the controller's IMU has been enabled with SwitchControllerHID.SetIMUEnabled(true), it will report uncalibrated acceleration and gyroscope data. In my testing, this data isn't particularly accurate, so we should figure out how to improve it.

Player LEDs

The green LEDs on the controllers can be set with SwitchControllerHID.SetLEDs().

Example:

controller.SetLEDs(
    p1: SwitchControllerLEDStatusEnum.Off,
    p2: SwitchControllerLEDStatusEnum.On,
    p3: SwitchControllerLEDStatusEnum.Flashing,
    p4: SwitchControllerLEDStatusEnum.On
    );

However, quitting the application doesn't reset the LEDs. If you want them to get back to their initial state, you should either restart the controller or set the LEDs again in the OnApplicationQuit() method of a GameObject.

Credits

Fork of the repository [JoyConUnityInputSystem]https://github.com/Meorge/JoyConUnityInputSystem by Meorge, which is itself largely based on: