暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

OSXGameController.cs 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #if UNITY_EDITOR || UNITY_STANDALONE_OSX || PACKAGE_DOCS_GENERATION
  2. using System.Runtime.InteropServices;
  3. using UnityEngine.InputSystem.Layouts;
  4. using UnityEngine.InputSystem.LowLevel;
  5. using UnityEngine.InputSystem.Utilities;
  6. using UnityEngine.InputSystem.OSX.LowLevel;
  7. using UnityEngine.InputSystem.Controls;
  8. namespace UnityEngine.InputSystem.OSX.LowLevel
  9. {
  10. /// <summary>
  11. /// Structure of HID input reports for SteelSeries Nimbus+ controllers supported
  12. /// via HID on OSX.
  13. /// </summary>
  14. [StructLayout(LayoutKind.Explicit, Size = 8)]
  15. internal struct NimbusPlusHIDInputReport : IInputStateTypeInfo
  16. {
  17. /// <summary>
  18. /// A dummy vendor ID made available by OSX when supporting Nimbus+ via HID.
  19. /// This is exposed by OSX instead of the true SteelSeries vendor ID 0x1038.
  20. /// </summary>
  21. public const int OSXVendorId = 0xd;
  22. /// <summary>
  23. /// A dummy product ID made available by OSX when supporting Nimbus+ via HID.
  24. /// This is exposed by OSX instead of the true Nimbus+ product ID 0x1422.
  25. /// </summary>
  26. public const int OSXProductId = 0x0;
  27. public FourCC format => new FourCC('H', 'I', 'D');
  28. [InputControl(name = "leftStick", layout = "Stick", format = "VC2B")]
  29. [InputControl(name = "leftStick/x", offset = 0, format = "SBYT", parameters = "")]
  30. [InputControl(name = "leftStick/left", offset = 0, format = "SBYT", parameters = "clamp=1,clampMin=-1,clampMax=0,invert")]
  31. [InputControl(name = "leftStick/right", offset = 0, format = "SBYT", parameters = "clamp=1,clampMin=0,clampMax=1")]
  32. [InputControl(name = "leftStick/y", offset = 1, format = "SBYT", parameters = "")]
  33. [InputControl(name = "leftStick/up", offset = 1, format = "SBYT", parameters = "clamp=1,clampMin=0,clampMax=1")]
  34. [InputControl(name = "leftStick/down", offset = 1, format = "SBYT", parameters = "clamp=1,clampMin=-1,clampMax=0,invert")]
  35. [FieldOffset(0)] public sbyte leftStickX;
  36. [FieldOffset(1)] public sbyte leftStickY;
  37. [InputControl(name = "rightStick", layout = "Stick", format = "VC2B")]
  38. [InputControl(name = "rightStick/x", offset = 0, format = "SBYT")]
  39. [InputControl(name = "rightStick/left", offset = 0, format = "SBYT", parameters = "clamp=1,clampMin=-1,clampMax=0,invert")]
  40. [InputControl(name = "rightStick/right", offset = 0, format = "SBYT", parameters = "clamp=1,clampMin=0,clampMax=1")]
  41. [InputControl(name = "rightStick/y", offset = 1, format = "SBYT")]
  42. [InputControl(name = "rightStick/up", offset = 1, format = "SBYT", parameters = "clamp=1,clampMin=0,clampMax=1")]
  43. [InputControl(name = "rightStick/down", offset = 1, format = "SBYT", parameters = "clamp=1,clampMin=-1,clampMax=0,invert")]
  44. [FieldOffset(2)] public sbyte rightStickX;
  45. [FieldOffset(3)] public sbyte rightStickY;
  46. [InputControl(name = "leftTrigger", format = "BYTE")]
  47. [FieldOffset(4)] public byte leftTrigger;
  48. [InputControl(name = "rightTrigger", format = "BYTE")]
  49. [FieldOffset(5)] public byte rightTrigger;
  50. [InputControl(name = "dpad", format = "BIT", layout = "Dpad", sizeInBits = 4)]
  51. [InputControl(name = "dpad/up", format = "BIT", bit = 0)]
  52. [InputControl(name = "dpad/right", format = "BIT", bit = 1)]
  53. [InputControl(name = "dpad/down", format = "BIT", bit = 2)]
  54. [InputControl(name = "dpad/left", format = "BIT", bit = 3)]
  55. [InputControl(name = "buttonSouth", displayName = "A", bit = 4)]
  56. [InputControl(name = "buttonEast", displayName = "B", bit = 5)]
  57. [InputControl(name = "buttonWest", displayName = "X", bit = 6)]
  58. [InputControl(name = "buttonNorth", displayName = "Y", bit = 7)]
  59. [FieldOffset(6)] public byte buttons1;
  60. [InputControl(name = "leftShoulder", bit = 0)]
  61. [InputControl(name = "rightShoulder", bit = 1)]
  62. [InputControl(name = "leftStickPress", bit = 2)]
  63. [InputControl(name = "rightStickPress", bit = 3)]
  64. [InputControl(name = "homeButton", layout = "Button", bit = 4)]
  65. [InputControl(name = "select", bit = 5)]
  66. [InputControl(name = "start", bit = 6)]
  67. [FieldOffset(7)] public byte buttons2;
  68. }
  69. }
  70. namespace UnityEngine.InputSystem.OSX
  71. {
  72. /// <summary>
  73. /// Steel Series Nimbus+ uses iOSGameController MFI when on iOS but
  74. /// is just a standard HID on OSX. Note that the gamepad is made available
  75. /// with incorrect VID/PID by OSX instead of the true VID/PID registred with
  76. /// USB.org for this device.
  77. /// </summary>
  78. [InputControlLayout(stateType = typeof(NimbusPlusHIDInputReport), displayName = "Nimbus+ Gamepad")]
  79. [Scripting.Preserve]
  80. public class NimbusGamepadHid : Gamepad
  81. {
  82. /// <summary>
  83. /// The center button in the middle section of the controller.
  84. /// </summary>
  85. /// <remarks>
  86. /// Note that this button is also picked up by OS.
  87. /// </remarks>
  88. [InputControl(name = "homeButton", displayName = "Home", shortDisplayName = "Home")]
  89. public ButtonControl homeButton { get; protected set; }
  90. /// <inheritdoc />
  91. protected override void FinishSetup()
  92. {
  93. homeButton = GetChildControl<ButtonControl>("homeButton");
  94. Debug.Assert(homeButton != null);
  95. base.FinishSetup();
  96. }
  97. }
  98. }
  99. #endif // UNITY_EDITOR || UNITY_STANDALONE_OSX