8
8
using UnityEngine . TestTools ;
9
9
using Is = UnityEngine . TestTools . Constraints . Is ;
10
10
11
-
12
11
partial class CoreTests
13
12
{
14
- internal GameObject SetUpScene ( )
13
+ internal GameObject SetUpScene ( Type pointerType , out Pointer pointer )
15
14
{
16
15
var gameObject = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
17
16
gameObject . transform . position = Vector3 . zero ;
18
17
var camera = new GameObject ( "MainCamera" ) . AddComponent < Camera > ( ) ;
19
18
camera . transform . position = new Vector3 ( 0 , 0 , - 2f ) ;
20
19
camera . tag = "MainCamera" ;
20
+ pointer = ( Pointer ) InputSystem . s_Manager . AddDevice ( pointerType ) ;
21
+ InputSystem . AddDevice ( pointer ) ;
21
22
return gameObject ;
22
23
}
23
24
24
- private static HashSet < Type > _testDevices = new HashSet < Type > { typeof ( Mouse ) , typeof ( Pen ) , typeof ( Touchscreen ) } ;
25
+ private static readonly Type [ ] _testDevices = new Type [ ] { typeof ( Mouse ) , typeof ( Pen ) , typeof ( Touchscreen ) } ;
25
26
// OnMouseOver/Exit and Hover events are not supported for touch
26
- private static HashSet < Type > _testDevicesNoTouch = new HashSet < Type > { typeof ( Mouse ) , typeof ( Pen ) } ;
27
+ private static readonly Type [ ] _testDevicesNoTouch = new Type [ ] { typeof ( Mouse ) , typeof ( Pen ) } ;
27
28
28
29
[ UnityTest ]
29
30
[ Category ( "MouseEvents" ) ]
30
31
public IEnumerator MouseEvents_CanReceiveOnMouseDown ( [ ValueSource ( nameof ( _testDevices ) ) ] Type pointerType )
31
32
{
32
- var pointer = ( Pointer ) InputSystem . s_Manager . AddDevice ( pointerType ) ;
33
- InputSystem . AddDevice ( pointer ) ;
34
-
35
- var gameObject = SetUpScene ( ) ;
33
+ var gameObject = SetUpScene ( pointerType , out var pointer ) ;
36
34
gameObject . AddComponent < OnMouseEventsTest > ( ) ;
37
35
var vec = Camera . main . WorldToScreenPoint ( gameObject . transform . position ) ;
38
36
@@ -46,10 +44,7 @@ public IEnumerator MouseEvents_CanReceiveOnMouseDown([ValueSource(nameof(_testDe
46
44
[ Category ( "MouseEvents" ) ]
47
45
public IEnumerator MouseEvents_CanReceiveOnMouseUp ( [ ValueSource ( nameof ( _testDevices ) ) ] Type pointerType )
48
46
{
49
- var pointer = ( Pointer ) InputSystem . s_Manager . AddDevice ( pointerType ) ;
50
- InputSystem . AddDevice ( pointer ) ;
51
-
52
- var gameObject = SetUpScene ( ) ;
47
+ var gameObject = SetUpScene ( pointerType , out var pointer ) ;
53
48
gameObject . AddComponent < OnMouseEventsTest > ( ) ;
54
49
var vec = Camera . main . WorldToScreenPoint ( gameObject . transform . position ) ;
55
50
Set ( pointer , new Vector2 ( vec . x , vec . y ) , true , false ) ;
@@ -63,10 +58,7 @@ public IEnumerator MouseEvents_CanReceiveOnMouseUp([ValueSource(nameof(_testDevi
63
58
[ Category ( "MouseEvents" ) ]
64
59
public IEnumerator MouseEvents_CanReceiveOnMouseUpAsButton ( [ ValueSource ( nameof ( _testDevices ) ) ] Type pointerType )
65
60
{
66
- var pointer = ( Pointer ) InputSystem . s_Manager . AddDevice ( pointerType ) ;
67
- InputSystem . AddDevice ( pointer ) ;
68
-
69
- var gameObject = SetUpScene ( ) ;
61
+ var gameObject = SetUpScene ( pointerType , out var pointer ) ;
70
62
gameObject . AddComponent < OnMousEventTestTwo > ( ) ;
71
63
var vec = Camera . main . WorldToScreenPoint ( gameObject . transform . position ) ;
72
64
Set ( pointer , new Vector2 ( vec . x , vec . y ) , true , false ) ;
@@ -80,10 +72,7 @@ public IEnumerator MouseEvents_CanReceiveOnMouseUpAsButton([ValueSource(nameof(_
80
72
[ Category ( "MouseEvents" ) ]
81
73
public IEnumerator MouseEvents_CanReceiveOnMouseDrag ( [ ValueSource ( nameof ( _testDevices ) ) ] Type pointerType )
82
74
{
83
- var pointer = ( Pointer ) InputSystem . s_Manager . AddDevice ( pointerType ) ;
84
- InputSystem . AddDevice ( pointer ) ;
85
-
86
- var gameObject = SetUpScene ( ) ;
75
+ var gameObject = SetUpScene ( pointerType , out var pointer ) ;
87
76
gameObject . AddComponent < OnMouseEventsTest > ( ) ;
88
77
var vec = Camera . main . WorldToScreenPoint ( gameObject . transform . position ) ;
89
78
Set ( pointer , new Vector2 ( vec . x , vec . y ) , false , false ) ;
@@ -99,10 +88,7 @@ public IEnumerator MouseEvents_CanReceiveOnMouseDrag([ValueSource(nameof(_testDe
99
88
[ Category ( "MouseEvents" ) ]
100
89
public IEnumerator MouseEvents_CanReceiveOnMouseEnterAndMouseExit ( [ ValueSource ( nameof ( _testDevicesNoTouch ) ) ] Type pointerType )
101
90
{
102
- var pointer = ( Pointer ) InputSystem . s_Manager . AddDevice ( pointerType ) ;
103
- InputSystem . AddDevice ( pointer ) ;
104
-
105
- var gameObject = SetUpScene ( ) ;
91
+ var gameObject = SetUpScene ( pointerType , out var pointer ) ;
106
92
gameObject . AddComponent < OnMouseEventsTest > ( ) ;
107
93
var vec = Camera . main . WorldToScreenPoint ( gameObject . transform . position ) ;
108
94
Set ( pointer , new Vector2 ( 0 , 0 ) , false , false ) ;
@@ -120,10 +106,7 @@ public IEnumerator MouseEvents_CanReceiveOnMouseEnterAndMouseExit([ValueSource(n
120
106
[ Category ( "MouseEvents" ) ]
121
107
public IEnumerator MouseEvents_CanReceiveOnMouseOver ( [ ValueSource ( nameof ( _testDevicesNoTouch ) ) ] Type pointerType )
122
108
{
123
- var pointer = ( Pointer ) InputSystem . s_Manager . AddDevice ( pointerType ) ;
124
- InputSystem . AddDevice ( pointer ) ;
125
-
126
- var gameObject = SetUpScene ( ) ;
109
+ var gameObject = SetUpScene ( pointerType , out var pointer ) ;
127
110
gameObject . AddComponent < OnMousEventTestTwo > ( ) ;
128
111
var vec = Camera . main . WorldToScreenPoint ( gameObject . transform . position ) ;
129
112
Set ( pointer , new Vector2 ( vec . x , vec . y ) , false , false ) ;
0 commit comments