// 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 { /// /// Describes the haptic capabilities of a specific device. /// public struct HapticCapabilities { /// /// Initializes and returns an instance of . /// /// The number of haptic channels available on this device. /// This device supports sending a haptic impulse. /// This device supports sending a haptic buffer. /// The buffer frequency the device operates at in Hertz. /// The max amount of buffer data that can be stored by the device. /// The optimal size of a device's buffer, taking into account frequency and latency. public HapticCapabilities(uint numChannels, bool supportsImpulse, bool supportsBuffer, uint frequencyHz, uint maxBufferSize, uint optimalBufferSize) { this.numChannels = numChannels; this.supportsImpulse = supportsImpulse; this.supportsBuffer = supportsBuffer; this.frequencyHz = frequencyHz; this.maxBufferSize = maxBufferSize; this.optimalBufferSize = optimalBufferSize; } /// /// Deprecated. Use instead. /// This constructor did not match the native haptic capabilities struct and was missing properties. /// /// The number of haptic channels available on this device. /// The buffer frequency the device operates at in Hertz. /// The max amount of buffer data that can be stored by the device. public HapticCapabilities(uint numChannels, uint frequencyHz, uint maxBufferSize) : this(numChannels, false, false, frequencyHz, maxBufferSize, 0U) { } /// /// The number of haptic channels available on this device. /// public uint numChannels { get; } /// /// This device supports sending a haptic impulse. /// /// public bool supportsImpulse { get; } /// /// This device supports sending a haptic buffer. /// /// public bool supportsBuffer { get; } /// /// The buffer frequency the device operates at in Hertz. This impacts how fast the device consumes buffered haptic data. /// /// /// This value is greater than 0 if is , and 0 otherwise. /// public uint frequencyHz { get; } /// /// The max amount of buffer data that can be stored by the device. /// public uint maxBufferSize { get; } /// /// The optimal size of a device's buffer, taking into account frequency and latency. /// public uint optimalBufferSize { get; } } /// /// Input device command struct for retrieving the haptic capabilities of a device. /// [StructLayout(LayoutKind.Explicit, Size = kSize)] public struct GetHapticCapabilitiesCommand : IInputDeviceCommandInfo { static FourCC Type => new FourCC('X', 'H', 'C', '0'); // 20 bytes of data from uint(4) + bool(1) + bool(1) + padding + uint(4) + uint(4) + uint(4) const int kSize = InputDeviceCommand.kBaseCommandSize + 20; /// public FourCC typeStatic => Type; [FieldOffset(0)] InputDeviceCommand baseCommand; /// /// The number of haptic channels available on this device. /// [FieldOffset(InputDeviceCommand.kBaseCommandSize)] public uint numChannels; /// /// This device supports sending a haptic impulse. /// /// [FieldOffset(InputDeviceCommand.kBaseCommandSize + 4)] public bool supportsImpulse; /// /// This device supports sending a haptic buffer. /// /// [FieldOffset(InputDeviceCommand.kBaseCommandSize + 5)] public bool supportsBuffer; /// /// The buffer frequency the device operates at in Hertz. This impacts how fast the device consumes buffered haptic data. /// /// /// This value is greater than 0 if is , and 0 otherwise. /// [FieldOffset(InputDeviceCommand.kBaseCommandSize + 8)] public uint frequencyHz; /// /// The max amount of buffer data that can be stored by the device. /// [FieldOffset(InputDeviceCommand.kBaseCommandSize + 12)] public uint maxBufferSize; /// /// The optimal size of a device's buffer, taking into account frequency and latency. /// [FieldOffset(InputDeviceCommand.kBaseCommandSize + 16)] public uint optimalBufferSize; /// /// The haptic capabilities of the device, populated after this command is executed. /// public HapticCapabilities capabilities => new HapticCapabilities(numChannels, supportsImpulse, supportsBuffer, frequencyHz, maxBufferSize, optimalBufferSize); /// /// Creates and returns a new initialized input device command struct for retrieving /// the haptic capabilities of a device when executed. /// /// Returns a new command struct with the data header initialized, making it ready to execute. /// public static GetHapticCapabilitiesCommand Create() { return new GetHapticCapabilitiesCommand { baseCommand = new InputDeviceCommand(Type, kSize), }; } } } #endif