예제 #1
0
    public void Devices_CanReadSlotIndexAndGetDualShockPS4BySlotIndex()
    {
        runtime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4",
            capabilities  = new PS4InputDeviceDescriptor {
                slotId = 0, isAimController = false, defaultColorId = 0, userId = 1234
            }.ToJson()
        }.ToJson(), 1);

        runtime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4",
            capabilities  = new PS4InputDeviceDescriptor {
                slotId = 1, isAimController = false, defaultColorId = 0, userId = 1234
            }.ToJson()
        }.ToJson(), 2);

        runtime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4",
            capabilities  = new PS4InputDeviceDescriptor {
                slotId = 2, isAimController = false, defaultColorId = 0, userId = 1234
            }.ToJson()
        }.ToJson(), 3);

        runtime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4",
            capabilities  = new PS4InputDeviceDescriptor {
                slotId = 3, isAimController = false, defaultColorId = 0, userId = 1234
            }.ToJson()
        }.ToJson(), 4);

        InputSystem.Update();

        var gamepad1 = (DualShockGamepadPS4)InputSystem.devices[0];
        var gamepad2 = (DualShockGamepadPS4)InputSystem.devices[1];
        var gamepad3 = (DualShockGamepadPS4)InputSystem.devices[2];
        var gamepad4 = (DualShockGamepadPS4)InputSystem.devices[3];

        Assert.That(gamepad1.slotIndex, Is.EqualTo(0));
        Assert.That(gamepad2.slotIndex, Is.EqualTo(1));
        Assert.That(gamepad3.slotIndex, Is.EqualTo(2));
        Assert.That(gamepad4.slotIndex, Is.EqualTo(3));

        Assert.That(DualShockGamepadPS4.GetBySlotIndex(0), Is.SameAs(gamepad1));
        Assert.That(DualShockGamepadPS4.GetBySlotIndex(1), Is.SameAs(gamepad2));
        Assert.That(DualShockGamepadPS4.GetBySlotIndex(2), Is.SameAs(gamepad3));
        Assert.That(DualShockGamepadPS4.GetBySlotIndex(3), Is.SameAs(gamepad4));
    }
    public unsafe void Devices_CanReadSlotIndexAndGetDualShockPS4BySlotIndex()
    {
        testRuntime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4"
        }.ToJson(), 1);
        testRuntime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4"
        }.ToJson(), 2);
        testRuntime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4"
        }.ToJson(), 3);
        testRuntime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4"
        }.ToJson(), 4);

        testRuntime.SetDeviceCommandCallback(1, QueryPS4ControllerInfo.Create().WithSlotIndex(0));
        testRuntime.SetDeviceCommandCallback(2, QueryPS4ControllerInfo.Create().WithSlotIndex(1));
        testRuntime.SetDeviceCommandCallback(3, QueryPS4ControllerInfo.Create().WithSlotIndex(2));
        testRuntime.SetDeviceCommandCallback(4, QueryPS4ControllerInfo.Create().WithSlotIndex(3));

        InputSystem.Update();

        var gamepad1 = (DualShockGamepadPS4)InputSystem.devices[0];
        var gamepad2 = (DualShockGamepadPS4)InputSystem.devices[1];
        var gamepad3 = (DualShockGamepadPS4)InputSystem.devices[2];
        var gamepad4 = (DualShockGamepadPS4)InputSystem.devices[3];

        Assert.That(gamepad1.slotIndex, Is.EqualTo(0));
        Assert.That(gamepad2.slotIndex, Is.EqualTo(1));
        Assert.That(gamepad3.slotIndex, Is.EqualTo(2));
        Assert.That(gamepad4.slotIndex, Is.EqualTo(3));

        Assert.That(DualShockGamepadPS4.GetBySlotIndex(0), Is.SameAs(gamepad1));
        Assert.That(DualShockGamepadPS4.GetBySlotIndex(1), Is.SameAs(gamepad2));
        Assert.That(DualShockGamepadPS4.GetBySlotIndex(2), Is.SameAs(gamepad3));
        Assert.That(DualShockGamepadPS4.GetBySlotIndex(3), Is.SameAs(gamepad4));
    }
예제 #3
0
    public void Devices_CanReadSlotIndexAndGetDualShockPS4BySlotIndex()
    {
#if UNITY_2019_1_OR_NEWER
        runtime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4",
            capabilities  = new PS4InputDeviceDescriptor {
                slotId = 0, isAimController = false, defaultColorId = 0, userId = 1234
            }.ToJson()
        }.ToJson(), 1);

        runtime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4",
            capabilities  = new PS4InputDeviceDescriptor {
                slotId = 1, isAimController = false, defaultColorId = 0, userId = 1234
            }.ToJson()
        }.ToJson(), 2);

        runtime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4",
            capabilities  = new PS4InputDeviceDescriptor {
                slotId = 2, isAimController = false, defaultColorId = 0, userId = 1234
            }.ToJson()
        }.ToJson(), 3);

        runtime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4",
            capabilities  = new PS4InputDeviceDescriptor {
                slotId = 3, isAimController = false, defaultColorId = 0, userId = 1234
            }.ToJson()
        }.ToJson(), 4);
#else
        runtime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4"
        }.ToJson(), 1);
        runtime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4"
        }.ToJson(), 2);
        runtime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4"
        }.ToJson(), 3);
        runtime.ReportNewInputDevice(new InputDeviceDescription
        {
            deviceClass   = "PS4DualShockGamepad",
            interfaceName = "PS4"
        }.ToJson(), 4);

        runtime.SetDeviceCommandCallback(1, QueryPS4ControllerInfo.Create().WithSlotIndex(0));
        runtime.SetDeviceCommandCallback(2, QueryPS4ControllerInfo.Create().WithSlotIndex(1));
        runtime.SetDeviceCommandCallback(3, QueryPS4ControllerInfo.Create().WithSlotIndex(2));
        runtime.SetDeviceCommandCallback(4, QueryPS4ControllerInfo.Create().WithSlotIndex(3));
#endif

        InputSystem.Update();

        var gamepad1 = (DualShockGamepadPS4)InputSystem.devices[0];
        var gamepad2 = (DualShockGamepadPS4)InputSystem.devices[1];
        var gamepad3 = (DualShockGamepadPS4)InputSystem.devices[2];
        var gamepad4 = (DualShockGamepadPS4)InputSystem.devices[3];

        Assert.That(gamepad1.slotIndex, Is.EqualTo(0));
        Assert.That(gamepad2.slotIndex, Is.EqualTo(1));
        Assert.That(gamepad3.slotIndex, Is.EqualTo(2));
        Assert.That(gamepad4.slotIndex, Is.EqualTo(3));

        Assert.That(DualShockGamepadPS4.GetBySlotIndex(0), Is.SameAs(gamepad1));
        Assert.That(DualShockGamepadPS4.GetBySlotIndex(1), Is.SameAs(gamepad2));
        Assert.That(DualShockGamepadPS4.GetBySlotIndex(2), Is.SameAs(gamepad3));
        Assert.That(DualShockGamepadPS4.GetBySlotIndex(3), Is.SameAs(gamepad4));
    }