Skip to content

Commit

Permalink
Merge branch 'develop' into ekcoh/profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ekcoh authored Nov 6, 2024
2 parents a3f8272 + 12ee89a commit 4046fad
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .yamato/config.metadata
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
editors:
- version: 2021.3
- version: 2021.3.45f
- version: 2022.3
disable_tvos_run: true
- version: 6000.0
Expand Down
95 changes: 0 additions & 95 deletions Assets/Tests/InputSystem/CoreTests_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12405,99 +12405,4 @@ public void Actions_ActionMapDisabledDuringOnAfterSerialization()
Assert.That(map.enabled, Is.True);
Assert.That(map.FindAction("MyAction", true).enabled, Is.True);
}

// ResetDevice wasn't properly clearly Composite key state, i.e. BindingState.pressTime
// https://jira.unity3d.com/browse/ISXB-746
[Test]
[TestCase(false)]
[TestCase(true)]
[Category("Actions")]
public void Actions_CompositeBindingResetWhenResetDeviceCalledWhileExecutingAction(bool useTwoModifierComposite)
{
var keyboard = InputSystem.AddDevice<Keyboard>();
bool actionPerformed;

// Enables "Modifier must be pressed first" behavior on all Composite Bindings
InputSystem.settings.shortcutKeysConsumeInput = true;

const string modifier1 = "<Keyboard>/shift";
const string modifier2 = "<Keyboard>/ctrl";
const string key = "<Keyboard>/F1";

var map = new InputActionMap();
var resetAction = map.AddAction("resetAction");

if (!useTwoModifierComposite)
{
resetAction.AddCompositeBinding("OneModifier")
.With("Modifier", modifier1)
.With("Binding", key);
}
else
{
resetAction.AddCompositeBinding("TwoModifiers")
.With("Modifier1", modifier1)
.With("Modifier2", modifier2)
.With("Binding", key);
}

resetAction.performed += (InputAction.CallbackContext ctx) =>
{
// Disable the Keyboard while action is being performed.
// This simulates an "OnFocusLost" event occurring while processing the Action, e.g. when switching primary displays or moving the main window
actionPerformed = true;
InputSystem.s_Manager.EnableOrDisableDevice(keyboard.device, false, InputManager.DeviceDisableScope.TemporaryWhilePlayerIsInBackground);
};

map.Enable();

actionPerformed = false;
Press(keyboard.leftShiftKey);
Press(keyboard.leftCtrlKey);
Press(keyboard.f1Key);

Assert.IsTrue(actionPerformed);

// Re enable the Keyboard (before keys are released) and execute Action again
InputSystem.s_Manager.EnableOrDisableDevice(keyboard.device, true, InputManager.DeviceDisableScope.TemporaryWhilePlayerIsInBackground);

actionPerformed = false;
Release(keyboard.leftShiftKey);
Release(keyboard.leftCtrlKey);
Release(keyboard.f1Key);

Press(keyboard.leftCtrlKey);
Press(keyboard.leftShiftKey);
Press(keyboard.f1Key);

Assert.IsTrue(actionPerformed);

actionPerformed = false;
Release(keyboard.leftCtrlKey);
Release(keyboard.leftShiftKey);
Release(keyboard.f1Key);

// Re enable the Keyboard (after keys are released) and execute Action one more time
InputSystem.s_Manager.EnableOrDisableDevice(keyboard.device, true, InputManager.DeviceDisableScope.TemporaryWhilePlayerIsInBackground);

Press(keyboard.leftCtrlKey);
Press(keyboard.leftShiftKey);
Press(keyboard.f1Key);

Assert.IsTrue(actionPerformed);

actionPerformed = false;
Press(keyboard.leftShiftKey);
Press(keyboard.leftCtrlKey);
Press(keyboard.f1Key);

// Re enable the Keyboard (before keys are released) and verify Action isn't triggered when Key pressed first
InputSystem.s_Manager.EnableOrDisableDevice(keyboard.device, true, InputManager.DeviceDisableScope.TemporaryWhilePlayerIsInBackground);

Press(keyboard.f1Key);
Press(keyboard.leftCtrlKey);
Press(keyboard.leftShiftKey);

Assert.IsFalse(actionPerformed);
}
}
27 changes: 27 additions & 0 deletions Assets/Tests/InputSystem/Plugins/OnScreenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,33 @@ public void Devices_DisablingLastOnScreenControlRemovesCreatedDevice()
Assert.That(InputSystem.devices, Has.None.InstanceOf<Keyboard>());
}

