@@ -23,16 +23,14 @@ internal class XRTests : CoreTestsFixture
2323{
2424 [ Test ]
2525 [ Category ( "Devices" ) ]
26- [ TestCase ( InputDeviceRole . Generic , "XRHMD" , typeof ( XRHMD ) ) ]
27- [ TestCase ( InputDeviceRole . LeftHanded , "XRController" , typeof ( XRController ) ) ]
28- [ TestCase ( InputDeviceRole . RightHanded , "XRController" , typeof ( XRController ) ) ]
29- [ TestCase ( InputDeviceRole . HardwareTracker , null , typeof ( UnityEngine . InputSystem . InputDevice ) ) ]
30- [ TestCase ( InputDeviceRole . TrackingReference , null , typeof ( UnityEngine . InputSystem . InputDevice ) ) ]
31- [ TestCase ( InputDeviceRole . GameController , null , typeof ( UnityEngine . InputSystem . InputDevice ) ) ]
32- [ TestCase ( InputDeviceRole . Unknown , null , typeof ( UnityEngine . InputSystem . InputDevice ) ) ]
33- public void Devices_XRDeviceRoleDeterminesTypeOfDevice ( InputDeviceRole role , string baseLayoutName , Type expectedType )
26+ [ TestCase ( InputDeviceCharacteristics . HeadMounted , "XRHMD" , typeof ( XRHMD ) ) ]
27+ [ TestCase ( ( InputDeviceCharacteristics . HeldInHand | InputDeviceCharacteristics . Controller ) , "XRController" , typeof ( XRController ) ) ]
28+ [ TestCase ( ( InputDeviceCharacteristics . HeldInHand | InputDeviceCharacteristics . Controller | InputDeviceCharacteristics . Left ) , "XRController" , typeof ( XRController ) ) ]
29+ [ TestCase ( InputDeviceCharacteristics . TrackedDevice , null , typeof ( UnityEngine . InputSystem . InputDevice ) ) ]
30+ [ TestCase ( InputDeviceCharacteristics . None , null , typeof ( UnityEngine . InputSystem . InputDevice ) ) ]
31+ public void Devices_XRDeviceCharacteristicsDeterminesTypeOfDevice ( InputDeviceCharacteristics characteristics , string baseLayoutName , Type expectedType )
3432 {
35- var deviceDescription = CreateSimpleDeviceDescriptionByRole ( role ) ;
33+ var deviceDescription = CreateSimpleDeviceDescriptionByType ( characteristics ) ;
3634 runtime . ReportNewInputDevice ( deviceDescription . ToJson ( ) ) ;
3735
3836 InputSystem . Update ( ) ;
@@ -44,6 +42,7 @@ public void Devices_XRDeviceRoleDeterminesTypeOfDevice(InputDeviceRole role, str
4442
4543 var generatedLayout = InputSystem . LoadLayout (
4644 $ "{ XRUtilities . InterfaceCurrent } ::{ deviceDescription . manufacturer } ::{ deviceDescription . product } ") ;
45+
4746 Assert . That ( generatedLayout , Is . Not . Null ) ;
4847 if ( baseLayoutName == null )
4948 Assert . That ( generatedLayout . baseLayouts , Is . Empty ) ;
@@ -55,7 +54,8 @@ public void Devices_XRDeviceRoleDeterminesTypeOfDevice(InputDeviceRole role, str
5554 [ Category ( "Devices" ) ]
5655 public void Devices_CanChangeHandednessOfXRController ( )
5756 {
58- var deviceDescription = CreateSimpleDeviceDescriptionByRole ( InputDeviceRole . LeftHanded ) ;
57+ var deviceDescription = CreateSimpleDeviceDescriptionByType ( InputDeviceCharacteristics . Controller | InputDeviceCharacteristics . HeldInHand | InputDeviceCharacteristics . Left ) ;
58+
5959 runtime . ReportNewInputDevice ( deviceDescription . ToJson ( ) ) ;
6060
6161 InputSystem . Update ( ) ;
@@ -79,7 +79,7 @@ public void Devices_CanChangeHandednessOfXRController()
7979 [ Category ( "Layouts" ) ]
8080 public void Layouts_XRLayoutIsNamespacedAsInterfaceManufacturerDevice ( )
8181 {
82- var deviceDescription = CreateSimpleDeviceDescriptionByRole ( InputDeviceRole . Generic ) ;
82+ var deviceDescription = CreateSimpleDeviceDescriptionByType ( InputDeviceCharacteristics . HeadMounted ) ;
8383 runtime . ReportNewInputDevice ( deviceDescription . ToJson ( ) ) ;
8484
8585 InputSystem . Update ( ) ;
@@ -96,7 +96,7 @@ public void Layouts_XRLayoutIsNamespacedAsInterfaceManufacturerDevice()
9696 [ Category ( "Layouts" ) ]
9797 public void Layouts_XRLayoutWithoutManufacturer_IsNamespacedAsInterfaceDevice ( )
9898 {
99- var deviceDescription = CreateSimpleDeviceDescriptionByRole ( InputDeviceRole . Generic ) ;
99+ var deviceDescription = CreateSimpleDeviceDescriptionByType ( InputDeviceCharacteristics . HeadMounted ) ;
100100 deviceDescription . manufacturer = null ;
101101 runtime . ReportNewInputDevice ( deviceDescription . ToJson ( ) ) ;
102102
@@ -146,7 +146,7 @@ public void Layouts_XRLayoutFeatures_OnlyContainAllowedCharacters()
146146 [ Category ( "Layouts" ) ]
147147 public void Layouts_XRDevicesWithNoOrInvalidCapabilities_DoNotCreateLayouts ( )
148148 {
149- var deviceDescription = CreateSimpleDeviceDescriptionByRole ( InputDeviceRole . Generic ) ;
149+ var deviceDescription = CreateSimpleDeviceDescriptionByType ( InputDeviceCharacteristics . HeadMounted ) ;
150150 deviceDescription . capabilities = null ;
151151 runtime . ReportNewInputDevice ( deviceDescription . ToJson ( ) ) ;
152152
@@ -746,29 +746,31 @@ public void Layouts_PoseControlsCanBeCreatedBySubcontrols()
746746
747747 private const int kNumBaseHMDControls = 10 ;
748748
749- static InputDeviceCharacteristics CharacteristicsFromInputDeviceRole ( InputDeviceRole role )
749+ InputDeviceRole RoleFromCharacteristics ( InputDeviceCharacteristics characteristics )
750750 {
751- switch ( role )
752- {
753- case InputDeviceRole . Generic :
754- return InputDeviceCharacteristics . HeadMounted ;
755- case InputDeviceRole . LeftHanded :
756- return InputDeviceCharacteristics . Controller | InputDeviceCharacteristics . HeldInHand | InputDeviceCharacteristics . Left ;
757- case InputDeviceRole . RightHanded :
758- return InputDeviceCharacteristics . Controller | InputDeviceCharacteristics . HeldInHand | InputDeviceCharacteristics . Right ;
759- case InputDeviceRole . GameController :
760- return InputDeviceCharacteristics . Controller ;
761- case InputDeviceRole . TrackingReference :
762- return InputDeviceCharacteristics . TrackingReference ;
763- case InputDeviceRole . HardwareTracker :
764- return InputDeviceCharacteristics . TrackedDevice ;
765- case InputDeviceRole . LegacyController :
766- return InputDeviceCharacteristics . Controller ;
767- }
768- return InputDeviceCharacteristics . None ;
751+ if ( ( characteristics & InputDeviceCharacteristics . Left ) != 0 )
752+ return InputDeviceRole . LeftHanded ;
753+ if ( ( characteristics & InputDeviceCharacteristics . Right ) != 0 )
754+ return InputDeviceRole . RightHanded ;
755+ if ( ( characteristics & InputDeviceCharacteristics . TrackingReference ) != 0 )
756+ return InputDeviceRole . TrackingReference ;
757+ if ( ( characteristics & InputDeviceCharacteristics . HeadMounted ) != 0 )
758+ return InputDeviceRole . Generic ;
759+ if ( ( characteristics & InputDeviceCharacteristics . HeldInHand ) != 0 )
760+ return InputDeviceRole . Generic ;
761+ if ( ( characteristics & InputDeviceCharacteristics . EyeTracking ) != 0 )
762+ return InputDeviceRole . Generic ;
763+ if ( ( characteristics & InputDeviceCharacteristics . Camera ) != 0 )
764+ return InputDeviceRole . Generic ;
765+ if ( ( characteristics & InputDeviceCharacteristics . Controller ) != 0 )
766+ return InputDeviceRole . GameController ;
767+ if ( ( characteristics & InputDeviceCharacteristics . TrackedDevice ) != 0 )
768+ return InputDeviceRole . HardwareTracker ;
769+
770+ return InputDeviceRole . LegacyController ;
769771 }
770772
771- private static InputDeviceDescription CreateSimpleDeviceDescriptionByRole ( InputDeviceRole role )
773+ private static InputDeviceDescription CreateSimpleDeviceDescriptionByType ( InputDeviceCharacteristics deviceCharacteristics )
772774 {
773775 return new InputDeviceDescription
774776 {
@@ -777,7 +779,7 @@ private static InputDeviceDescription CreateSimpleDeviceDescriptionByRole(InputD
777779 manufacturer = "Manufacturer" ,
778780 capabilities = new XRDeviceDescriptor
779781 {
780- characteristics = CharacteristicsFromInputDeviceRole ( role ) ,
782+ characteristics = deviceCharacteristics ,
781783 inputFeatures = new List < XRFeatureDescriptor > ( )
782784 {
783785 new XRFeatureDescriptor ( )
@@ -799,7 +801,7 @@ private static InputDeviceDescription CreateMangledNameDeviceDescription()
799801 manufacturer = "__Manufacturer::" ,
800802 capabilities = new XRDeviceDescriptor
801803 {
802- characteristics = CharacteristicsFromInputDeviceRole ( InputDeviceRole . Generic ) ,
804+ characteristics = InputDeviceCharacteristics . HeadMounted ,
803805 inputFeatures = new List < XRFeatureDescriptor > ( )
804806 {
805807 new XRFeatureDescriptor ( )
@@ -833,7 +835,7 @@ public static InputDeviceDescription CreateDeviceDescription()
833835 manufacturer = "XRManufacturer" ,
834836 capabilities = new XRDeviceDescriptor
835837 {
836- characteristics = CharacteristicsFromInputDeviceRole ( InputDeviceRole . Generic ) ,
838+ characteristics = InputDeviceCharacteristics . HeadMounted ,
837839 inputFeatures = new List < XRFeatureDescriptor > ( )
838840 {
839841 new XRFeatureDescriptor ( )
@@ -905,7 +907,7 @@ public static InputDeviceDescription CreateDeviceDescription()
905907 manufacturer = "XRManufacturer" ,
906908 capabilities = new XRDeviceDescriptor
907909 {
908- characteristics = CharacteristicsFromInputDeviceRole ( InputDeviceRole . Generic ) ,
910+ characteristics = InputDeviceCharacteristics . HeadMounted ,
909911 inputFeatures = new List < XRFeatureDescriptor > ( )
910912 {
911913 new XRFeatureDescriptor ( )
@@ -1039,9 +1041,6 @@ public static InputDeviceDescription CreateDeviceDescription()
10391041 manufacturer = "XRManufacturer" ,
10401042 capabilities = new XRDeviceDescriptor
10411043 {
1042- #if ! UNITY_2019_3_OR_NEWER
1043- deviceRole = InputDeviceRole . Generic ,
1044- #endif
10451044 inputFeatures = new List < XRFeatureDescriptor > ( )
10461045 {
10471046 new XRFeatureDescriptor ( )
0 commit comments