GetCurrentHapticStateCommand.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #if UNITY_INPUT_SYSTEM_ENABLE_XR || PACKAGE_DOCS_GENERATION
  2. using System.Runtime.InteropServices;
  3. using UnityEngine.InputSystem.Utilities;
  4. using UnityEngine.InputSystem.LowLevel;
  5. namespace UnityEngine.InputSystem.XR.Haptics
  6. {
  7. public struct HapticState
  8. {
  9. public HapticState(uint samplesQueued, uint samplesAvailable)
  10. {
  11. this.samplesQueued = samplesQueued;
  12. this.samplesAvailable = samplesAvailable;
  13. }
  14. public uint samplesQueued { get; private set; }
  15. public uint samplesAvailable { get; private set; }
  16. }
  17. [StructLayout(LayoutKind.Explicit, Size = kSize)]
  18. public struct GetCurrentHapticStateCommand : IInputDeviceCommandInfo
  19. {
  20. static FourCC Type => new FourCC('X', 'H', 'S', '0');
  21. const int kSize = InputDeviceCommand.kBaseCommandSize + (sizeof(uint) * 2);
  22. public FourCC typeStatic => Type;
  23. [FieldOffset(0)]
  24. InputDeviceCommand baseCommand;
  25. [FieldOffset(InputDeviceCommand.kBaseCommandSize)]
  26. public uint samplesQueued;
  27. [FieldOffset(InputDeviceCommand.kBaseCommandSize + sizeof(int))]
  28. public uint samplesAvailable;
  29. public HapticState currentState => new HapticState(samplesQueued, samplesAvailable);
  30. public static GetCurrentHapticStateCommand Create()
  31. {
  32. return new GetCurrentHapticStateCommand
  33. {
  34. baseCommand = new InputDeviceCommand(Type, kSize),
  35. };
  36. }
  37. }
  38. }
  39. #endif // UNITY_INPUT_SYSTEM_ENABLE_XR