Skip to content

Commit 7320077

Browse files
author
Rene Damm
committed
MERGE: develop => stable.
2 parents 8f61b4b + e98b0d6 commit 7320077

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4242
-2114
lines changed

Assets/Tests/InputSystem/APIVerificationTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ void CheckHTMLFileLinkConsistency(string htmlFile, List<string> unresolvedLinks,
512512
}
513513
}
514514

515+
////TODO: add verification of *online* links to this; probably prone to instability and maybe they shouldn't fail tests but would
516+
//// be great to have some way of diagnosing links that have gone stale
515517
[Test]
516518
[Category("API")]
517519
#if UNITY_EDITOR_OSX

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 171 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,42 @@ public void Actions_CanReadValueFromAction_InCallback()
739739
Assert.That(receivedValue, Is.EqualTo(1).Within(0.00001));
740740
}
741741

742+
[Test]
743+
[Category("Actions")]
744+
public void Actions_CanReadValueFromAction_InCallback_AsButton()
745+
{
746+
InputSystem.settings.defaultButtonPressPoint = 0.5f;
747+
748+
var action = new InputAction(binding: "<Gamepad>/leftTrigger");
749+
var gamepad = InputSystem.AddDevice<Gamepad>();
750+
751+
action.Enable();
752+
753+
bool? receivedValue = null;
754+
action.performed +=
755+
ctx =>
756+
{
757+
Assert.That(receivedValue, Is.Null);
758+
receivedValue = ctx.ReadValueAsButton();
759+
};
760+
761+
Set(gamepad.leftTrigger, 0.25f);
762+
763+
Assert.That(receivedValue, Is.False);
764+
765+
receivedValue = null;
766+
767+
Set(gamepad.leftTrigger, 0.75f);
768+
769+
Assert.That(receivedValue, Is.True);
770+
771+
receivedValue = null;
772+
773+
Set(gamepad.leftTrigger, 0.15f);
774+
775+
Assert.That(receivedValue, Is.False);
776+
}
777+
742778
// Some code needs to be able to just generically transfer values from A to B. For this, the
743779
// generic ReadValue<TValue>() API isn't sufficient.
744780
[Test]
@@ -1161,53 +1197,33 @@ public void Actions_CanByPassControlActuationChecks_UsingPasshtroughAction()
11611197
var action = new InputAction(type: InputActionType.PassThrough, binding: "<Gamepad>/*stick");
11621198
action.Enable();
11631199

1164-
using (var trace = new InputActionTrace())
1200+
using (var trace = new InputActionTrace(action))
11651201
{
1166-
trace.SubscribeTo(action);
1167-
11681202
Set(gamepad.leftStick, new Vector2(0.123f, 0.234f));
11691203

1170-
var actions = trace.ToArray();
1171-
Assert.That(actions, Has.Length.EqualTo(1));
1172-
Assert.That(actions[0].phase, Is.EqualTo(InputActionPhase.Performed));
1173-
Assert.That(actions[0].control, Is.SameAs(gamepad.leftStick));
1174-
Assert.That(actions[0].ReadValue<Vector2>(),
1175-
Is.EqualTo(new StickDeadzoneProcessor().Process(new Vector2(0.123f, 0.234f)))
1176-
.Using(Vector2EqualityComparer.Instance));
1204+
Assert.That(trace,
1205+
Performed(action, gamepad.leftStick, new StickDeadzoneProcessor().Process(new Vector2(0.123f, 0.234f))));
11771206

11781207
trace.Clear();
11791208

11801209
Set(gamepad.leftStick, new Vector2(0.234f, 0.345f));
11811210

1182-
actions = trace.ToArray();
1183-
Assert.That(actions, Has.Length.EqualTo(1));
1184-
Assert.That(actions[0].phase, Is.EqualTo(InputActionPhase.Performed));
1185-
Assert.That(actions[0].control, Is.SameAs(gamepad.leftStick));
1186-
Assert.That(actions[0].ReadValue<Vector2>(),
1187-
Is.EqualTo(new StickDeadzoneProcessor().Process(new Vector2(0.234f, 0.345f)))
1188-
.Using(Vector2EqualityComparer.Instance));
1211+
Assert.That(trace,
1212+
Performed(action, gamepad.leftStick, new StickDeadzoneProcessor().Process(new Vector2(0.234f, 0.345f))));
11891213

11901214
trace.Clear();
11911215

11921216
Set(gamepad.rightStick, new Vector2(0.123f, 0.234f));
11931217

1194-
actions = trace.ToArray();
1195-
Assert.That(actions, Has.Length.EqualTo(1));
1196-
Assert.That(actions[0].phase, Is.EqualTo(InputActionPhase.Performed));
1197-
Assert.That(actions[0].control, Is.SameAs(gamepad.rightStick));
1198-
Assert.That(actions[0].ReadValue<Vector2>(),
1199-
Is.EqualTo(new StickDeadzoneProcessor().Process(new Vector2(0.123f, 0.234f)))
1200-
.Using(Vector2EqualityComparer.Instance));
1218+
Assert.That(trace,
1219+
Performed(action, gamepad.rightStick, new StickDeadzoneProcessor().Process(new Vector2(0.123f, 0.234f))));
12011220

12021221
trace.Clear();
12031222

12041223
Set(gamepad.rightStick, Vector2.zero);
12051224

1206-
actions = trace.ToArray();
1207-
Assert.That(actions, Has.Length.EqualTo(1));
1208-
Assert.That(actions[0].phase, Is.EqualTo(InputActionPhase.Performed));
1209-
Assert.That(actions[0].control, Is.SameAs(gamepad.rightStick));
1210-
Assert.That(actions[0].ReadValue<Vector2>(), Is.EqualTo(Vector2.zero).Using(Vector2EqualityComparer.Instance));
1225+
Assert.That(trace,
1226+
Performed(action, gamepad.rightStick, Vector2.zero));
12111227
}
12121228
}
12131229