[Test]
[Category("Devices")]
public void Devices_DisablingLastOnScreenControlDoesReportActiveControl()
{
var gameObject = new GameObject();

Assert.That(OnScreenControl.HasAnyActive, Is.False);

var buttonA = gameObject.AddComponent<OnScreenButton>();

Assert.That(OnScreenControl.HasAnyActive, Is.True);

var buttonB = gameObject.AddComponent<OnScreenButton>();
buttonA.controlPath = "/<Keyboard>/a";
buttonB.controlPath = "/<Keyboard>/b";

Assert.That(OnScreenControl.HasAnyActive, Is.True);

buttonA.enabled = false;

Assert.That(OnScreenControl.HasAnyActive, Is.True);

buttonB.enabled = false;

Assert.That(OnScreenControl.HasAnyActive, Is.False);
}

// https://fogbugz.unity3d.com/f/cases/1271942
[UnityTest]
[Category("Devices")]
Expand Down
53 changes: 53 additions & 0 deletions Assets/Tests/InputSystem/Plugins/PlayerInputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Object = UnityEngine.Object;
using Gyroscope = UnityEngine.InputSystem.Gyroscope;
using Is = UnityEngine.TestTools.Constraints.Is;
using UnityEngine.InputSystem.OnScreen;

/// <summary>
/// Tests for <see cref="PlayerInput"/> and <see cref="PlayerInputManager"/>.
Expand Down Expand Up @@ -663,6 +664,58 @@ public void PlayerInput_CanAutoSwitchControlSchemesInSinglePlayer()
}));
}

[Test]
[Category("PlayerInput")]
public void PlayerInput_AutoSwitchControlSchemesInSinglePlayerWithOnScreenControl_AutoSwitchToTargetDeviceAndIgnoreMouse()
{
var keyboard = InputSystem.AddDevice<Keyboard>();
var mouse = InputSystem.AddDevice<Mouse>();

var go = new GameObject();

var onScreenButton = go.AddComponent<OnScreenButton>();
onScreenButton.enabled = false;
onScreenButton.controlPath = "<Gamepad>/buttonSouth";

var playerInput = go.AddComponent<PlayerInput>();
playerInput.defaultControlScheme = "Keyboard&Mouse";
playerInput.defaultActionMap = "gameplay";
playerInput.actions = InputActionAsset.FromJson(kActions);

Assert.That(playerInput.devices, Is.EquivalentTo(new InputDevice[] { keyboard, mouse }));

// enable the OnScreenButton, it should switch to Gamepad
onScreenButton.enabled = true;
var gamepad = onScreenButton.control.device;
Assert.That(gamepad, Is.TypeOf<Gamepad>());
Assert.That(playerInput.devices, Is.EquivalentTo(new InputDevice[] { gamepad }));
Assert.That(playerInput.user.controlScheme, Is.Not.Null);
Assert.That(playerInput.user.controlScheme.Value.name, Is.EqualTo("Gamepad"));

// Perform mouse move and click. to try to switch to Keyboard&Mouse scheme
Move(mouse.position, new Vector2(0.123f, 0.234f));
Click(mouse.leftButton);
Move(mouse.position, new Vector2(100f, 100f));
InputSystem.Update();

// The controlScheme shouldn't have changed
Assert.That(playerInput.devices, Is.EquivalentTo(new[] { gamepad }));
Assert.That(playerInput.user.controlScheme, Is.Not.Null);
Assert.That(playerInput.user.controlScheme.Value.name, Is.EqualTo("Gamepad"));

// disabling the OnScreenButton to ensure that it will now switch to Keyboard&Mouse as expected
onScreenButton.enabled = false;

// Perform mouse move and click. to try to switch to Keyboard&Mouse scheme
Move(mouse.position, new Vector2(0.123f, 0.234f));
Click(mouse.leftButton);
Move(mouse.position, new Vector2(100f, 100f));

Assert.That(playerInput.devices, Is.EquivalentTo(new InputDevice[] { keyboard, mouse }));
Assert.That(playerInput.user.controlScheme, Is.Not.Null);
Assert.That(playerInput.user.controlScheme.Value.name, Is.EqualTo("Keyboard&Mouse"));
}

[Test]
[Category("PlayerInput")]
public void PlayerInput_CanAutoSwitchControlSchemesInSinglePlayer_WithSomeDevicesSharedBetweenSchemes()
Expand Down
5 changes: 5 additions & 0 deletions Assets/Tests/InputSystem/Plugins/UITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2630,6 +2630,11 @@ public void UI_ClickDraggingMouseDoesNotAllocateGCMemory()
Release(mouse.leftButton);
scene.eventSystem.InvokeUpdate();

#if UNITY_2023_2_OR_NEWER // UnityEngine.InputForUI Module unavailable in earlier releases
// Process all queued UI events to ensure that next events will not make the events list capacity growing
UnityEngine.InputForUI.EventProvider.NotifyUpdate();
#endif

var kProfilerRegion = "UI_ClickDraggingDoesNotAllocateGCMemory";

// Now for real.
Expand Down
10 changes: 7 additions & 3 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ however, it has to be formatted properly to pass verification tests.

