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.
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.
buttonSouth
exists for "Joy-Con (L)", but it is never used. Whenever you want to refer to the player pressing the "A" button, make sure the device is either "Joy-Con (R)" or "Pro Controller"..inputactions
file and add them manually.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).
buttonEast
, buttonSouth
, buttonNorth
, and buttonEast
respectivelydpad
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
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.
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.
Fork of the repository [JoyConUnityInputSystem]https://github.com/Meorge/JoyConUnityInputSystem by Meorge, which is itself largely based on:
SwitchControllerFullInputReport.ToHIDInputReport()
method follows the implementation in SwitchFullInputReport.SwitchControllerHID.PreProcessEvent()
method is an expanded version of the implementation in SwitchProControllerHID.SwitchControllerVirtualInputState
class is an expanded version of SwitchProControllerHIDInputState, with support added for Joy-Cons and IMU data. The format was changed from "SPVS" to "SCVS", since it also supports Joy-Cons.