Beispiel #1
0
    //calling default vibration
    public void Vibration(int playerId)
    {
#if UNITY_SWITCH
        foreach (Joystick joystick in ReInput.players.GetPlayer(playerId).controllers.Joysticks)
        {
            // Get the Switch Gamepad Extension from the Joystick
            ISwitchVibrationDevice ext = joystick.GetExtension <ISwitchVibrationDevice>();
            if (ext != null)
            {
                // Create a new SwitchVibration
                // You could also use the SetVibration overload that takes 5 float values instead
                SwitchVibration vib = new SwitchVibration()
                {
                    amplitudeLow  = 1f,
                    frequencyLow  = 50,
                    amplitudeHigh = 0.5f,
                    frequencyHigh = 100
                };

                // Send the vibration to the controller
                for (int i = 0; i < ext.vibrationMotorCount; i++)
                {
                    ext.SetVibration(i, vib); // set vibration in each motor
                }
            }
        }
#endif
    }
Beispiel #2
0
    //calling custom vibration
    public void CustomVibration(int playerId, VibrationType vT)
    {
#if UNITY_SWITCH
        VibrationTypeClass vibrationToFire = VibrationType.Where(r => r.VibrationT == vT).First();
        foreach (Joystick joystick in ReInput.players.GetPlayer(playerId).controllers.Joysticks)
        {
            // Get the Switch Gamepad Extension from the Joystick
            ISwitchVibrationDevice ext = joystick.GetExtension <ISwitchVibrationDevice>();
            if (ext != null)
            {
                for (int i = 0; i < ext.vibrationMotorCount; i++)
                {
                    ext.SetVibration(i, vibrationToFire.vibFile); // Pass the BNVIB file as a byte array
                }
            }
        }
#endif
    }