XRSimulatedHMDState.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System.Runtime.InteropServices;
  2. using UnityEngine;
  3. using UnityEngine.InputSystem.Layouts;
  4. using UnityEngine.InputSystem.LowLevel;
  5. using UnityEngine.InputSystem.Utilities;
  6. namespace SC.XR.Unity.Simulation {
  7. /// <summary>
  8. /// State for input device representing a simulated XR HMD.
  9. /// </summary>
  10. [StructLayout(LayoutKind.Explicit, Size = 117)]
  11. public struct XRSimulatedHMDState : IInputStateTypeInfo
  12. {
  13. /// <summary>
  14. /// Memory format identifier for <see cref="XRSimulatedHMDState"/>.
  15. /// </summary>
  16. /// <seealso cref="InputStateBlock.format"/>
  17. public static FourCC formatId => new FourCC('X', 'R', 'S', 'H');
  18. /// <summary>
  19. /// See <a href="https://docs.unity3d.com/Packages/com.unity.inputsystem@1.2/api/UnityEngine.InputSystem.LowLevel.IInputStateTypeInfo.html">IInputStateTypeInfo</a>.format.
  20. /// </summary>
  21. public FourCC format => formatId;
  22. /// <summary>
  23. /// The position of the left eye on this device.
  24. /// </summary>
  25. [InputControl(usage = "LeftEyePosition")]
  26. [FieldOffset(0)]
  27. public Vector3 leftEyePosition;
  28. /// <summary>
  29. /// The rotation of the left eye on this device.
  30. /// </summary>
  31. [InputControl(usage = "LeftEyeRotation")]
  32. [FieldOffset(12)]
  33. public Quaternion leftEyeRotation;
  34. /// <summary>
  35. /// The position of the right eye on this device.
  36. /// </summary>
  37. [InputControl(usage = "RightEyePosition")]
  38. [FieldOffset(28)]
  39. public Vector3 rightEyePosition;
  40. /// <summary>
  41. /// The rotation of the right eye on this device.
  42. /// </summary>
  43. [InputControl(usage = "RightEyeRotation")]
  44. [FieldOffset(40)]
  45. public Quaternion rightEyeRotation;
  46. /// <summary>
  47. /// The position of the center eye on this device.
  48. /// </summary>
  49. [InputControl(usage = "CenterEyePosition")]
  50. [FieldOffset(56)]
  51. public Vector3 centerEyePosition;
  52. /// <summary>
  53. /// The rotation of the center eye on this device.
  54. /// </summary>
  55. [InputControl(usage = "CenterEyeRotation")]
  56. [FieldOffset(68)]
  57. public Quaternion centerEyeRotation;
  58. /// <summary>
  59. /// Represents the values being tracked for this device.
  60. /// </summary>
  61. [InputControl(usage = "TrackingState", layout = "Integer")]
  62. [FieldOffset(84)]
  63. public int trackingState;
  64. /// <summary>
  65. /// Informs to the developer whether the device is currently being tracked.
  66. /// </summary>
  67. [InputControl(usage = "IsTracked", layout = "Button")]
  68. [FieldOffset(88)]
  69. public bool isTracked;
  70. /// <summary>
  71. /// The position of the device.
  72. /// </summary>
  73. [InputControl(usage = "DevicePosition")]
  74. [FieldOffset(89)]
  75. public Vector3 devicePosition;
  76. /// <summary>
  77. /// The rotation of this device.
  78. /// </summary>
  79. [InputControl(usage = "DeviceRotation")]
  80. [FieldOffset(101)]
  81. public Quaternion deviceRotation;
  82. /// <summary>
  83. /// See <see cref="MonoBehaviour"/>.
  84. /// </summary>
  85. public void Reset()
  86. {
  87. leftEyePosition = default;
  88. leftEyeRotation = Quaternion.identity;
  89. rightEyePosition = default;
  90. rightEyeRotation = Quaternion.identity;
  91. centerEyePosition = default;
  92. centerEyeRotation = Quaternion.identity;
  93. trackingState = default;
  94. isTracked = default;
  95. devicePosition = default;
  96. deviceRotation = Quaternion.identity;
  97. }
  98. }
  99. }