// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) || PACKAGE_DOCS_GENERATION
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
namespace UnityEngine.InputSystem.XR.Haptics
{
///
/// A device command sent to a device to set it's motor rumble amplitude for a set duration.
///
/// This is directly used by the class. For clearer details of using this command, see that class.
[StructLayout(LayoutKind.Explicit, Size = kSize)]
public struct SendHapticImpulseCommand : IInputDeviceCommandInfo
{
static FourCC Type => new FourCC('X', 'H', 'I', '0');
private const int kSize = InputDeviceCommand.kBaseCommandSize + sizeof(int) + (sizeof(float) * 2);
[FieldOffset(0)]
InputDeviceCommand baseCommand;
[FieldOffset(InputDeviceCommand.kBaseCommandSize)]
private int channel;
[FieldOffset(InputDeviceCommand.kBaseCommandSize + sizeof(int))]
private float amplitude;
[FieldOffset(InputDeviceCommand.kBaseCommandSize + sizeof(int) + (sizeof(float)))]
private float duration;
public FourCC typeStatic => Type;
///
/// Creates a device command that can then be sent to a specific device.
///
/// The desired motor you want to rumble
/// The desired motor amplitude that should be within a [0-1] range.
/// The desired duration of the impulse in seconds.
/// The command that should be sent to the device via InputDevice.ExecuteCommand.
public static SendHapticImpulseCommand Create(int motorChannel, float motorAmplitude, float motorDuration)
{
return new SendHapticImpulseCommand
{
baseCommand = new InputDeviceCommand(Type, kSize),
channel = motorChannel,
amplitude = motorAmplitude,
duration = motorDuration
};
}
}
}
#endif