A game about forced loneliness, made by TACStudios
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 56 lines 2.2 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 [StructLayout(LayoutKind.Explicit, Size = kSize)] 10 public unsafe struct SendBufferedHapticCommand : IInputDeviceCommandInfo 11 { 12 static FourCC Type => new FourCC('X', 'H', 'U', '0'); 13 14 private const int kMaxHapticBufferSize = 1024; 15 private const int kSize = InputDeviceCommand.kBaseCommandSize + (sizeof(int) * 2) + (kMaxHapticBufferSize * sizeof(byte)); 16 17 public FourCC typeStatic => Type; 18 19 [FieldOffset(0)] 20 private InputDeviceCommand baseCommand; 21 22 [FieldOffset(InputDeviceCommand.kBaseCommandSize)] 23 private int channel; 24 25 [FieldOffset(InputDeviceCommand.kBaseCommandSize + sizeof(int))] 26 private int bufferSize; 27 28 [FieldOffset(InputDeviceCommand.kBaseCommandSize + (sizeof(int) * 2))] 29 private fixed byte buffer[kMaxHapticBufferSize]; 30 31 public static SendBufferedHapticCommand Create(byte[] rumbleBuffer) 32 { 33 if (rumbleBuffer == null) 34 throw new System.ArgumentNullException(nameof(rumbleBuffer)); 35 36 var rumbleBufferSize = Mathf.Min(kMaxHapticBufferSize, rumbleBuffer.Length); 37 var newCommand = new SendBufferedHapticCommand 38 { 39 baseCommand = new InputDeviceCommand(Type, kSize), 40 bufferSize = rumbleBufferSize 41 }; 42 43 //TODO TOMB: There must be a more effective, bulk copy operation for fixed buffers than this. 44 //Replace if found. 45 var commandPtr = &newCommand; 46 fixed(byte* src = rumbleBuffer) 47 { 48 for (int cpyIndex = 0; cpyIndex < rumbleBufferSize; cpyIndex++) 49 commandPtr->buffer[cpyIndex] = src[cpyIndex]; 50 } 51 52 return newCommand; 53 } 54 } 55} 56#endif