@@ -53,7 +53,7 @@ public void Actions_CanConsumeInput(bool legacyComposites)
53
53
54
54
// Enable some actions individually to make sure the code that deals
55
55
// with re-resolution of already enabled bindings handles the enabling
56
- // of just individual actions out of the whole set correctlyuk .
56
+ // of just individual actions out of the whole set correctly .
57
57
action1 . Enable ( ) ;
58
58
action2 . Enable ( ) ;
59
59
@@ -2077,10 +2077,10 @@ public void Actions_CanCreateActionAssetWithMultipleActionMaps()
2077
2077
. AndThen ( Performed ( action4 ,
2078
2078
value : new StickDeadzoneProcessor ( ) . Process ( new Vector2 ( 0.123f , 0.234f ) ) * new Vector2 ( 1 , - 1 ) ,
2079
2079
control : gamepad . leftStick , time : startTime + 0.234 ) )
2080
- // map3/action5 should have been started.
2081
- . AndThen ( Started < TapInteraction > ( action5 , value : 1f , control : gamepad . buttonSouth , time : startTime + 0.345 ) )
2082
2080
// map2/action3 should have been started.
2083
2081
. AndThen ( Started < TapInteraction > ( action3 , value : 1f , control : gamepad . buttonSouth , time : startTime + 0.345 ) )
2082
+ // map3/action5 should have been started.
2083
+ . AndThen ( Started < TapInteraction > ( action5 , value : 1f , control : gamepad . buttonSouth , time : startTime + 0.345 ) )
2084
2084
// map3/action4 should have been performed as the stick has been moved
2085
2085
// beyond where it had already moved.
2086
2086
. AndThen ( Performed ( action4 ,
@@ -7463,7 +7463,10 @@ public void Actions_CanCreateAxisComposite()
7463
7463
InputSystem . QueueStateEvent ( gamepad , new GamepadState { rightTrigger = 0.456f } ) ;
7464
7464
InputSystem . Update ( ) ;
7465
7465
7466
- Assert . That ( trace , Performed ( action , control : gamepad . rightTrigger , value : 0.456f ) ) ;
7466
+ // Bit of an odd case. leftTrigger and rightTrigger have both changed state here so
7467
+ // in a way, it's up to the system which one to pick. Might be useful if it was deliberately
7468
+ // picking the control with the highest magnitude but not sure it's worth the effort.
7469
+ Assert . That ( trace , Performed ( action , control : gamepad . leftTrigger , value : 0.456f ) ) ;
7467
7470
7468
7471
trace . Clear ( ) ;
7469
7472
@@ -8177,7 +8180,7 @@ public void Actions_CompositesReportControlThatTriggeredTheCompositeInCallback()
8177
8180
InputSystem . QueueStateEvent ( keyboard , new KeyboardState ( Key . A , Key . S ) ) ;
8178
8181
InputSystem . Update ( ) ;
8179
8182
8180
- Assert . That ( performedControl , Is . EqualTo ( keyboard . aKey ) ) ;
8183
+ Assert . That ( performedControl , Is . EqualTo ( keyboard . sKey ) ) ;
8181
8184
8182
8185
LogAssert . NoUnexpectedReceived ( ) ;
8183
8186
}
@@ -10045,6 +10048,116 @@ public void Actions_RebindingCandidatesShouldBeSorted_IfAddingNewCandidate()
10045
10048
}
10046
10049
}
10047
10050
10051
+ // Straight from demo project
10052
+ public struct PointerInput
10053
+ {
10054
+ public bool Contact ;
10055
+ public int InputId ;
10056
+ public Vector2 Position ;
10057
+ public Vector2 ? Tilt ;
10058
+ public float ? Pressure ;
10059
+ public Vector2 ? Radius ;
10060
+ public float ? Twist ;
10061
+ }
10062
+
10063
+ public class PointerInputComposite : InputBindingComposite < PointerInput >
10064
+ {
10065
+ [ InputControl ( layout = "Button" ) ]
10066
+ public int contact ;
10067
+
10068
+ [ InputControl ( layout = "Vector2" ) ]
10069
+ public int position ;
10070
+
10071
+ [ InputControl ( layout = "Vector2" ) ]
10072
+ public int tilt ;
10073
+
10074
+ [ InputControl ( layout = "Vector2" ) ]
10075
+ public int radius ;
10076
+
10077
+ [ InputControl ( layout = "Axis" ) ]
10078
+ public int pressure ;
10079
+
10080
+ [ InputControl ( layout = "Axis" ) ]
10081
+ public int twist ;
10082
+
10083
+ [ InputControl ( layout = "Integer" ) ]
10084
+ public int inputId ;
10085
+
10086
+ public override PointerInput ReadValue ( ref InputBindingCompositeContext context )
10087
+ {
10088
+ var contact = context . ReadValueAsButton ( this . contact ) ;
10089
+ var pointerId = context . ReadValue < int > ( inputId ) ;
10090
+ var pressure = context . ReadValue < float > ( this . pressure ) ;
10091
+ var radius = context . ReadValue < Vector2 , Vector2MagnitudeComparer > ( this . radius ) ;
10092
+ var tilt = context . ReadValue < Vector2 , Vector2MagnitudeComparer > ( this . tilt ) ;
10093
+ var position = context . ReadValue < Vector2 , Vector2MagnitudeComparer > ( this . position ) ;
10094
+ var twist = context . ReadValue < float > ( this . twist ) ;
10095
+
10096
+ return new PointerInput
10097
+ {
10098
+ Contact = contact ,
10099
+ InputId = pointerId ,
10100
+ Position = position ,
10101
+ Tilt = tilt != default ? tilt : ( Vector2 ? ) null ,
10102
+ Pressure = pressure > 0 ? pressure : ( float ? ) null ,
10103
+ Radius = radius . sqrMagnitude > 0 ? radius : ( Vector2 ? ) null ,
10104
+ Twist = twist > 0 ? twist : ( float ? ) null ,
10105
+ } ;
10106
+ }
10107
+ }
10108
+
10109
+ // https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-98
10110
+ [ Test ]
10111
+ [ Category ( "Actions" ) ]
10112
+ [ TestCase ( true ) ]
10113
+ [ TestCase ( false ) ]
10114
+ public void Actions_WithMultipleCompositeBindings_WithoutEvaluateMagnitude_Works ( bool prepopulateTouchesBeforeEnablingAction )
10115
+ {
10116
+ InputSystem . RegisterBindingComposite < PointerInputComposite > ( ) ;
10117
+
10118
+ InputSystem . AddDevice < Touchscreen > ( ) ;
10119
+
10120
+ var actionMap = new InputActionMap ( "test" ) ;
10121
+ var action = actionMap . AddAction ( "point" , InputActionType . Value ) ;
10122
+ for ( var i = 0 ; i < 5 ; ++ i )
10123
+ action . AddCompositeBinding ( "PointerInput" )
10124
+ . With ( "contact" , $ "<Touchscreen>/touch{ i } /press")
10125
+ . With ( "position" , $ "<Touchscreen>/touch{ i } /position")
10126
+ . With ( "radius" , $ "<Touchscreen>/touch{ i } /radius")
10127
+ . With ( "pressure" , $ "<Touchscreen>/touch{ i } /pressure")
10128
+ . With ( "inputId" , $ "<Touchscreen>/touch{ i } /touchId") ;
10129
+
10130
+ var values = new List < PointerInput > ( ) ;
10131
+ action . started += ctx => values . Add ( ctx . ReadValue < PointerInput > ( ) ) ;
10132
+ action . performed += ctx => values . Add ( ctx . ReadValue < PointerInput > ( ) ) ;
10133
+ action . canceled += ctx => values . Add ( ctx . ReadValue < PointerInput > ( ) ) ;
10134
+
10135
+ if ( ! prepopulateTouchesBeforeEnablingAction ) // normally actions are enabled before any control actuations happen
10136
+ actionMap . Enable ( ) ;
10137
+
10138
+ // Start 5 touches, so we fill all slots [touch0, touch4] in Touchscreen with some valid touchId
10139
+ for ( var i = 0 ; i < 2 ; ++ i )
10140
+ BeginTouch ( 100 + i , new Vector2 ( 100 * ( i + 1 ) , 100 * ( i + 1 ) ) ) ;
10141
+ for ( var i = 0 ; i < 2 ; ++ i )
10142
+ EndTouch ( 100 + i , new Vector2 ( 100 * ( i + 1 ) , 100 * ( i + 1 ) ) ) ;
10143
+ Assert . That ( values . Count , Is . EqualTo ( prepopulateTouchesBeforeEnablingAction ? 0 : 3 ) ) ;
10144
+ values . Clear ( ) ;
10145
+
10146
+ // Now when enabling actionMap ..
10147
+ actionMap . Enable ( ) ;
10148
+ // On the following update we will trigger OnBeforeUpdate which will rise started/performed
10149
+ // from InputActionState.OnBeforeInitialUpdate as controls are "actuated"
10150
+ InputSystem . Update ( ) ;
10151
+ Assert . That ( values . Count , Is . EqualTo ( prepopulateTouchesBeforeEnablingAction ? 2 : 0 ) ) ; // started+performed arrive from OnBeforeUpdate
10152
+ values . Clear ( ) ;
10153
+
10154
+ // Now subsequent touches should not be ignored
10155
+ BeginTouch ( 200 , new Vector2 ( 1 , 1 ) ) ;
10156
+ Assert . That ( values . Count , Is . EqualTo ( 1 ) ) ;
10157
+ Assert . That ( values [ 0 ] . InputId , Is . EqualTo ( 200 ) ) ;
10158
+ Assert . That ( values [ 0 ] . Position , Is . EqualTo ( new Vector2 ( 1 , 1 ) ) ) ;
10159
+ }
10160
+
10048
10161
[ Test ]
10049
10162
[ Category ( "Actions" ) ]
10050
10163
[ Ignore ( "TODO" ) ]
0 commit comments