@@ -2784,6 +2800,46 @@ public void Actions_CanAddProcessorsToBindings()
27842800
Assert.That(receivedVector.Value.y, Is.EqualTo(0.5678).Within(0.00001));
27852801
}
27862802

2803+
// https://fogbugz.unity3d.com/f/cases/1207082/
2804+
[Test]
2805+
[Category("Actions")]
2806+
public void Actions_CanAddProcessorsToCompositeBindings()
2807+
{
2808+
var keyboard = InputSystem.AddDevice<Keyboard>();
2809+
2810+
var action = new InputAction();
2811+
action.AddCompositeBinding("2DVector", processors: "invertVector2(invertX=true,invertY=true)")
2812+
.With("Up", "<Keyboard>/w")
2813+
.With("Down", "<Keyboard>/s")
2814+
.With("Left", "<Keyboard>/a")
2815+
.With("Right", "<Keyboard>/d");
2816+
2817+
action.Enable();
2818+
2819+
// Left -> Right.
2820+
Press(keyboard.aKey);
2821+
2822+
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(new Vector2(1, 0)));
2823+
2824+
// Right -> Left.
2825+
Release(keyboard.aKey);
2826+
Press(keyboard.dKey);
2827+
2828+
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(new Vector2(-1, 0)));
2829+
2830+
// Up -> Down.
2831+
Release(keyboard.dKey);
2832+
Press(keyboard.wKey);
2833+
2834+
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(new Vector2(0, -1)));
2835+
2836+
// Down -> Up.
2837+
Release(keyboard.wKey);
2838+
Press(keyboard.sKey);
2839+
2840+
Assert.That(action.ReadValue<Vector2>(), Is.EqualTo(new Vector2(0, 1)));
2841+
}
2842+
27872843
[Test]
27882844
[Category("Actions")]
27892845
public void Actions_CanAddScaleProcessor()
@@ -3588,6 +3644,69 @@ public void Actions_CanEnableActionThatHasNoControls()
35883644
Assert.That(action2.enabled, Is.True);
35893645
}
35903646

