Skip to content

Commit bef9515

Browse files
committed
Address InputSystem refactor PR feedback
- Rename some variables - Add update some comments - Other small tweaks.
1 parent bc2d23e commit bef9515

File tree

5 files changed

+58
-33
lines changed

5 files changed

+58
-33
lines changed

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -2782,7 +2782,7 @@ internal static DeferBindingResolutionContext DeferBindingResolution()
27822782
}
27832783
}
27842784

2785-
internal class DeferBindingResolutionContext : IDisposable
2785+
internal sealed class DeferBindingResolutionContext : IDisposable
27862786
{
27872787
public int deferredCount => m_DeferredCount;
27882788

@@ -2793,14 +2793,13 @@ public void Acquire()
27932793

27942794
public void Release()
27952795
{
2796-
if (m_DeferredCount > 0)
2797-
--m_DeferredCount;
2798-
if (m_DeferredCount == 0)
2796+
if (m_DeferredCount > 0 && --m_DeferredCount == 0)
27992797
ExecuteDeferredResolutionOfBindings();
28002798
}
28012799

28022800
/// <summary>
2803-
/// Allows usage within using() blocks.
2801+
/// Allows usage within using() blocks, i.e. we need a "Release" method to match "Acquire", but we also want
2802+
/// to implement IDisposable so instance are automatically cleaned up when exiting a using() block.
28042803
/// </summary>
28052804
public void Dispose()
28062805
{

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

+15-14
Original file line numberDiff line numberDiff line change
@@ -61,38 +61,39 @@ internal partial class InputManager : IDisposable
6161
{
6262
private InputManager() { }
6363

64-
public static InputManager CreateAndInitialize(IInputRuntime runtime, InputSettings settings, bool fakeRemove = false)
64+
public static InputManager CreateAndInitialize(IInputRuntime runtime, InputSettings settings, bool fakeManagerForRemotingTests = false)
6565
{
66-
var newInst = new InputManager();
66+
var newInstance = new InputManager();
6767

6868
// Not directly used by InputManager, but we need a single instance that's used in a variety of places without a static field
69-
newInst.m_DeferBindingResolutionContext = new DeferBindingResolutionContext();
69+
newInstance.m_DeferBindingResolutionContext = new DeferBindingResolutionContext();
7070

7171
// If settings object wasn't provided, create a temporary settings object for now
7272
if (settings == null)
7373
{
7474
settings = ScriptableObject.CreateInstance<InputSettings>();
7575
settings.hideFlags = HideFlags.HideAndDontSave;
7676
}
77-
newInst.m_Settings = settings;
77+
newInstance.m_Settings = settings;
7878

7979
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
80-
newInst.InitializeActions();
80+
newInstance.InitializeActions();
8181
#endif // UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
8282

83-
newInst.InitializeData();
84-
newInst.InstallRuntime(runtime);
83+
newInstance.InitializeData();
84+
newInstance.InstallRuntime(runtime);
8585

86-
// Skip if initializing for "Fake Remove" manager (in tests)
87-
if (!fakeRemove)
88-
newInst.InstallGlobals();
86+
// For remoting tests, we need to create a "fake manager" that simulates a remote endpoint.
87+
// In this case don't install globals as this will corrupt the "local" manager state.
88+
if (!fakeManagerForRemotingTests)
89+
newInstance.InstallGlobals();
8990

90-
newInst.ApplySettings();
91+
newInstance.ApplySettings();
9192

9293
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
93-
newInst.ApplyActions();
94+
newInstance.ApplyActions();
9495
#endif
95-
return newInst;
96+
return newInstance;
9697
}
9798

9899
#region Dispose implementation
@@ -3985,7 +3986,7 @@ internal void RestoreStateWithoutDevices(SerializedState state)
39853986
if (state.settings == null)
39863987
{
39873988
state.settings = ScriptableObject.CreateInstance<InputSettings>();
3988-
state.settings.hideFlags = HideFlags.HideAndDontSave;
3989+
state.settings.hideFlags = HideFlags.HideAndDontSave; // Hide from the project Hierarchy and Scene
39893990
}
39903991

39913992
if (m_Settings != null && m_Settings != state.settings)

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

+9-12
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static InputSystem()
8989

9090
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
9191
private static void RuntimeInitialize()
92-
{
92+
{
9393
GlobalInitialize(false);
9494
}
9595

@@ -3483,12 +3483,9 @@ private static void SetUpRemotingInternal()
34833483
private static bool ShouldEnableRemoting()
34843484
{
34853485
#if UNITY_INCLUDE_TESTS
3486-
var isRunningTests = true;
3487-
#else
3488-
var isRunningTests = false;
3486+
return false; // Don't remote while running tests.
34893487
#endif
3490-
if (isRunningTests)
3491-
return false; // Don't remote while running tests.
3488+
34923489
return true;
34933490
}
34943491
#endif //!UNITY_EDITOR
@@ -3517,7 +3514,7 @@ private static void GlobalInitialize(bool calledFromCtor)
35173514
// must initialize via the Runtime call.
35183515

35193516
if (calledFromCtor || IsDomainReloadDisabledForPlayMode())
3520-
{
3517+
{
35213518
InitializeInEditor(calledFromCtor);
35223519
}
35233520
#else
@@ -3544,7 +3541,7 @@ internal static void EnsureInitialized()
35443541

35453542
#if UNITY_EDITOR
35463543

3547-
// TODO: ISX-1860
3544+
// ISX-1860 - #ifdef out Domain Reload specific functionality from CoreCLR
35483545
private static InputSystemStateManager s_DomainStateManager;
35493546
internal static InputSystemStateManager domainStateManager => s_DomainStateManager;
35503547

@@ -3573,8 +3570,8 @@ internal static void InitializeInEditor(bool calledFromCtor, IInputRuntime runti
35733570
#endif
35743571
}
35753572

3576-
var existingSystemObjects = Resources.FindObjectsOfTypeAll<InputSystemStateManager>();
3577-
if (existingSystemObjects != null && existingSystemObjects.Length > 0)
3573+
var existingSystemStateManagers = Resources.FindObjectsOfTypeAll<InputSystemStateManager>();
3574+
if (existingSystemStateManagers != null && existingSystemStateManagers.Length > 0)
35783575
{
35793576
if (globalReset)
35803577
{
@@ -3584,7 +3581,7 @@ internal static void InitializeInEditor(bool calledFromCtor, IInputRuntime runti
35843581
// InputManager state here but we're still waiting from layout registrations
35853582
// that happen during domain initialization.
35863583

3587-
s_DomainStateManager = existingSystemObjects[0];
3584+
s_DomainStateManager = existingSystemStateManagers[0];
35883585
s_Manager.RestoreStateWithoutDevices(s_DomainStateManager.systemState.managerState);
35893586
InputDebuggerWindow.ReviveAfterDomainReload();
35903587

@@ -3765,7 +3762,7 @@ internal static void InitializeInPlayer(IInputRuntime runtime, bool loadSettings
37653762

37663763
#if UNITY_INCLUDE_TESTS
37673764
//
3768-
// We cannot define UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONSw with the Test-Framework assembly, and
3765+
// We cannot define UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS within the Test-Framework assembly, and
37693766
// so this hook is needed; it's called from InputTestStateManager.Reset().
37703767
//
37713768
internal static void TestHook_DisableActions()

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

+29-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal struct InputSystemState
3333
[NonSerialized] public ISavedState inputUserState;
3434
}
3535

36-
// TODO: ISX-1860
36+
// ISX-1860 - #ifdef out Domain Reload specific functionality from CoreCLR
3737
#if UNITY_EDITOR
3838
/// <summary>
3939
/// A hidden, internal object we put in the editor to bundle input system state
@@ -45,10 +45,38 @@ internal struct InputSystemState
4545
/// </remarks>
4646
internal class InputSystemStateManager : ScriptableObject, ISerializationCallbackReceiver
4747
{
48+
/// <summary>
49+
/// References the "core" input state that must survive domain reloads.
50+
/// </summary>
4851
[SerializeField] public InputSystemState systemState;
52+
53+
/// <summary>
54+
/// Triggers Editor restart when enabling NewInput back-ends.
55+
/// </summary>
4956
[SerializeField] public bool newInputBackendsCheckedAsEnabled;
57+
58+
/// <summary>
59+
/// Saves and restores InputSettings across domain reloads
60+
/// </summary>
61+
/// <remarks>
62+
/// InputSettings are serialized to JSON which this string holds.
63+
/// </remarks>
5064
[SerializeField] public string settings;
65+
66+
/// <summary>
67+
/// Timestamp retrieved from InputRuntime.currentTime when exiting EditMode.
68+
/// </summary>
69+
/// <remarks>
70+
/// All input events occurring between exiting EditMode and entering PlayMode are discarded.
71+
/// </remarks>
5172
[SerializeField] public double exitEditModeTime;
73+
74+
/// <summary>
75+
/// Timestamp retrieved from InputRuntime.currentTime when entering PlayMode.
76+
/// </summary>
77+
/// <remarks>
78+
/// All input events occurring between exiting EditMode and entering PlayMode are discarded.
79+
/// </remarks>
5280
[SerializeField] public double enterPlayModeTime;
5381

5482
public void OnBeforeSerialize()

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ internal struct GlobalState
12091209
private static void InitializeGlobalPlayerState()
12101210
{
12111211
// Touch GlobalState doesn't require Dispose operations
1212-
s_GlobalState = new GlobalState
1212+
s_GlobalState = new PlayerInput.GlobalState
12131213
{
12141214
initPlayerIndex = -1,
12151215
initSplitScreenIndex = -1

0 commit comments

Comments
 (0)