@@ -23,16 +23,14 @@ internal class XRTests : CoreTestsFixture
23
23
{
24
24
[ Test ]
25
25
[ 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 )
34
32
{
35
- var deviceDescription = CreateSimpleDeviceDescriptionByRole ( role ) ;
33
+ var deviceDescription = CreateSimpleDeviceDescriptionByType ( characteristics ) ;
36
34
runtime . ReportNewInputDevice ( deviceDescription . ToJson ( ) ) ;
37
35
38
36
InputSystem . Update ( ) ;
@@ -44,6 +42,7 @@ public void Devices_XRDeviceRoleDeterminesTypeOfDevice(InputDeviceRole role, str
44
42
45
43
var generatedLayout = InputSystem . LoadLayout (
46
44
$ "{ XRUtilities . InterfaceCurrent } ::{ deviceDescription . manufacturer } ::{ deviceDescription . product } ") ;
45
+
47
46
Assert . That ( generatedLayout , Is . Not . Null ) ;
48
47
if ( baseLayoutName == null )
49
48
Assert . That ( generatedLayout . baseLayouts , Is . Empty ) ;
@@ -55,7 +54,8 @@ public void Devices_XRDeviceRoleDeterminesTypeOfDevice(InputDeviceRole role, str
55
54
[ Category ( "Devices" ) ]
56
55
public void Devices_CanChangeHandednessOfXRController ( )
57
56
{
58
- var deviceDescription = CreateSimpleDeviceDescriptionByRole ( InputDeviceRole . LeftHanded ) ;
57
+ var deviceDescription = CreateSimpleDeviceDescriptionByType ( InputDeviceCharacteristics . Controller | InputDeviceCharacteristics . HeldInHand | InputDeviceCharacteristics . Left ) ;
58
+
59
59
runtime . ReportNewInputDevice ( deviceDescription . ToJson ( ) ) ;
60
60
61
61
InputSystem . Update ( ) ;
@@ -79,7 +79,7 @@ public void Devices_CanChangeHandednessOfXRController()
79
79
[ Category ( "Layouts" ) ]
80
80
public void Layouts_XRLayoutIsNamespacedAsInterfaceManufacturerDevice ( )
81
81
{
82
- var deviceDescription = CreateSimpleDeviceDescriptionByRole ( InputDeviceRole . Generic ) ;
82
+ var deviceDescription = CreateSimpleDeviceDescriptionByType ( InputDeviceCharacteristics . HeadMounted ) ;
83
83
runtime . ReportNewInputDevice ( deviceDescription . ToJson ( ) ) ;
84
84
85
85
InputSystem . Update ( ) ;
@@ -96,7 +96,7 @@ public void Layouts_XRLayoutIsNamespacedAsInterfaceManufacturerDevice()
96
96
[ Category ( "Layouts" ) ]
97
97
public void Layouts_XRLayoutWithoutManufacturer_IsNamespacedAsInterfaceDevice ( )
98
98
{
99
- var deviceDescription = CreateSimpleDeviceDescriptionByRole ( InputDeviceRole . Generic ) ;
99
+ var deviceDescription = CreateSimpleDeviceDescriptionByType ( InputDeviceCharacteristics . HeadMounted ) ;
100
100
deviceDescription . manufacturer = null ;
101
101
runtime . ReportNewInputDevice ( deviceDescription . ToJson ( ) ) ;
102
102
@@ -146,7 +146,7 @@ public void Layouts_XRLayoutFeatures_OnlyContainAllowedCharacters()
146
146
[ Category ( "Layouts" ) ]
147
147
public void Layouts_XRDevicesWithNoOrInvalidCapabilities_DoNotCreateLayouts ( )
148
148
{
149
- var deviceDescription = CreateSimpleDeviceDescriptionByRole ( InputDeviceRole . Generic ) ;
149
+ var deviceDescription = CreateSimpleDeviceDescriptionByType ( InputDeviceCharacteristics . HeadMounted ) ;
150
150
deviceDescription . capabilities = null ;
151
151
runtime . ReportNewInputDevice ( deviceDescription . ToJson ( ) ) ;
152
152
@@ -746,29 +746,31 @@ public void Layouts_PoseControlsCanBeCreatedBySubcontrols()
746
746
747
747
private const int kNumBaseHMDControls = 10 ;
748
748
749
- static InputDeviceCharacteristics CharacteristicsFromInputDeviceRole ( InputDeviceRole role )
749
+ InputDeviceRole RoleFromCharacteristics ( InputDeviceCharacteristics characteristics )
750
750
{
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 ;
769
771
}
770
772
771
- private static InputDeviceDescription CreateSimpleDeviceDescriptionByRole ( InputDeviceRole role )
773
+ private static InputDeviceDescription CreateSimpleDeviceDescriptionByType ( InputDeviceCharacteristics deviceCharacteristics )
772
774
{
773
775
return new InputDeviceDescription
774
776
{
@@ -777,7 +779,7 @@ private static InputDeviceDescription CreateSimpleDeviceDescriptionByRole(InputD
777
779
manufacturer = "Manufacturer" ,
778
780
capabilities = new XRDeviceDescriptor
779
781
{
780
- characteristics = CharacteristicsFromInputDeviceRole ( role ) ,
782
+ characteristics = deviceCharacteristics ,
781
783
inputFeatures = new List < XRFeatureDescriptor > ( )
782
784
{
783
785
new XRFeatureDescriptor ( )
@@ -799,7 +801,7 @@ private static InputDeviceDescription CreateMangledNameDeviceDescription()
799
801
manufacturer = "__Manufacturer::" ,
800
802
capabilities = new XRDeviceDescriptor
801
803
{
802
- characteristics = CharacteristicsFromInputDeviceRole ( InputDeviceRole . Generic ) ,
804
+ characteristics = InputDeviceCharacteristics . HeadMounted ,
803
805
inputFeatures = new List < XRFeatureDescriptor > ( )
804
806
{
805
807
new XRFeatureDescriptor ( )
@@ -833,7 +835,7 @@ public static InputDeviceDescription CreateDeviceDescription()
833
835
manufacturer = "XRManufacturer" ,
834
836
capabilities = new XRDeviceDescriptor
835
837
{
836
- characteristics = CharacteristicsFromInputDeviceRole ( InputDeviceRole . Generic ) ,
838
+ characteristics = InputDeviceCharacteristics . HeadMounted ,
837
839
inputFeatures = new List < XRFeatureDescriptor > ( )
838
840
{
839
841
new XRFeatureDescriptor ( )
@@ -905,7 +907,7 @@ public static InputDeviceDescription CreateDeviceDescription()
905
907
manufacturer = "XRManufacturer" ,
906
908
capabilities = new XRDeviceDescriptor
907
909
{
908
- characteristics = CharacteristicsFromInputDeviceRole ( InputDeviceRole . Generic ) ,
910
+ characteristics = InputDeviceCharacteristics . HeadMounted ,
909
911
inputFeatures = new List < XRFeatureDescriptor > ( )
910
912
{
911
913
new XRFeatureDescriptor ( )
@@ -1039,9 +1041,6 @@ public static InputDeviceDescription CreateDeviceDescription()
1039
1041
manufacturer = "XRManufacturer" ,
1040
1042
capabilities = new XRDeviceDescriptor
1041
1043
{
1042
- #if ! UNITY_2019_3_OR_NEWER
1043
- deviceRole = InputDeviceRole . Generic ,
1044
- #endif
1045
1044
inputFeatures = new List < XRFeatureDescriptor > ( )
1046
1045
{
1047
1046
new XRFeatureDescriptor ( )
0 commit comments