Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

SendBufferedHapticsCommand.cs 2.1KB

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