3647+
[Test]
3648+
[Category("Actions")]
3649+
public void Actions_CanMixEnablingSingleActionsAndEntireActionMaps()
3650+
{
3651+
var gamepad = InputSystem.AddDevice<Gamepad>();
3652+
3653+
var asset = ScriptableObject.CreateInstance<InputActionAsset>();
3654+
var map1 = new InputActionMap("map1");
3655+
var map2 = new InputActionMap("map2");
3656+
var action1 = map1.AddAction("action1", binding: "<Gamepad>/buttonSouth");
3657+
var action2 = map1.AddAction("action2", binding: "<Gamepad>/buttonNorth");
3658+
var action3 = map2.AddAction("action3", binding: "<Gamepad>/buttonSouth");
3659+
var action4 = map2.AddAction("action4", binding: "<Gamepad>/buttonNorth");
3660+
asset.AddActionMap(map1);
3661+
asset.AddActionMap(map2);
3662+
3663+
action3.Enable();
3664+
map1.Enable();
3665+
3666+
using (var trace1 = new InputActionTrace(action1))
3667+
using (var trace2 = new InputActionTrace(action2))
3668+
using (var trace3 = new InputActionTrace(action3))
3669+
using (var trace4 = new InputActionTrace(action4))
3670+
{
3671+
PressAndRelease(gamepad.buttonSouth);
3672+
3673+
Assert.That(trace1, Started(action1).AndThen(Performed(action1)).AndThen(Canceled(action1)));
3674+
Assert.That(trace2, Is.Empty);
3675+
Assert.That(trace3, Started(action3).AndThen(Performed(action3)).AndThen(Canceled(action3)));
3676+
Assert.That(trace4, Is.Empty);
3677+
3678+
trace1.Clear();
3679+
trace2.Clear();
3680+
trace3.Clear();
3681+
trace4.Clear();
3682+
3683+
map1.Disable();
3684+
map2.Enable();
3685+
3686+
PressAndRelease(gamepad.buttonSouth);
3687+
3688+
Assert.That(trace1, Is.Empty);
3689+
Assert.That(trace2, Is.Empty);
3690+
Assert.That(trace3, Started(action3).AndThen(Performed(action3)).AndThen(Canceled(action3)));
3691+
Assert.That(trace4, Is.Empty);
3692+
3693+
trace1.Clear();
3694+
trace2.Clear();
3695+
trace3.Clear();
3696+
trace4.Clear();
3697+
3698+
map1.Enable();
3699+
map2.Disable();
3700+
3701+
PressAndRelease(gamepad.buttonSouth);
3702+
3703+
Assert.That(trace1, Started(action1).AndThen(Performed(action1)).AndThen(Canceled(action1)));
3704+
Assert.That(trace2, Is.Empty);
3705+
Assert.That(trace3, Is.Empty);
3706+
Assert.That(trace4, Is.Empty);
3707+
}
3708+
}
3709+
35913710
[Test]
35923711
[Category("Actions")]
35933712
public void Actions_CanTargetSingleDeviceWithMultipleActions()
@@ -4762,7 +4881,7 @@ public void Actions_WhenGettingDisplayTextForBindingsOnAction_InteractionsAreSho
47624881

47634882
// Can suppress.
47644883
Assert.That(action1.GetBindingDisplayString(InputBinding.DisplayStringOptions.DontIncludeInteractions),
4765-
Is.EqualTo("Hold " + GamepadState.ButtonSouthShortDisplayName));
4884+
Is.EqualTo(GamepadState.ButtonSouthShortDisplayName));
47664885
}
47674886

47684887
[Test]
@@ -5724,7 +5843,6 @@ public void Actions_CompositesInDifferentMapsTiedToSameControlsWork()
57245843
asset.AddActionMap(map2);
57255844
asset.Enable();
57265845

5727-
57285846
InputControl performedControl1 = null;
57295847
InputControl performedControl2 = null;
57305848
action1.performed += ctx => performedControl1 = ctx.control;
@@ -6266,6 +6384,28 @@ public void Actions_CanEnableAndDisableEntireMap()
62666384
Assert.That(action2.enabled, Is.False);
62676385
}
62686386

6387+
// https://fogbugz.unity3d.com/f/cases/1213085 (bindings that refer to non-existent actions should not lead to errors)
6388+
[Test]
6389+
[Category("Actions")]
6390+
public void Actions_CanEnableAndDisableEntireMap_EvenWhenBindingsReferToNonExistentActions()
6391+
{
6392+
var gamepad = InputSystem.AddDevice<Gamepad>();
6393+
6394+
var map = new InputActionMap();
6395+
map.AddAction("action", binding: "<Gamepad>/buttonSouth");
6396+
map.AddBinding("<Gamepad>/buttonNorth", action: "DoesNotExist");
6397+
6398+
// Also try the same for a composite binding.
6399+
map.AddBinding(new InputBinding { path = "1DAxis", isComposite = true, action = "DoesNotExist" });
6400+
map.AddBinding(new InputBinding { name = "Positive", path = "<Gamepad>/leftTrigger", isPartOfComposite = true });
6401+
map.AddBinding(new InputBinding { name = "Negative", path = "<Gamepad>/rightTrigger", isPartOfComposite = true });
6402+
6403+
Assert.That(() => map.Enable(), Throws.Nothing);
6404+
6405+
Assert.That(() => Press(gamepad.buttonNorth), Throws.Nothing);
6406+
Assert.That(() => Press(gamepad.leftTrigger), Throws.Nothing);
6407+
}
6408+
62696409
[Test]
62706410
[Category("Actions")]
62716411
public void Actions_CanEnableAndDisableSingleActionFromMap()

Assets/Tests/InputSystem/CoreTests_Actions_Interactions.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
using System.Linq;
22
using NUnit.Framework;
3+
using UnityEngine;
34
using UnityEngine.InputSystem;
45
using UnityEngine.InputSystem.Interactions;
56
using UnityEngine.InputSystem.LowLevel;
67
using UnityEngine.InputSystem.Utilities;
7-
using UnityEngine.InputSystem.XR;
88
using UnityEngine.Scripting;
99

