A game about forced loneliness, made by TACStudios
at master 53 lines 2.4 kB view raw
1// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled. 2#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) || PACKAGE_DOCS_GENERATION 3using System.Runtime.InteropServices; 4using UnityEngine.InputSystem.LowLevel; 5using UnityEngine.InputSystem.Utilities; 6 7namespace UnityEngine.InputSystem.XR.Haptics 8{ 9 /// <summary> 10 /// A device command sent to a device to set it's motor rumble amplitude for a set duration. 11 /// </summary> 12 /// <remarks>This is directly used by the <see cref="XRControllerWithRumble"/> class. For clearer details of using this command, see that class.</remarks> 13 [StructLayout(LayoutKind.Explicit, Size = kSize)] 14 public struct SendHapticImpulseCommand : IInputDeviceCommandInfo 15 { 16 static FourCC Type => new FourCC('X', 'H', 'I', '0'); 17 18 private const int kSize = InputDeviceCommand.kBaseCommandSize + sizeof(int) + (sizeof(float) * 2); 19 20 [FieldOffset(0)] 21 InputDeviceCommand baseCommand; 22 23 [FieldOffset(InputDeviceCommand.kBaseCommandSize)] 24 private int channel; 25 26 [FieldOffset(InputDeviceCommand.kBaseCommandSize + sizeof(int))] 27 private float amplitude; 28 29 [FieldOffset(InputDeviceCommand.kBaseCommandSize + sizeof(int) + (sizeof(float)))] 30 private float duration; 31 32 public FourCC typeStatic => Type; 33 34 /// <summary> 35 /// Creates a device command that can then be sent to a specific device. 36 /// </summary> 37 /// <param name="motorChannel">The desired motor you want to rumble</param> 38 /// <param name="motorAmplitude">The desired motor amplitude that should be within a [0-1] range.</param> 39 /// <param name="motorDuration">The desired duration of the impulse in seconds.</param> 40 /// <returns>The command that should be sent to the device via <c>InputDevice.ExecuteCommand</c>.</returns> 41 public static SendHapticImpulseCommand Create(int motorChannel, float motorAmplitude, float motorDuration) 42 { 43 return new SendHapticImpulseCommand 44 { 45 baseCommand = new InputDeviceCommand(Type, kSize), 46 channel = motorChannel, 47 amplitude = motorAmplitude, 48 duration = motorDuration 49 }; 50 } 51 } 52} 53#endif