Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Assets/Tests/InputSystem/CoreTests_Devices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4550,6 +4550,13 @@ void DeviceChangeCallback(InputDevice device, InputDeviceChange change)
Assert.That(gamepad.canRunInBackground, Is.True);
Assert.That(joystick.canRunInBackground, Is.True);
Assert.That(keyboard.canRunInBackground, Is.False);
#if UNITY_EDITOR
Assert.That(trackedDevice.canDeviceRunInBackground, Is.True);
Assert.That(mouse.canDeviceRunInBackground, Is.True);
Assert.That(gamepad.canDeviceRunInBackground, Is.True);
Assert.That(joystick.canDeviceRunInBackground, Is.True);
Assert.That(keyboard.canDeviceRunInBackground, Is.True);
#endif
break;

case InputSettings.EditorInputBehaviorInPlayMode.AllDevicesRespectGameViewFocus:
Expand All @@ -4558,6 +4565,13 @@ void DeviceChangeCallback(InputDevice device, InputDeviceChange change)
Assert.That(gamepad.canRunInBackground, Is.False);
Assert.That(joystick.canRunInBackground, Is.False);
Assert.That(keyboard.canRunInBackground, Is.False);
#if UNITY_EDITOR
Assert.That(trackedDevice.canDeviceRunInBackground, Is.True);
Assert.That(mouse.canDeviceRunInBackground, Is.True);
Assert.That(gamepad.canDeviceRunInBackground, Is.True);
Assert.That(joystick.canDeviceRunInBackground, Is.True);
Assert.That(keyboard.canDeviceRunInBackground, Is.True);
#endif
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ however, it has to be formatted properly to pass verification tests.
- Renamed editor Resources directories to PackageResources to fix package validation warnings.
- Changed representation of GamepadButton enum values in Inspector to display aliased enum values as a single item to avoid confusion around selection and aliased value display when multiple enum items map to the same numerical value. [ISXB-543](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-543)
- PlayerInput component now warns if the system cannot find matching control scheme, which can occur if all control schemes already paired (e.g. to other game objects with PlayerInput components) [ISXB-1020](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1020)
### Added
- Added the display of the device flag CanRunInBackground in device debug view.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Code format CanRunInBackground


## [1.11.0] - 2024-09-10

Expand Down
17 changes: 15 additions & 2 deletions Packages/com.unity.inputsystem/InputSystem/Devices/InputDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,27 @@ public bool canRunInBackground
// In the editor, "background" refers to "game view not focused", not to the editor not being active.
// So, we modulate canRunInBackground depending on how input should behave WRT game view according
// to the input settings.
#if UNITY_EDITOR
#if UNITY_EDITOR
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I find this multi function spanning #if a bit hard to parse. Would love it if this could be simplified.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. From a readability perspective, it's not great. Can this be improved @bmalrat ?

var gameViewFocus = InputSystem.settings.editorInputBehaviorInPlayMode;
if (gameViewFocus == InputSettings.EditorInputBehaviorInPlayMode.AllDevicesRespectGameViewFocus)
return false; // No device considered being able to run without game view focus.
if (gameViewFocus == InputSettings.EditorInputBehaviorInPlayMode.PointersAndKeyboardsRespectGameViewFocus)
return !(this is Pointer || this is Keyboard); // Anything but pointers and keyboards considered as being able to run in background.
#endif


return canDeviceRunInBackground;
}
}
/// <summary>
/// In editor, it may differ from canRunInBackground depending on the gameViewFocus setting.
/// This property is used by Device Debug View
/// </summary>
/// <value>Whether the device should generate input while in the background.</value>
internal bool canDeviceRunInBackground
{
get
{
#endif
if ((m_DeviceFlags & DeviceFlags.CanRunInBackgroundHasBeenQueried) != 0)
return (m_DeviceFlags & DeviceFlags.CanRunInBackground) != 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ private void UpdateDeviceFlags()
flags.Add("DisabledInRuntime");
if (m_Device.disabledWhileInBackground)
flags.Add("DisabledWhileInBackground");
if (m_Device.canDeviceRunInBackground)
flags.Add("CanRunInBackground");
m_DeviceFlags = m_Device.m_DeviceFlags;
m_DeviceFlagsString = string.Join(", ", flags.ToArray());
}
Expand Down
16 changes: 1 addition & 15 deletions Packages/com.unity.inputsystem/InputSystem/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2893,22 +2893,8 @@ internal void AddAvailableDevicesThatAreNowRecognized()

private bool ShouldRunDeviceInBackground(InputDevice device)
{
var runDeviceInBackground =
m_Settings.backgroundBehavior != InputSettings.BackgroundBehavior.ResetAndDisableAllDevices &&
return m_Settings.backgroundBehavior != InputSettings.BackgroundBehavior.ResetAndDisableAllDevices &&
device.canRunInBackground;

// In editor, we may override canRunInBackground depending on the gameViewFocus setting.
#if UNITY_EDITOR
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is already done in canRunInBackground

if (runDeviceInBackground)
{
if (m_Settings.editorInputBehaviorInPlayMode == InputSettings.EditorInputBehaviorInPlayMode.AllDevicesRespectGameViewFocus)
runDeviceInBackground = false;
else if (m_Settings.editorInputBehaviorInPlayMode == InputSettings.EditorInputBehaviorInPlayMode.PointersAndKeyboardsRespectGameViewFocus)
runDeviceInBackground = !(device is Pointer || device is Keyboard);
}
#endif

return runDeviceInBackground;
}

internal void OnFocusChanged(bool focus)
Expand Down