This commit is contained in:
2025-01-17 13:10:42 +01:00
commit 4536213c91
15115 changed files with 1442174 additions and 0 deletions

View File

@@ -0,0 +1,137 @@
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.Scripting;
////TODO: speaker, touchpad
////TODO: move gyro here
namespace UnityEngine.InputSystem.DualShock
{
/// <summary>
/// A Sony DualShock/DualSense controller.
/// </summary>
[InputControlLayout(displayName = "PlayStation Controller")]
public class DualShockGamepad : Gamepad, IDualShockHaptics
{
/// <summary>
/// Button that is triggered when the touchbar on the controller is pressed down.
/// </summary>
/// <value>Control representing the touchbar button.</value>
[InputControl(name = "buttonWest", displayName = "Square", shortDisplayName = "Square")]
[InputControl(name = "buttonNorth", displayName = "Triangle", shortDisplayName = "Triangle")]
[InputControl(name = "buttonEast", displayName = "Circle", shortDisplayName = "Circle")]
[InputControl(name = "buttonSouth", displayName = "Cross", shortDisplayName = "Cross")]
[InputControl]
public ButtonControl touchpadButton { get; protected set; }
/// <summary>
/// The right side button in the middle section of the controller. Equivalent to
/// <see cref="Gamepad.startButton"/>.
/// </summary>
/// <value>Same as <see cref="Gamepad.startButton"/>.</value>
[InputControl(name = "start", displayName = "Options")]
public ButtonControl optionsButton { get; protected set; }
/// <summary>
/// The left side button in the middle section of the controller. Equivalent to
/// <see cref="Gamepad.selectButton"/>
/// </summary>
/// <value>Same as <see cref="Gamepad.selectButton"/>.</value>
[InputControl(name = "select", displayName = "Share")]
public ButtonControl shareButton { get; protected set; }
/// <summary>
/// The left shoulder button.
/// </summary>
/// <value>Equivalent to <see cref="Gamepad.leftShoulder"/>.</value>
[InputControl(name = "leftShoulder", displayName = "L1", shortDisplayName = "L1")]
public ButtonControl L1 { get; protected set; }
/// <summary>
/// The right shoulder button.
/// </summary>
/// <value>Equivalent to <see cref="Gamepad.rightShoulder"/>.</value>
[InputControl(name = "rightShoulder", displayName = "R1", shortDisplayName = "R1")]
public ButtonControl R1 { get; protected set; }
/// <summary>
/// The left trigger button.
/// </summary>
/// <value>Equivalent to <see cref="Gamepad.leftTrigger"/>.</value>
[InputControl(name = "leftTrigger", displayName = "L2", shortDisplayName = "L2")]
public ButtonControl L2 { get; protected set; }
/// <summary>
/// The right trigger button.
/// </summary>
/// <value>Equivalent to <see cref="Gamepad.rightTrigger"/>.</value>
[InputControl(name = "rightTrigger", displayName = "R2", shortDisplayName = "R2")]
public ButtonControl R2 { get; protected set; }
/// <summary>
/// The left stick press button.
/// </summary>
/// <value>Equivalent to <see cref="Gamepad.leftStickButton"/>.</value>
[InputControl(name = "leftStickPress", displayName = "L3", shortDisplayName = "L3")]
public ButtonControl L3 { get; protected set; }
/// <summary>
/// The right stick press button.
/// </summary>
/// <value>Equivalent to <see cref="Gamepad.rightStickButton"/>.</value>
[InputControl(name = "rightStickPress", displayName = "R3", shortDisplayName = "R3")]
public ButtonControl R3 { get; protected set; }
/// <summary>
/// The last used/added DualShock controller.
/// </summary>
/// <value>Equivalent to <see cref="Gamepad.leftTrigger"/>.</value>
public new static DualShockGamepad current { get; private set; }
/// <summary>
/// If the controller is connected over HID, returns <see cref="HID.HID.HIDDeviceDescriptor"/> data parsed from <see cref="InputDeviceDescription.capabilities"/>.
/// </summary>
internal HID.HID.HIDDeviceDescriptor hidDescriptor { get; private set; }
/// <inheritdoc />
public override void MakeCurrent()
{
base.MakeCurrent();
current = this;
}
/// <inheritdoc />
protected override void OnRemoved()
{
base.OnRemoved();
if (current == this)
current = null;
}
/// <inheritdoc />
protected override void FinishSetup()
{
base.FinishSetup();
touchpadButton = GetChildControl<ButtonControl>("touchpadButton");
optionsButton = startButton;
shareButton = selectButton;
L1 = leftShoulder;
R1 = rightShoulder;
L2 = leftTrigger;
R2 = rightTrigger;
L3 = leftStickButton;
R3 = rightStickButton;
if (m_Description.capabilities != null && m_Description.interfaceName == "HID")
hidDescriptor = HID.HID.HIDDeviceDescriptor.FromJson(m_Description.capabilities);
}
/// <inheritdoc />
public virtual void SetLightBarColor(Color color)
{
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: df88ce51eaa14f2f8975023f7f45d2d9
timeCreated: 1511133490

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c7225419e3d446c5982afd5ba9cce319
timeCreated: 1517282565

View File

@@ -0,0 +1,73 @@
using UnityEngine.InputSystem.Layouts;
namespace UnityEngine.InputSystem.DualShock
{
/// <summary>
/// Adds support for PS4 DualShock controllers.
/// </summary>
#if UNITY_DISABLE_DEFAULT_INPUT_PLUGIN_INITIALIZATION
public
#else
internal
#endif
static class DualShockSupport
{
public static void Initialize()
{
InputSystem.RegisterLayout<DualShockGamepad>();
// HID version for platforms where we pick up the controller as a raw HID.
// This works without any PS4-specific drivers but does not support the full
// range of capabilities of the controller (the HID format is undocumented
// and only partially understood).
//
// NOTE: We match by PID and VID here as that is the most reliable way. The product
// and manufacturer strings we get from APIs often return inconsistent results
// or none at all. E.g. when connected via Bluetooth on OSX, the DualShock will
// not return anything from IOHIDDevice_GetProduct() and IOHIDevice_GetManufacturer()
// even though it will report the expected results when plugged in via USB.
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_WSA || UNITY_EDITOR
InputSystem.RegisterLayout<DualSenseGamepadHID>(
matches: new InputDeviceMatcher()
.WithInterface("HID")
.WithCapability("vendorId", 0x54C) // Sony Entertainment.
.WithCapability("productId", 0xDF2)); // Dual Sense Edge
InputSystem.RegisterLayout<DualSenseGamepadHID>(
matches: new InputDeviceMatcher()
.WithInterface("HID")
.WithCapability("vendorId", 0x54C) // Sony Entertainment.
.WithCapability("productId", 0xCE6)); // Dual Sense
InputSystem.RegisterLayout<DualShock4GamepadHID>(
matches: new InputDeviceMatcher()
.WithInterface("HID")
.WithCapability("vendorId", 0x54C) // Sony Entertainment.
.WithCapability("productId", 0x9CC)); // Wireless controller.
InputSystem.RegisterLayoutMatcher<DualShock4GamepadHID>(
new InputDeviceMatcher()
.WithInterface("HID")
.WithCapability("vendorId", 0x54C) // Sony Entertainment.
.WithCapability("productId", 0x5C4)); // Wireless controller.
// Just to make sure, also set up a matcher that goes by strings so that we cover
// all bases.
InputSystem.RegisterLayoutMatcher<DualShock4GamepadHID>(
new InputDeviceMatcher()
.WithInterface("HID")
.WithManufacturerContains("Sony")
.WithProduct("Wireless Controller"));
InputSystem.RegisterLayout<DualShock3GamepadHID>(
matches: new InputDeviceMatcher()
.WithInterface("HID")
.WithCapability("vendorId", 0x54C) // Sony Entertainment.
.WithCapability("productId", 0x268)); // PLAYSTATION(R)3 Controller.
InputSystem.RegisterLayoutMatcher<DualShock3GamepadHID>(
new InputDeviceMatcher()
.WithInterface("HID")
.WithManufacturerContains("Sony")
.WithProduct("PLAYSTATION(R)3 Controller", supportRegex: false));
#endif
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fa26399d579948dd90c6ff298cdb0570
timeCreated: 1511133448

View File

@@ -0,0 +1,17 @@
using UnityEngine.InputSystem.Haptics;
namespace UnityEngine.InputSystem.DualShock
{
/// <summary>
/// Extended haptics interface for DualShock controllers.
/// </summary>
public interface IDualShockHaptics : IDualMotorRumble
{
/// <summary>
/// Set the color of the light bar on the back of the controller.
/// </summary>
/// <param name="color">Color to use for the light bar. Alpha component is ignored. Also,
/// RBG values are clamped into [0..1] range.</param>
void SetLightBarColor(Color color);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0e235e01f7e6408f87e899ac373c85d1
timeCreated: 1517282788