// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
// These are the guards that Input System uses to define the SendHapticImpulseCommand class.
#if ENABLE_VR || UNITY_GAMECORE
#define INPUT_HAPTICS_AVAILABLE
#endif
#if INPUT_HAPTICS_AVAILABLE
using UnityEngine.InputSystem.XR.Haptics;
#endif
namespace UnityEngine.XR.Interaction.Toolkit.Inputs.Haptics
{
///
/// Allows for sending haptic impulses to a channel on a device from the input system.
///
///
///
public class HapticImpulseCommandChannel : IXRHapticImpulseChannel
{
///
/// The channel to receive the impulse.
///
public int motorChannel { get; set; }
///
/// The input device to send the impulse to.
///
public InputSystem.InputDevice device { get; set; }
///
public bool SendHapticImpulse(float amplitude, float duration, float frequency)
{
#if INPUT_HAPTICS_AVAILABLE
if (device == null)
return false;
// The command does not yet support specifying the frequency.
var command = SendHapticImpulseCommand.Create(motorChannel, amplitude, duration);
return device.ExecuteCommand(ref command) >= 0L;
#else
return false;
#endif
}
}
}