public void Devices_XRDeviceRoleDeterminesTypeOfDevice(InputDeviceRole role, string baseLayoutName, Type expectedType)
    {
        var deviceDescription = CreateSimpleDeviceDescriptionByRole(role);

        runtime.ReportNewInputDevice(deviceDescription.ToJson());

        InputSystem.Update();

        Assert.That(InputSystem.devices, Has.Count.EqualTo(1));
        var createdDevice = InputSystem.devices[0];

        Assert.That(createdDevice, Is.TypeOf(expectedType));

        var generatedLayout = InputSystem.LoadLayout(
            $"{XRUtilities.InterfaceCurrent}::{deviceDescription.manufacturer}::{deviceDescription.product}");

        Assert.That(generatedLayout, Is.Not.Null);
        if (baseLayoutName == null)
        {
            Assert.That(generatedLayout.baseLayouts, Is.Empty);
        }
        else
        {
            Assert.That(generatedLayout.baseLayouts, Is.EquivalentTo(new[] { new InternedString(baseLayoutName) }));
        }
    }
Example #2
0
    static InputDeviceCharacteristics CharacteristicsFromInputDeviceRole(InputDeviceRole role)
    {
        switch (role)
        {
        case InputDeviceRole.Generic:
            return(InputDeviceCharacteristics.HeadMounted);

        case InputDeviceRole.LeftHanded:
            return(InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.Left);

        case InputDeviceRole.RightHanded:
            return(InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.Right);

        case InputDeviceRole.GameController:
            return(InputDeviceCharacteristics.Controller);

        case InputDeviceRole.TrackingReference:
            return(InputDeviceCharacteristics.TrackingReference);

        case InputDeviceRole.HardwareTracker:
            return(InputDeviceCharacteristics.TrackedDevice);

        case InputDeviceRole.LegacyController:
            return(InputDeviceCharacteristics.Controller);
        }
        return(InputDeviceCharacteristics.None);
    }
Example #3
0
    private static InputDeviceDescription CreateSimpleDeviceDescriptionByRole(InputDeviceRole role)
    {
        return(new InputDeviceDescription
        {
            interfaceName = XRUtilities.InterfaceCurrent,
            product = "Device",
            manufacturer = "Manufacturer",
            capabilities = new XRDeviceDescriptor
            {
#if UNITY_2019_3_OR_NEWER
                characteristics = CharacteristicsFromInputDeviceRole(role),
#else
                deviceRole = role,
#endif
                inputFeatures = new List <XRFeatureDescriptor>()
                {
                    new XRFeatureDescriptor()
                    {
                        name = "Filler",
                        featureType = FeatureType.Binary
                    }
                }
            }.ToJson()
        });
    }