XRSimulatedController.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using UnityEngine.InputSystem;
  2. using UnityEngine.InputSystem.Controls;
  3. using UnityEngine.InputSystem.Layouts;
  4. using UnityEngine.Scripting;
  5. namespace SC.XR.Unity.Simulation {
  6. /// <summary>
  7. /// An input device representing a simulated XR handed controller.
  8. /// </summary>
  9. [InputControlLayout(stateType = typeof(XRSimulatedControllerState), commonUsages = new[] { "LeftHand", "RightHand" }, isGenericTypeOfDevice = false, displayName = "XR Simulated Controller"), Preserve]
  10. public class XRSimulatedController : UnityEngine.InputSystem.XR.XRController
  11. {
  12. /// <summary>
  13. /// The primary touchpad or joystick on a device.
  14. /// </summary>
  15. public Vector2Control primary2DAxis { get; private set; }
  16. /// <summary>
  17. /// A trigger-like control, pressed with the index finger.
  18. /// </summary>
  19. public AxisControl trigger { get; private set; }
  20. /// <summary>
  21. /// Represents the users grip on the controller.
  22. /// </summary>
  23. public AxisControl grip { get; private set; }
  24. /// <summary>
  25. /// A secondary touchpad or joystick on a device.
  26. /// </summary>
  27. public Vector2Control secondary2DAxis { get; private set; }
  28. /// <summary>
  29. /// The primary face button being pressed on a device, or sole button if only one is available.
  30. /// </summary>
  31. public ButtonControl primaryButton { get; private set; }
  32. /// <summary>
  33. /// The primary face button being touched on a device.
  34. /// </summary>
  35. public ButtonControl primaryTouch { get; private set; }
  36. /// <summary>
  37. /// The secondary face button being pressed on a device.
  38. /// </summary>
  39. public ButtonControl secondaryButton { get; private set; }
  40. /// <summary>
  41. /// The secondary face button being touched on a device.
  42. /// </summary>
  43. public ButtonControl secondaryTouch { get; private set; }
  44. /// <summary>
  45. /// A binary measure of whether the device is being gripped.
  46. /// </summary>
  47. public ButtonControl gripButton { get; private set; }
  48. /// <summary>
  49. /// A binary measure of whether the index finger is activating the trigger.
  50. /// </summary>
  51. public ButtonControl triggerButton { get; private set; }
  52. /// <summary>
  53. /// Represents a menu button, used to pause, go back, or otherwise exit gameplay.
  54. /// </summary>
  55. public ButtonControl menuButton { get; private set; }
  56. /// <summary>
  57. /// Represents the primary 2D axis being clicked or otherwise depressed.
  58. /// </summary>
  59. public ButtonControl primary2DAxisClick { get; private set; }
  60. /// <summary>
  61. /// Represents the primary 2D axis being touched.
  62. /// </summary>
  63. public ButtonControl primary2DAxisTouch { get; private set; }
  64. /// <summary>
  65. /// Represents the secondary 2D axis being clicked or otherwise depressed.
  66. /// </summary>
  67. public ButtonControl secondary2DAxisClick { get; private set; }
  68. /// <summary>
  69. /// Represents the secondary 2D axis being touched.
  70. /// </summary>
  71. public ButtonControl secondary2DAxisTouch { get; private set; }
  72. /// <summary>
  73. /// Value representing the current battery life of this device.
  74. /// </summary>
  75. public AxisControl batteryLevel { get; private set; }
  76. /// <summary>
  77. /// Indicates whether the user is present and interacting with the device.
  78. /// </summary>
  79. public ButtonControl userPresence { get; private set; }
  80. /// <summary>
  81. /// Finishes setting up all the input values for the controller.
  82. /// </summary>
  83. protected override void FinishSetup()
  84. {
  85. base.FinishSetup();
  86. primary2DAxis = GetChildControl<Vector2Control>(nameof(primary2DAxis));
  87. trigger = GetChildControl<AxisControl>(nameof(trigger));
  88. grip = GetChildControl<AxisControl>(nameof(grip));
  89. secondary2DAxis = GetChildControl<Vector2Control>(nameof(secondary2DAxis));
  90. primaryButton = GetChildControl<ButtonControl>(nameof(primaryButton));
  91. primaryTouch = GetChildControl<ButtonControl>(nameof(primaryTouch));
  92. secondaryButton = GetChildControl<ButtonControl>(nameof(secondaryButton));
  93. secondaryTouch = GetChildControl<ButtonControl>(nameof(secondaryTouch));
  94. gripButton = GetChildControl<ButtonControl>(nameof(gripButton));
  95. triggerButton = GetChildControl<ButtonControl>(nameof(triggerButton));
  96. menuButton = GetChildControl<ButtonControl>(nameof(menuButton));
  97. primary2DAxisClick = GetChildControl<ButtonControl>(nameof(primary2DAxisClick));
  98. primary2DAxisTouch = GetChildControl<ButtonControl>(nameof(primary2DAxisTouch));
  99. secondary2DAxisClick = GetChildControl<ButtonControl>(nameof(secondary2DAxisClick));
  100. secondary2DAxisTouch = GetChildControl<ButtonControl>(nameof(secondary2DAxisTouch));
  101. batteryLevel = GetChildControl<AxisControl>(nameof(batteryLevel));
  102. userPresence = GetChildControl<ButtonControl>(nameof(userPresence));
  103. }
  104. }
  105. }