1010
internal partial class CoreTests
1111
{
1212
[Preserve]
1313
class InteractionThatOnlyPerforms : IInputInteraction<float>
1414
{
15+
// Get rid of unused field warning.
16+
#pragma warning disable CS0649
1517
public bool stayPerformed;
18+
#pragma warning restore CS0649
1619

1720
public void Process(ref InputInteractionContext context)
1821
{
@@ -187,6 +190,47 @@ public void Actions_CanPerformPressInteraction()
187190
}
188191
}
189192

193+
// https://fogbugz.unity3d.com/f/cases/1205285/
194+
[Test]
195+
[Category("Actions")]
196+
public void Actions_CanPerformPressInteraction_AndTriggerInteractionResetInCallback()
197+
{
198+
var keyboard = InputSystem.AddDevice<Keyboard>();
199+
200+
var asset = ScriptableObject.CreateInstance<InputActionAsset>();
201+
var map1 = new InputActionMap("map1");
202+
var map2 = new InputActionMap("map2");
203+
asset.AddActionMap(map1);
204+
asset.AddActionMap(map2);
205+
206+
var action1 = map1.AddAction("action1");
207+
var action2 = map2.AddAction("action2");
208+
// PressInteraction used to set some local state *after* trigger callbacks. This meant that if the
209+
// callback triggered a Reset() call, PressInteraction would then overwrite state from the reset.
210+
action1.AddBinding("<Keyboard>/a", interactions: "press(behavior=0)");
211+
action2.AddBinding("<Keyboard>/b", interactions: "press(behavior=0)");
212+
213+
action1.performed += _ => { map1.Disable(); map2.Enable(); };
214+
action2.performed += _ => { map2.Disable(); map1.Enable(); };
215+
216+
map1.Enable();
217+
218+
PressAndRelease(keyboard.aKey);
219+
220+
Assert.That(map1.enabled, Is.False);
221+
Assert.That(map2.enabled, Is.True);
222+
223+
PressAndRelease(keyboard.bKey);
224+
225+
Assert.That(map1.enabled, Is.True);
226+
Assert.That(map2.enabled, Is.False);
227+
228+
PressAndRelease(keyboard.aKey);
229+
230+
Assert.That(map1.enabled, Is.False);
231+
Assert.That(map2.enabled, Is.True);
232+
}
233+
190234
[Test]
191235
[Category("Actions")]
192236
public void Actions_CanPerformHoldInteraction()

Assets/Tests/InputSystem/CoreTests_Editor.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,6 +2210,31 @@ public void Editor_InputEventsOccurringWhileGoingIntoPlayMode_AreDiscarded()
22102210
Assert.That(runtime.m_EventCount, Is.EqualTo(0));
22112211
}
22122212

2213+
[Test]
2214+
[Category("Editor")]
2215+
public void Editor_LeavingPlayMode_DestroysAllActionStates()
2216+
{
2217+
InputSystem.AddDevice<Gamepad>();
2218+
2219+
// Enter play mode.
2220+
InputSystem.OnPlayModeChange(PlayModeStateChange.ExitingEditMode);
2221+
InputSystem.OnPlayModeChange(PlayModeStateChange.EnteredPlayMode);
2222+
2223+
var action = new InputAction(binding: "<Gamepad>/buttonSouth");
2224+
action.Enable();
2225+
2226+
Assert.That(InputActionState.s_GlobalList.length, Is.EqualTo(1));
2227+
Assert.That(InputSystem.s_Manager.m_StateChangeMonitors.Length, Is.GreaterThan(0));
2228+
Assert.That(InputSystem.s_Manager.m_StateChangeMonitors[0].count, Is.EqualTo(1));
2229+
2230+
// Exit play mode.
2231+
InputSystem.OnPlayModeChange(PlayModeStateChange.ExitingPlayMode);
2232+
InputSystem.OnPlayModeChange(PlayModeStateChange.EnteredEditMode);
2233+
2234+
Assert.That(InputActionState.s_GlobalList.length, Is.Zero);
2235+
Assert.That(InputSystem.s_Manager.m_StateChangeMonitors[0].listeners[0].control, Is.Null); // Won't get removed, just cleared.
2236+
}
2237+
22132238
////TODO: tests for InputAssetImporter; for this we need C# mocks to be able to cut us off from the actual asset DB
22142239
}
22152240
#endif // UNITY_EDITOR

0 commit comments

Comments
 (0)