1+ // Copyright (c) Microsoft Corporation. All rights reserved.
2+ // Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+ using Microsoft . MixedReality . Toolkit . Internal . Definitions . Devices ;
5+ using Microsoft . MixedReality . Toolkit . Internal . Definitions . InputSystem ;
6+ using Microsoft . MixedReality . Toolkit . Internal . Definitions . Utilities ;
7+ using Microsoft . MixedReality . Toolkit . Internal . Utilities ;
8+ using NUnit . Framework ;
9+ using UnityEngine ;
10+
11+ namespace Microsoft . MixedReality . Toolkit . Tests
12+ {
13+ public class UnityInputManagerHelperTests
14+ {
15+ [ Test ]
16+ public void Test01_TestAddDefaultMRTKMappings ( )
17+ {
18+ //First apply settings
19+ InputMappingAxisUtility . ApplyMappings ( ) ;
20+ foreach ( var mapping in InputMappingAxisUtility . MRTKDefaultInputMappingNames )
21+ {
22+ Assert . IsTrue ( InputMappingAxisUtility . DoesAxisNameExist ( mapping ) ) ;
23+ }
24+ }
25+
26+ [ Test ]
27+ public void Test02_TestRemoveDefaultMRTKMappings ( )
28+ {
29+ //First apply settings
30+ InputMappingAxisUtility . ApplyMappings ( ) ;
31+
32+ InputMappingAxisUtility . RemoveMappings ( ) ;
33+
34+ foreach ( var mapping in InputMappingAxisUtility . MRTKDefaultInputMappingNames )
35+ {
36+ Assert . IsFalse ( InputMappingAxisUtility . DoesAxisNameExist ( mapping ) ) ;
37+ }
38+ }
39+
40+ [ Test ]
41+ public void Test03_TestAddCustomMappings ( )
42+ {
43+ //Ensure default mappings are removed
44+ InputMappingAxisUtility . RemoveMappings ( ) ;
45+
46+ InputMappingAxisUtility . InputManagerAxis [ ] OpenVRControllerAxisMappings =
47+ {
48+ new InputMappingAxisUtility . InputManagerAxis ( ) { Name = "OPENVR_TOUCHPAD_LEFT_CONTROLLER" , Dead = 0.001f , Sensitivity = 1 , Invert = false , Type = InputMappingAxisUtility . MappingAxisType . JoystickAxis , Axis = 1 } ,
49+ new InputMappingAxisUtility . InputManagerAxis ( ) { Name = "OPENVR_TOUCHPAD_RIGHT_CONTROLLER" , Dead = 0.001f , Sensitivity = 1 , Invert = false , Type = InputMappingAxisUtility . MappingAxisType . JoystickAxis , Axis = 2 }
50+ } ;
51+
52+ InputMappingAxisUtility . ApplyMappings ( OpenVRControllerAxisMappings ) ;
53+
54+
55+ Assert . IsTrue ( InputMappingAxisUtility . DoesAxisNameExist ( "OPENVR_TOUCHPAD_LEFT_CONTROLLER" ) ) ;
56+ Assert . IsTrue ( InputMappingAxisUtility . DoesAxisNameExist ( "OPENVR_TOUCHPAD_RIGHT_CONTROLLER" ) ) ;
57+
58+ }
59+
60+ [ Test ]
61+ public void Test04_TestRemoveCustomMappings ( )
62+ {
63+ //Ensure default mappings are removed
64+ InputMappingAxisUtility . RemoveMappings ( ) ;
65+
66+ InputMappingAxisUtility . InputManagerAxis [ ] OpenVRControllerAxisMappings =
67+ {
68+ new InputMappingAxisUtility . InputManagerAxis ( ) { Name = "OPENVR_TOUCHPAD_LEFT_CONTROLLER" , Dead = 0.001f , Sensitivity = 1 , Invert = false , Type = InputMappingAxisUtility . MappingAxisType . JoystickAxis , Axis = 1 } ,
69+ new InputMappingAxisUtility . InputManagerAxis ( ) { Name = "OPENVR_TOUCHPAD_RIGHT_CONTROLLER" , Dead = 0.001f , Sensitivity = 1 , Invert = false , Type = InputMappingAxisUtility . MappingAxisType . JoystickAxis , Axis = 2 }
70+ } ;
71+
72+ InputMappingAxisUtility . RemoveMappings ( OpenVRControllerAxisMappings ) ;
73+
74+ Assert . IsFalse ( InputMappingAxisUtility . DoesAxisNameExist ( "OPENVR_TOUCHPAD_LEFT_CONTROLLER" ) ) ;
75+ Assert . IsFalse ( InputMappingAxisUtility . DoesAxisNameExist ( "OPENVR_TOUCHPAD_RIGHT_CONTROLLER" ) ) ;
76+
77+ }
78+ }
79+ }
0 commit comments