Skip to content

Commit dc14c49

Browse files
author
Rene Damm
committed
MERGE: develop => stable.
2 parents 7320077 + 9ad20b8 commit dc14c49

File tree

239 files changed

+9756
-497
lines changed

Some content is hidden

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

239 files changed

+9756
-497
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Packages/com.unity.inputsystem/Documentation~/ApiDocs/**
2525
Packages/com.unity.inputsystem/.DS_Store
2626
Packages/com.unity.inputsystem/.npmrc
2727

28-
Packages/com.unity.package-manager-doctools/
2928
Packages/com.unity.package-manager-ui/
3029

3130
.Editor

Assets/Samples/EditorWindowDemo/.sample.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

Assets/Samples/EditorWindowDemo/Editor.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

Assets/Samples/EditorWindowDemo/Editor/EditorWindowDemo.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

Assets/Samples/EditorWindowDemo/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

Assets/Samples/GamepadMouseCursor/VirtualMouseInput.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using UnityEngine.InputSystem.LowLevel;
33
using UnityEngine.UI;
44

5+
////TODO: respect cursor lock mode
6+
57
////TODO: investigate how driving the HW cursor behaves when FPS drops low
68
//// (also, maybe we can add support where we turn the gamepad mouse on and off automatically based on whether the system mouse is used)
79

@@ -11,6 +13,8 @@
1113

1214
////TODO: make it work with PlayerInput such that it will automatically look up actions in the actual PlayerInput instance it is used with (based on the action IDs it has)
1315

16+
////REVIEW: should we default the SW cursor position to the center of the screen?
17+
1418
////REVIEW: consider this for inclusion directly in the input system
1519

1620
namespace UnityEngine.InputSystem.UI
@@ -439,7 +443,9 @@ private void UpdateMotion()
439443
InputState.Change(m_VirtualMouse.delta, delta);
440444

441445
// Update software cursor transform, if any.
442-
if (m_CursorTransform != null && m_CursorMode == CursorMode.SoftwareCursor)
446+
if (m_CursorTransform != null &&
447+
(m_CursorMode == CursorMode.SoftwareCursor ||
448+
(m_CursorMode == CursorMode.HardwareCursorIfAvailable && m_SystemMouse == null)))
443449
m_CursorTransform.anchoredPosition = newPosition;
444450

445451
m_LastStickValue = stickValue;

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,27 @@ public void Actions_CanAddBindingsToActions()
24352435
Assert.That(action.controls, Has.Exactly(1).SameAs(gamepad.rightStick));
24362436
}
24372437

2438+
// Case 1218544
2439+
[Test]
2440+
[Category("Actions")]
2441+
public void Actions_CanAddBindingsToActions_AfterActionHasBeenEnabled()
2442+
{
2443+
var gamepad = InputSystem.AddDevice<Gamepad>();
2444+
var action = new InputAction(name: "test", binding: "<Gamepad>/leftStick");
2445+
action.Enable();
2446+
2447+
Assert.That(action.controls, Is.EquivalentTo(new[] { gamepad.leftStick }));
2448+
Assert.That(action.bindings, Has.Count.EqualTo(1));
2449+
Assert.That(action.bindings[0].effectivePath, Is.EqualTo("<Gamepad>/leftStick"));
2450+
2451+
action.AddBinding("<Gamepad>/rightStick");
2452+
2453+
Assert.That(action.controls, Is.EquivalentTo(new[] { gamepad.leftStick, gamepad.rightStick }));
2454+
Assert.That(action.bindings, Has.Count.EqualTo(2));
2455+
Assert.That(action.bindings[0].path, Is.EqualTo("<Gamepad>/leftStick"));
2456+
Assert.That(action.bindings[0].path, Is.EqualTo("<Gamepad>/leftStick"));
2457+
}
2458+
24382459
[Test]
24392460
[Category("Actions")]
24402461
public void Actions_BindingsHaveUniqueIDs()

Assets/Tests/InputSystem/CoreTests_Actions_Rebinding.cs

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -407,17 +407,25 @@ public void Actions_InteractiveRebinding_IgnoresNoisyControls()
407407
InputSystem.RegisterLayout(layout);
408408
var device = InputSystem.AddDevice("TestLayout");
409409

410-
using (var rebind = action.PerformInteractiveRebinding().OnMatchWaitForAnother(0).Start())
410+
using (var rebind = new InputActionRebindingExtensions.RebindingOperation()
411+
.WithAction(action)
412+
.OnMatchWaitForAnother(0)
413+
.Start())
411414
{
412415
Set((ButtonControl)device["noisyButton"], 0.678f);
413416

414417
Assert.That(rebind.completed, Is.False);
415418
Assert.That(action.bindings[0].overridePath, Is.Null);
416419

420+
Set((ButtonControl)device["noisyButton"], 0f);
421+
417422
// Can disable the behavior. This is most useful in combination with a custom
418423
// OnPotentialMatch() callback or when the selection-by-magnitude logic will do
419424
// a good enough job.
420-
rebind.WithoutIgnoringNoisyControls();
425+
rebind.Cancel();
426+
rebind
427+
.WithoutIgnoringNoisyControls()
428+
.Start();
421429

422430
Set((ButtonControl)device["noisyButton"], 0.789f);
423431

@@ -449,25 +457,23 @@ public void Actions_InteractiveRebinding_UsesSyntheticControlsOnlyWhenBestMatch(
449457
// a candidate as well as leftStick/x. However, leftStick/right is synthetic so X axis should
450458
// win. Note that if we set expectedControlType to "Button", leftStick/x will get ignored
451459
// and leftStick/left will get picked.
452-
InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(1, 0)});
453-
InputSystem.Update();
460+
Set(gamepad.leftStick, Vector2.right);
454461

455462
Assert.That(rebind.completed, Is.False);
456463
Assert.That(rebind.candidates, Is.EquivalentTo(new[] {gamepad.leftStick.x, gamepad.leftStick.right}));
457464
Assert.That(rebind.scores, Has.Count.EqualTo(2));
458465
Assert.That(rebind.scores[0], Is.GreaterThan(rebind.scores[1]));
459466

460467
// Reset.
461-
InputSystem.QueueStateEvent(gamepad, new GamepadState());
462-
InputSystem.Update();
463-
rebind.RemoveCandidate(gamepad.leftStick.x);
464-
rebind.RemoveCandidate(gamepad.leftStick.right);
468+
Set(gamepad.leftStick, Vector2.zero);
465469

466470
// Switch to looking only for buttons. leftStick/x will no longer be a suitable pick.
467-
rebind.WithExpectedControlType("Button");
471+
rebind.Cancel();
472+
rebind
473+
.WithExpectedControlType("Button")
474+
.Start();
468475

469-
InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(1, 0)});
470-
InputSystem.Update();
476+
Set(gamepad.leftStick, Vector2.right);
471477

472478
Assert.That(rebind.completed, Is.True);
473479
Assert.That(action.bindings[0].overridePath, Is.EqualTo("<Gamepad>/leftStick/right"));
@@ -572,33 +578,71 @@ public void Actions_InteractiveRebinding_RespectsExpectedControlLayoutIfSet()
572578
}
573579
}
574580

575-
// If a control is already actuated when we initiate a rebind, we first require it to go
576-
// back to its default value.
581+
// We want to be able to deal with controls that are already actuated when the rebinding starts and
582+
// also with controls that don't usually go back to default values at all.
583+
//
584+
// What we require is that when we detect sufficient actuation on a control in an event, we compare
585+
// it to the control's current actuation level when we first considered it. This is expected to work
586+
// regardless of whether we are suppressing events or not.
587+
//
588+
// https://fogbugz.unity3d.com/f/cases/1215784/
577589
[Test]
578590
[Category("Actions")]
579-
public void Actions_InteractiveRebinding_RequiresControlToBeActuatedStartingWithDefaultValue()
591+
public void Actions_InteractiveRebinding_WhenControlAlreadyActuated_HasToCrossMagnitudeThresholdFromCurrentActuation()
580592
{
581593
var action = new InputAction(binding: "<Gamepad>/buttonSouth");
582594
var gamepad = InputSystem.AddDevice<Gamepad>();
583595

584-
// Put buttonNorth in pressed state.
585-
InputSystem.QueueStateEvent(gamepad, new GamepadState().WithButton(GamepadButton.North));
586-
InputSystem.Update();
596+
// Actuate some controls.
597+
Press(gamepad.buttonNorth);
598+
Set(gamepad.leftTrigger, 0.75f);
587599

588-
using (var rebind = new InputActionRebindingExtensions.RebindingOperation().WithAction(action).Start())
600+
using (var rebind = new InputActionRebindingExtensions.RebindingOperation()
601+
.WithAction(action)
602+
.WithMagnitudeHavingToBeGreaterThan(0.25f)
603+
.Start())
589604
{
590-
// Reset buttonNorth to unpressed state.
591-
InputSystem.QueueStateEvent(gamepad, new GamepadState());
592-
InputSystem.Update();
605+
Release(gamepad.buttonNorth);
593606

594607
Assert.That(rebind.completed, Is.False);
608+
Assert.That(rebind.candidates, Is.Empty);
595609

596-
// Now press it again.
597-
InputSystem.QueueStateEvent(gamepad, new GamepadState().WithButton(GamepadButton.North));
598-
InputSystem.Update();
610+
Set(gamepad.leftTrigger, 0.9f);
611+
612+
Assert.That(rebind.completed, Is.False);
613+
Assert.That(rebind.candidates, Is.Empty);
614+
615+
Set(gamepad.leftTrigger, 0f);
616+
617+
Assert.That(rebind.completed, Is.False);
618+
Assert.That(rebind.candidates, Is.Empty);
619+
620+
Set(gamepad.leftTrigger, 0.7f);
599621

600622
Assert.That(rebind.completed, Is.True);
601-
Assert.That(action.bindings[0].overridePath, Is.EqualTo("<Gamepad>/buttonNorth"));
623+
Assert.That(action.bindings[0].overridePath, Is.EqualTo("<Gamepad>/leftTrigger"));
624+
}
625+
}
626+
627+
[Test]
628+
[Category("Actions")]
629+
public void Actions_InteractiveRebinding_CanGetActuationMagnitudeOfCandidateControls()
630+
{
631+
var action = new InputAction(binding: "<Gamepad>/buttonSouth");
632+
var gamepad = InputSystem.AddDevice<Gamepad>();
633+
634+
using (var rebind = new InputActionRebindingExtensions.RebindingOperation()
635+
.WithAction(action)
636+
.WithMagnitudeHavingToBeGreaterThan(0.25f)
637+
.OnMatchWaitForAnother(1)
638+
.Start())
639+
{
640+
Set(gamepad.leftTrigger, 0.75f);
641+
642+
Assert.That(rebind.candidates, Has.Count.EqualTo(1));
643+
Assert.That(rebind.magnitudes, Has.Count.EqualTo(rebind.candidates.Count));
644+
Assert.That(rebind.candidates[0], Is.SameAs(gamepad.leftTrigger));
645+
Assert.That(rebind.magnitudes[0], Is.EqualTo(0.75).Within(0.00001));
602646
}
603647
}
604648

@@ -801,14 +845,12 @@ public void Actions_InteractiveRebinding_CanSpecifyMagnitudeThreshold()
801845
.WithMagnitudeHavingToBeGreaterThan(0.5f)
802846
.Start())
803847
{
804-
InputSystem.QueueStateEvent(gamepad, new GamepadState {leftTrigger = 0.4f});
805-
InputSystem.Update();
848+
Set(gamepad.leftTrigger, 0.4f);
806849

807850
Assert.That(rebind.completed, Is.False);
808851
Assert.That(rebind.candidates, Is.Empty);
809852

810-
InputSystem.QueueStateEvent(gamepad, new GamepadState {leftTrigger = 0.6f});
811-
InputSystem.Update();
853+
Set(gamepad.leftTrigger, 0.6f);
812854

813855
Assert.That(rebind.completed, Is.True);
814856
Assert.That(action.bindings[0].overridePath, Is.EqualTo("<Gamepad>/leftTrigger"));

Assets/Tests/InputSystem/CoreTests_Devices.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,10 @@ public void Devices_CanGetAllDevices()
4040
var mouse = InputSystem.AddDevice<Mouse>();
4141

4242
Assert.That(InputSystem.devices, Is.EquivalentTo(new InputDevice[] { gamepad1, gamepad2, keyboard, mouse }));
43-
// Alternate getter.
44-
Assert.That(InputDevice.all, Is.EquivalentTo(new InputDevice[] { gamepad1, gamepad2, keyboard, mouse }));
4543

4644
InputSystem.RemoveDevice(keyboard);
4745

4846
Assert.That(InputSystem.devices, Is.EquivalentTo(new InputDevice[] { gamepad1, gamepad2, mouse }));
49-
Assert.That(InputDevice.all, Is.EquivalentTo(new InputDevice[] { gamepad1, gamepad2, mouse }));
5047
}
5148

5249
[Test]
@@ -1841,6 +1838,29 @@ public void Devices_CanQueryAllGamepadsWithSimpleGetter()
18411838
Assert.That(Gamepad.all, Has.None.SameAs(gamepad2));
18421839
}
18431840

1841+
[Test]
1842+
[Category("Devices")]
1843+
public void Devices_CanQueryAllJoysticksWithSimpleGetter()
1844+
{
1845+
var joystick1 = InputSystem.AddDevice<Joystick>();
1846+
var joystick2 = InputSystem.AddDevice<Joystick>();
1847+
InputSystem.AddDevice<Keyboard>();
1848+
1849+
Assert.That(Joystick.all, Has.Count.EqualTo(2));
1850+
Assert.That(Joystick.all, Has.Exactly(1).SameAs(joystick1));
1851+
Assert.That(Joystick.all, Has.Exactly(1).SameAs(joystick2));
1852+
1853+
var joystick3 = InputSystem.AddDevice<Joystick>();
1854+
1855+
Assert.That(Joystick.all, Has.Count.EqualTo(3));
1856+
Assert.That(Joystick.all, Has.Exactly(1).SameAs(joystick3));
1857+
1858+
InputSystem.RemoveDevice(joystick2);
1859+
1860+
Assert.That(Joystick.all, Has.Count.EqualTo(2));
1861+
Assert.That(Joystick.all, Has.None.SameAs(joystick2));
1862+
}
1863+
18441864
[Test]
18451865
[Category("Devices")]
18461866
public void Devices_CanGetButtonOnGamepadUsingEnum()
@@ -3265,6 +3285,7 @@ private struct TestDeviceCapabilities
32653285
public string stringCap;
32663286
public int intCap;
32673287
public float floatCap;
3288+
public float floatCapWithExponent;
32683289
public bool boolCap;
32693290
public NestedCaps nestedCap;
32703291
public string[] arrayCap;
@@ -3315,6 +3336,8 @@ public void Devices_CanMatchDeviceDescriptions_WithCapabilities()
33153336
.WithCapability("intCap", "1234");
33163337
var matchFloatCapWithString = new InputDeviceMatcher()
33173338
.WithCapability("floatCap", "1.234");
3339+
var matchFloatWithExponentCapWithString = new InputDeviceMatcher()
3340+
.WithCapability("floatCapWithExponent", "1.234e-10");
33183341
var matchBoolCapWithString = new InputDeviceMatcher()
33193342
.WithCapability("boolCap", "true");
33203343
var matchNone = new InputDeviceMatcher()
@@ -3328,6 +3351,7 @@ public void Devices_CanMatchDeviceDescriptions_WithCapabilities()
33283351
stringCap = "string",
33293352
intCap = 1234,
33303353
floatCap = 1.234f,
3354+
floatCapWithExponent = 1.234e-10f,
33313355
boolCap = true,
33323356
nestedCap = new TestDeviceCapabilities.NestedCaps
33333357
{
@@ -3348,6 +3372,7 @@ public void Devices_CanMatchDeviceDescriptions_WithCapabilities()
33483372
Assert.That(matchIntCapWithRegex.MatchPercentage(description), Is.EqualTo(1 / 2.0).Within(0.0001));
33493373
Assert.That(matchIntCapWithString.MatchPercentage(description), Is.EqualTo(1 / 2.0).Within(0.0001));
33503374
Assert.That(matchFloatCapWithString.MatchPercentage(description), Is.EqualTo(1 / 2.0).Within(0.0001));
3375+
Assert.That(matchFloatWithExponentCapWithString.MatchPercentage(description), Is.EqualTo(1 / 2.0).Within(0.0001));
33513376
Assert.That(matchBoolCapWithString.MatchPercentage(description), Is.EqualTo(1 / 2.0).Within(0.0001));
33523377
Assert.That(matchNone.MatchPercentage(description), Is.EqualTo(0).Within(0.0001));
33533378
}

0 commit comments

Comments
 (0)