| 
5 | 5 | using UnityEngine.InputSystem.Layouts;  | 
6 | 6 | using UnityEngine.InputSystem.Utilities;  | 
7 | 7 | using System.Runtime.InteropServices;  | 
 | 8 | +using UnityEngine.InputSystem.HID;  | 
8 | 9 | using UnityEngine.InputSystem.Processors;  | 
9 | 10 | 
 
  | 
10 | 11 | #if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || UNITY_XBOXONE || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN  | 
@@ -148,6 +149,63 @@ public void Devices_SupportXboxControllerOnOSX()  | 
148 | 149 |         AssertButtonPress(gamepad, new XInputControllerOSXState().WithButton(XInputControllerOSXState.Button.Select), gamepad.selectButton);  | 
149 | 150 |     }  | 
150 | 151 | 
 
  | 
 | 152 | +    [TestCase(0x045e, 0x02e0, 16, 11)] // Xbox One Wireless Controller  | 
 | 153 | +    [TestCase(0x045e, 0x02fd, 10, 11)] // Xbox Series X|S Wireless Controller  | 
 | 154 | +    // This test is used to establish the correct button map layout based on the PID and VIDs  | 
 | 155 | +    // If the layout is changed this test will fail and will need to be adapted either with a new device/layout or  | 
 | 156 | +    // a new button map.  | 
 | 157 | +    public void Devices_SupportWirelessXboxOneAndSeriesControllerOnOSX(int vendorId, int productId, int selectBit, int startBit)  | 
 | 158 | +    {  | 
 | 159 | +        // Fake a real Xbox Wireless Controller  | 
 | 160 | +        var xboxGamepad = InputSystem.AddDevice(new InputDeviceDescription  | 
 | 161 | +        {  | 
 | 162 | +            interfaceName = "HID",  | 
 | 163 | +            product = "Xbox Wireless Controller",  | 
 | 164 | +            manufacturer = "Microsoft",  | 
 | 165 | +            capabilities = new HID.HIDDeviceDescriptor  | 
 | 166 | +            {  | 
 | 167 | +                vendorId = vendorId,  | 
 | 168 | +                productId = productId,  | 
 | 169 | +            }.ToJson()  | 
 | 170 | +        });  | 
 | 171 | + | 
 | 172 | + | 
 | 173 | +        Assert.That(xboxGamepad, Is.AssignableTo<XInputController>());  | 
 | 174 | + | 
 | 175 | +        var gamepad = (XInputController)xboxGamepad;  | 
 | 176 | +        Assert.That(gamepad.selectButton.isPressed, Is.False);  | 
 | 177 | + | 
 | 178 | +        // Check if the controller is an Xbox One from a particular type where we know the select and start buttons are  | 
 | 179 | +        // different  | 
 | 180 | +        if (productId == 0x02e0)  | 
 | 181 | +        {  | 
 | 182 | +            Assert.That(xboxGamepad, Is.AssignableTo<XboxOneGampadMacOSWireless>());  | 
 | 183 | + | 
 | 184 | +            InputSystem.QueueStateEvent(gamepad,  | 
 | 185 | +                new XInputControllerWirelessOSXState  | 
 | 186 | +                {  | 
 | 187 | +                    buttons = (uint)(1 << selectBit |  | 
 | 188 | +                        1 << startBit)  | 
 | 189 | +                });  | 
 | 190 | +            InputSystem.Update();  | 
 | 191 | +        }  | 
 | 192 | +        else  | 
 | 193 | +        {  | 
 | 194 | +            Assert.That(xboxGamepad, Is.AssignableTo<XboxGamepadMacOSWireless>());  | 
 | 195 | + | 
 | 196 | +            InputSystem.QueueStateEvent(gamepad,  | 
 | 197 | +                new XInputControllerWirelessOSXState  | 
 | 198 | +                {  | 
 | 199 | +                    buttons = (uint)(1 << selectBit |  | 
 | 200 | +                        1 << startBit)  | 
 | 201 | +                });  | 
 | 202 | +            InputSystem.Update();  | 
 | 203 | +        }  | 
 | 204 | + | 
 | 205 | +        Assert.That(gamepad.selectButton.isPressed);  | 
 | 206 | +        Assert.That(gamepad.startButton.isPressed);  | 
 | 207 | +    }  | 
 | 208 | + | 
151 | 209 | // Disable tests in standalone builds from 2022.1+ see UUM-19622  | 
152 | 210 | #if !UNITY_STANDALONE_OSX || !TEMP_DISABLE_STANDALONE_OSX_XINPUT_TEST  | 
153 | 211 |     [Test]  | 
 | 
0 commit comments