### Fixed
- Fixed an issue causing the Action context menu to not show on right click when right clicking an action in the Input Action Editor [ISXB-1134](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1134).
- Reverted changes from 0ddd534d8 (ISXB-746) which introduced a regression [ISXB-1127](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1127).
- Fixed `ArgumentNullException: Value cannot be null.` during the migration of Project-wide Input Actions from `InputManager.asset` to `InputSystem_Actions.inputactions` asset which lead do the lost of the configuration [ISXB-1105](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1105)
- Fixed pointerId staying the same when simultaneously releasing and then pressing in the same frame on mobile using touch. [ISXB-1006](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-845)
- Fixed ISubmitHandler.OnSubmit event processing when operating in Manual Update mode (ISXB-1141)
- Fixed Rename mode is not entered and name is autocompleted to default when creating a new Action Map on 2022.3. [ISXB-1151](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1151)
- Fixed unexpected control scheme switch when using `OnScreenControl` and pointer based schemes which registed "Cancel" event on every frame.[ISXB-656](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-656)
- Fixed an issue with The "Add Control Scheme..." popup window so that it now persists until any changes are explicitly Saved or Cancelled [case ISXB-1131](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1131)

### Changed
- Added back the InputManager to InputSystem project-wide asset migration code with performance improvement (ISX-2086)
- Changed `OnScreenControl` to automaticaly switch, in Single Player with autoswitch enabled, to the target device control scheme when the first component is enabled to prevent bad interactions when it start.

## [1.11.2] - 2024-10-16

Expand All @@ -27,14 +33,12 @@ however, it has to be formatted properly to pass verification tests.
- Fixed "AnalyticsResult" errors on consoles [ISXB-1107]
- Fixed wrong `Display Index` value for touchscreen events.[ISXB-1101](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1101)
- Fixed event handling when using Fixed Update processing where WasPressedThisFrame could appear to true for consecutive frames [ISXB-1006](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1006)
- Removed a redundant warning when using fallback code to parse a HID descriptor. (UUM-71260)

### Added
- Added the display of the device flag `CanRunInBackground` in device debug view.
- Added analytics for programmatic `InputAction` setup via `InputActionSetupExtensions` when exiting play-mode.

### Fixed
- Removed a redundant warning when using fallback code to parse a HID descriptor. (UUM-71260)

### Changed
- Removed the InputManager to InputSystem project-wide asset migration code for performance improvement (ISX-2086)

Expand Down
18 changes: 14 additions & 4 deletions Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,16 @@ public unsafe bool IsInProgress()
return false;
}

private int ExpectedFrame()
{
// Used by the Was<XXX>ThisFrame() methods below.
// When processing events manually the event processing will happen one frame later.
//
int frameOffset = InputSystem.settings.updateMode == InputSettings.UpdateMode.ProcessEventsManually ? 1 : 0;
int expectedFrame = Time.frameCount - frameOffset;
return expectedFrame;
}

/// <summary>
/// Returns true if the action's value crossed the press threshold (see <see cref="InputSettings.defaultButtonPressPoint"/>)
/// at any point in the frame.
Expand Down Expand Up @@ -1236,7 +1246,7 @@ public unsafe bool WasPressedThisFrame()
{
var actionStatePtr = &state.actionStates[m_ActionIndexInState];
var currentUpdateStep = InputUpdate.s_UpdateStepCount;
return actionStatePtr->pressedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == Time.frameCount;
return actionStatePtr->pressedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == ExpectedFrame();
}

return false;
Expand Down Expand Up @@ -1285,7 +1295,7 @@ public unsafe bool WasReleasedThisFrame()
{
var actionStatePtr = &state.actionStates[m_ActionIndexInState];
var currentUpdateStep = InputUpdate.s_UpdateStepCount;
return actionStatePtr->releasedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == Time.frameCount;
return actionStatePtr->releasedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == ExpectedFrame();
}

return false;
Expand Down Expand Up @@ -1344,7 +1354,7 @@ public unsafe bool WasPerformedThisFrame()
{
var actionStatePtr = &state.actionStates[m_ActionIndexInState];
var currentUpdateStep = InputUpdate.s_UpdateStepCount;
return actionStatePtr->lastPerformedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == Time.frameCount;
return actionStatePtr->lastPerformedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == ExpectedFrame();
}

return false;
Expand Down Expand Up @@ -1417,7 +1427,7 @@ public unsafe bool WasCompletedThisFrame()
{
var actionStatePtr = &state.actionStates[m_ActionIndexInState];
var currentUpdateStep = InputUpdate.s_UpdateStepCount;
return actionStatePtr->lastCompletedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == Time.frameCount;
return actionStatePtr->lastCompletedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == ExpectedFrame();
}

return false;
Expand Down
Loading

0 comments on commit 4046fad

Please sign in to comment.