暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DualShockGamepad.cs 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using UnityEngine.InputSystem.Controls;
  2. using UnityEngine.InputSystem.Layouts;
  3. using UnityEngine.Scripting;
  4. ////TODO: speaker, touchpad
  5. ////TODO: move gyro here
  6. namespace UnityEngine.InputSystem.DualShock
  7. {
  8. /// <summary>
  9. /// A Sony DualShock/DualSense controller.
  10. /// </summary>
  11. [InputControlLayout(displayName = "PlayStation Controller")]
  12. public class DualShockGamepad : Gamepad, IDualShockHaptics
  13. {
  14. /// <summary>
  15. /// Button that is triggered when the touchbar on the controller is pressed down.
  16. /// </summary>
  17. /// <value>Control representing the touchbar button.</value>
  18. [InputControl(name = "buttonWest", displayName = "Square", shortDisplayName = "Square")]
  19. [InputControl(name = "buttonNorth", displayName = "Triangle", shortDisplayName = "Triangle")]
  20. [InputControl(name = "buttonEast", displayName = "Circle", shortDisplayName = "Circle")]
  21. [InputControl(name = "buttonSouth", displayName = "Cross", shortDisplayName = "Cross")]
  22. [InputControl]
  23. public ButtonControl touchpadButton { get; protected set; }
  24. /// <summary>
  25. /// The right side button in the middle section of the controller. Equivalent to
  26. /// <see cref="Gamepad.startButton"/>.
  27. /// </summary>
  28. /// <value>Same as <see cref="Gamepad.startButton"/>.</value>
  29. [InputControl(name = "start", displayName = "Options")]
  30. public ButtonControl optionsButton { get; protected set; }
  31. /// <summary>
  32. /// The left side button in the middle section of the controller. Equivalent to
  33. /// <see cref="Gamepad.selectButton"/>
  34. /// </summary>
  35. /// <value>Same as <see cref="Gamepad.selectButton"/>.</value>
  36. [InputControl(name = "select", displayName = "Share")]
  37. public ButtonControl shareButton { get; protected set; }
  38. /// <summary>
  39. /// The left shoulder button.
  40. /// </summary>
  41. /// <value>Equivalent to <see cref="Gamepad.leftShoulder"/>.</value>
  42. [InputControl(name = "leftShoulder", displayName = "L1", shortDisplayName = "L1")]
  43. public ButtonControl L1 { get; protected set; }
  44. /// <summary>
  45. /// The right shoulder button.
  46. /// </summary>
  47. /// <value>Equivalent to <see cref="Gamepad.rightShoulder"/>.</value>
  48. [InputControl(name = "rightShoulder", displayName = "R1", shortDisplayName = "R1")]
  49. public ButtonControl R1 { get; protected set; }
  50. /// <summary>
  51. /// The left trigger button.
  52. /// </summary>
  53. /// <value>Equivalent to <see cref="Gamepad.leftTrigger"/>.</value>
  54. [InputControl(name = "leftTrigger", displayName = "L2", shortDisplayName = "L2")]
  55. public ButtonControl L2 { get; protected set; }
  56. /// <summary>
  57. /// The right trigger button.
  58. /// </summary>
  59. /// <value>Equivalent to <see cref="Gamepad.rightTrigger"/>.</value>
  60. [InputControl(name = "rightTrigger", displayName = "R2", shortDisplayName = "R2")]
  61. public ButtonControl R2 { get; protected set; }
  62. /// <summary>
  63. /// The left stick press button.
  64. /// </summary>
  65. /// <value>Equivalent to <see cref="Gamepad.leftStickButton"/>.</value>
  66. [InputControl(name = "leftStickPress", displayName = "L3", shortDisplayName = "L3")]
  67. public ButtonControl L3 { get; protected set; }
  68. /// <summary>
  69. /// The right stick press button.
  70. /// </summary>
  71. /// <value>Equivalent to <see cref="Gamepad.rightStickButton"/>.</value>
  72. [InputControl(name = "rightStickPress", displayName = "R3", shortDisplayName = "R3")]
  73. public ButtonControl R3 { get; protected set; }
  74. /// <summary>
  75. /// The last used/added DualShock controller.
  76. /// </summary>
  77. /// <value>Equivalent to <see cref="Gamepad.leftTrigger"/>.</value>
  78. public new static DualShockGamepad current { get; private set; }
  79. /// <summary>
  80. /// If the controller is connected over HID, returns <see cref="HID.HID.HIDDeviceDescriptor"/> data parsed from <see cref="InputDeviceDescription.capabilities"/>.
  81. /// </summary>
  82. internal HID.HID.HIDDeviceDescriptor hidDescriptor { get; private set; }
  83. /// <inheritdoc />
  84. public override void MakeCurrent()
  85. {
  86. base.MakeCurrent();
  87. current = this;
  88. }
  89. /// <inheritdoc />
  90. protected override void OnRemoved()
  91. {
  92. base.OnRemoved();
  93. if (current == this)
  94. current = null;
  95. }
  96. /// <inheritdoc />
  97. protected override void FinishSetup()
  98. {
  99. base.FinishSetup();
  100. touchpadButton = GetChildControl<ButtonControl>("touchpadButton");
  101. optionsButton = startButton;
  102. shareButton = selectButton;
  103. L1 = leftShoulder;
  104. R1 = rightShoulder;
  105. L2 = leftTrigger;
  106. R2 = rightTrigger;
  107. L3 = leftStickButton;
  108. R3 = rightStickButton;
  109. if (m_Description.capabilities != null && m_Description.interfaceName == "HID")
  110. hidDescriptor = HID.HID.HIDDeviceDescriptor.FromJson(m_Description.capabilities);
  111. }
  112. /// <inheritdoc />
  113. public virtual void SetLightBarColor(Color color)
  114. {
  115. }
  116. }
  117. }