Skip to content

Commit 3c10099

Browse files
FIX: Allow InputSystem class to set runtime runInBackground field (#1662)
* Allow InputSystem class to set runtime runInBackground field * Exclude new public property from public documentation * Update changelog
1 parent 16bbcb5 commit 3c10099

5 files changed

Lines changed: 33 additions & 6 deletions

File tree

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ however, it has to be formatted properly to pass verification tests.
1212

1313
### Added
1414
- Added `InputSystem.customBindingPathValidators` interface to allow showing warnings in the `InputAsset` Editor for specific InputBindings and draw custom UI in the properties panel.
15+
- Added `InputSystem.runInBackground` to be used internally by specific platforms packages. Allows telling the input system that a specific platform runs in background. It allows fixing of [case UUM-6744](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-6744).
1516

1617
## [1.5.1] - 2023-03-15
1718

Packages/com.unity.inputsystem/Documentation~/filter.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ apiRules:
3737
- exclude:
3838
uidRegex: ^UnityEngine\.InputSystem\.Samples\..*$
3939
type: Namespace
40+
- exclude:
41+
uidRegex: ^UnityEngine\.InputSystem\.InputSystem\.runInBackground$
42+
type: Member

Packages/com.unity.inputsystem/InputSystem/IInputRuntime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ internal unsafe interface IInputRuntime
170170
/// </summary>
171171
double currentTimeOffsetToRealtimeSinceStartup { get; }
172172

173-
bool runInBackground { get; }
173+
bool runInBackground { get; set; }
174174

175175
Vector2 screenSize { get; }
176176
ScreenOrientation screenOrientation { get; }

Packages/com.unity.inputsystem/InputSystem/InputSystem.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics.CodeAnalysis;
4+
using System.Runtime.CompilerServices;
45
using UnityEngine.InputSystem.Haptics;
56
using Unity.Collections.LowLevel.Unsafe;
67
using UnityEngine.InputSystem.Controls;
@@ -74,10 +75,12 @@ namespace UnityEngine.InputSystem
7475
/// be called on the main thread. However, select APIs like <see cref="QueueEvent"/> can be
7576
/// called from threads. Where this is the case, it is stated in the documentation.
7677
/// </remarks>
78+
7779
[SuppressMessage("Microsoft.Naming", "CA1724:TypeNamesShouldNotMatchNamespaces", Justification = "Options for namespaces are limited due to the legacy input class. Agreed on this as the least bad solution.")]
7880
#if UNITY_EDITOR
7981
[InitializeOnLoad]
8082
#endif
83+
8184
public static partial class InputSystem
8285
{
8386
#region Layouts
@@ -3279,6 +3282,20 @@ public static int ListEnabledActions(List<InputAction> actions)
32793282
/// <value>Current version of the input system.</value>
32803283
public static Version version => new Version(kAssemblyVersion);
32813284

3285+
/// <summary>
3286+
/// Property for internal use that allows setting the player to run in the background.
3287+
/// </summary>
3288+
/// <remarks>
3289+
/// Some platforms don't care about <see cref="Application.runInBackground"/> and for those we need to
3290+
/// enable it manually through this propriety.
3291+
/// </remarks>
3292+
/// <param name="value">The boolean value to set to <see cref="NativeInputRuntime.runInBackground"/></param>
3293+
public static bool runInBackground
3294+
{
3295+
get => s_Manager.m_Runtime.runInBackground;
3296+
set => s_Manager.m_Runtime.runInBackground = value;
3297+
}
3298+
32823299
////REVIEW: restrict metrics to editor and development builds?
32833300
/// <summary>
32843301
/// Get various up-to-date metrics about the input system.

Packages/com.unity.inputsystem/InputSystem/NativeInputRuntime.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,17 @@ public float pollingFrequency
227227
public double currentTimeOffsetToRealtimeSinceStartup => NativeInputSystem.currentTimeOffsetToRealtimeSinceStartup;
228228
public float unscaledGameTime => Time.unscaledTime;
229229

230-
public bool runInBackground => Application.runInBackground ||
231-
// certain platforms ignore the runInBackground flag and always run. Make sure we're
232-
// not running on one of those.
233-
// TODO: Add more platforms here as they're discovered.
234-
Application.platform == RuntimePlatform.PS5;
230+
public bool runInBackground
231+
{
232+
get =>
233+
Application.runInBackground ||
234+
// certain platforms ignore the runInBackground flag and always run. Make sure we're
235+
// not running on one of those and set the values when running on specific platforms.
236+
m_RunInBackground;
237+
set => m_RunInBackground = value;
238+
}
239+
240+
bool m_RunInBackground;
235241

236242
private Action m_ShutdownMethod;
237243
private InputUpdateDelegate m_OnUpdate;

0 commit comments

Comments
 (0)