DualShockGamepad.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 controller.
  10. /// </summary>
  11. [InputControlLayout(displayName = "PS4 Controller")]
  12. [Preserve]
  13. public class DualShockGamepad : Gamepad, IDualShockHaptics
  14. {
  15. /// <summary>
  16. /// Button that is triggered when the touchbar on the controller is pressed down.
  17. /// </summary>
  18. /// <value>Control representing the touchbar button.</value>
  19. [InputControl(name = "buttonWest", displayName = "Square", shortDisplayName = "Square")]
  20. [InputControl(name = "buttonNorth", displayName = "Triangle", shortDisplayName = "Triangle")]
  21. [InputControl(name = "buttonEast", displayName = "Circle", shortDisplayName = "Circle")]
  22. [InputControl(name = "buttonSouth", displayName = "Cross", shortDisplayName = "Cross")]
  23. [InputControl]
  24. public ButtonControl touchpadButton { get; private set; }
  25. /// <summary>
  26. /// The right side button in the middle section of the controller. Equivalent to
  27. /// <see cref="Gamepad.startButton"/>.
  28. /// </summary>
  29. /// <value>Same as <see cref="Gamepad.startButton"/>.</value>
  30. [InputControl(name = "start", displayName = "Options")]
  31. public ButtonControl optionsButton { get; private set; }
  32. /// <summary>
  33. /// The left side button in the middle section of the controller. Equivalent to
  34. /// <see cref="Gamepad.selectButton"/>
  35. /// </summary>
  36. /// <value>Same as <see cref="Gamepad.selectButton"/>.</value>
  37. [InputControl(name = "select", displayName = "Share")]
  38. public ButtonControl shareButton { get; private set; }
  39. /// <summary>
  40. /// The left shoulder button.
  41. /// </summary>
  42. /// <value>Equivalent to <see cref="Gamepad.leftShoulder"/>.</value>
  43. [InputControl(name = "leftShoulder", displayName = "L1", shortDisplayName = "L1")]
  44. public ButtonControl L1 { get; private set; }
  45. /// <summary>
  46. /// The right shoulder button.
  47. /// </summary>
  48. /// <value>Equivalent to <see cref="Gamepad.rightShoulder"/>.</value>
  49. [InputControl(name = "rightShoulder", displayName = "R1", shortDisplayName = "R1")]
  50. public ButtonControl R1 { get; private set; }
  51. /// <summary>
  52. /// The left trigger button.
  53. /// </summary>
  54. /// <value>Equivalent to <see cref="Gamepad.leftTrigger"/>.</value>
  55. [InputControl(name = "leftTrigger", displayName = "L2", shortDisplayName = "L2")]
  56. public ButtonControl L2 { get; private set; }
  57. /// <summary>
  58. /// The right trigger button.
  59. /// </summary>
  60. /// <value>Equivalent to <see cref="Gamepad.rightTrigger"/>.</value>
  61. [InputControl(name = "rightTrigger", displayName = "R2", shortDisplayName = "R2")]
  62. public ButtonControl R2 { get; private set; }
  63. /// <summary>
  64. /// The left stick press button.
  65. /// </summary>
  66. /// <value>Equivalent to <see cref="Gamepad.leftStickButton"/>.</value>
  67. [InputControl(name = "leftStickPress", displayName = "L3", shortDisplayName = "L3")]
  68. public ButtonControl L3 { get; private set; }
  69. /// <summary>
  70. /// The right stick press button.
  71. /// </summary>
  72. /// <value>Equivalent to <see cref="Gamepad.rightStickButton"/>.</value>
  73. [InputControl(name = "rightStickPress", displayName = "R3", shortDisplayName = "R3")]
  74. public ButtonControl R3 { get; private set; }
  75. /// <summary>
  76. /// The last used/added DualShock controller.
  77. /// </summary>
  78. public new static DualShockGamepad current { get; private set; }
  79. /// <inheritdoc />
  80. public override void MakeCurrent()
  81. {
  82. base.MakeCurrent();
  83. current = this;
  84. }
  85. /// <inheritdoc />
  86. protected override void OnRemoved()
  87. {
  88. base.OnRemoved();
  89. if (current == this)
  90. current = null;
  91. }
  92. /// <inheritdoc />
  93. protected override void FinishSetup()
  94. {
  95. base.FinishSetup();
  96. touchpadButton = GetChildControl<ButtonControl>("touchpadButton");
  97. optionsButton = startButton;
  98. shareButton = selectButton;
  99. L1 = leftShoulder;
  100. R1 = rightShoulder;
  101. L2 = leftTrigger;
  102. R2 = rightTrigger;
  103. L3 = leftStickButton;
  104. R3 = rightStickButton;
  105. }
  106. /// <inheritdoc />
  107. public virtual void SetLightBarColor(Color color)
  108. {
  109. }
  110. }
  111. }