Skip to content

Commit c5e8d47

Browse files
committed
Replace UpdateEditorState
This reverts something generated from an LLM which wasn't properly reviewed. And it fixes a regression preventing an application from receiving Input when using keyboard shortcut to enter play mode.
1 parent 9b95343 commit c5e8d47

3 files changed

Lines changed: 15 additions & 29 deletions

File tree

Packages/com.unity.inputsystem/Editor/InputSystemEditorInitializer.cs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,6 @@ private static void SendEditorAnalytic(InputAnalytics.IInputAnalytic analytic)
115115

116116
#endregion
117117

118-
private static void UpdateEditorState()
119-
{
120-
if (InputRuntime.s_Instance is NativeInputRuntime nativeRuntime)
121-
{
122-
nativeRuntime.m_IsInPlayMode = EditorApplication.isPlaying;
123-
nativeRuntime.m_IsEditorPaused = EditorApplication.isPaused;
124-
nativeRuntime.m_IsEditorActive = InternalEditorUtility.isApplicationActive;
125-
}
126-
127-
// Update Editor settings
128-
InputSystem.s_Manager.m_AddDevicesNotSupportedByProject = InputEditorUserSettings.addDevicesNotSupportedByProject;
129-
}
130-
131118
private static void RegisterSetupApiUsage(int api)
132119
{
133120
InputExitPlayModeAnalytic.Register((InputExitPlayModeAnalytic.Api)api);
@@ -195,8 +182,6 @@ internal static void InitializeInEditor(bool calledFromCtor, IInputRuntime runti
195182

196183
EditorApplication.playModeStateChanged += OnEditorPlayModeStateChanged;
197184
EditorApplication.projectChanged += OnEditorProjectChanged;
198-
//TODO EDITOR CODE SPLIT: this doesn't make sense, needs to be removed
199-
EditorApplication.update += UpdateEditorState;
200185

201186
InputSystem.s_Manager.runtime.onPlayModeChanged = InputSystem.OnPlayModeChange;
202187
InputSystem.s_Manager.runtime.onProjectChange = InputSystem.OnProjectChange;
@@ -278,12 +263,9 @@ private static void InitializeEditorHooks()
278263
UnityEngine.InputSystem.UI.InputSystemUIInputModule.s_OnReset = OnUIInputModuleReset;
279264
#endif
280265

281-
// TODO EDITOR CODE SPLIT: check this is correct
282-
UpdateEditorState();
283-
284266
InputActionAsset.s_OnMarkAsDirty = DirtyAssetTracker.TrackDirtyInputActionAsset;
285267
InputManager.s_GetProjectWideActions = () => ProjectWideActionsBuildProvider.actionsToIncludeInPlayerBuild;
286-
InputSystem.s_Manager.m_AddDevicesNotSupportedByProject = InputEditorUserSettings.addDevicesNotSupportedByProject;
268+
InputSystem.s_Manager.m_AddDevicesNotSupportedByProject = () => InputEditorUserSettings.addDevicesNotSupportedByProject;
287269

288270
InputSystem.s_OnPlayModeChangeCallback = change => OnPlayModeChange((PlayModeStateChange)change);
289271
InputSystem.s_OnProjectChangeCallback = OnProjectChange;
@@ -300,6 +282,10 @@ private static void InitializeEditorHooks()
300282

301283
if (InputRuntime.s_Instance is NativeInputRuntime nativeRuntime)
302284
{
285+
nativeRuntime.m_IsInPlayMode = () => EditorApplication.isPlaying;
286+
nativeRuntime.m_IsEditorPaused = () => EditorApplication.isPaused;
287+
nativeRuntime.m_IsEditorActive = () => InternalEditorUtility.isApplicationActive;
288+
303289
nativeRuntime.m_RegisterWantsToQuit = RegisterWantsToQuit;
304290
nativeRuntime.m_UnregisterWantsToQuit = UnregisterWantsToQuit;
305291

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ private bool IsDeviceLayoutMarkedAsSupportedInSettings(InternedString layoutName
11051105
// is useful to ensure that things like keyboard, mouse, and pen keep working in the editor
11061106
// even if not supported as devices in the game.
11071107
#if UNITY_EDITOR
1108-
if (m_AddDevicesNotSupportedByProject)
1108+
if (m_AddDevicesNotSupportedByProject?.Invoke() ?? false)
11091109
return true;
11101110
#endif
11111111

@@ -2328,7 +2328,7 @@ internal struct AvailableDevice
23282328
internal double m_EnterPlayModeTime;
23292329

23302330
// Editor settings (set by InputSystemEditorInitializer)
2331-
internal bool m_AddDevicesNotSupportedByProject;
2331+
internal Func<bool> m_AddDevicesNotSupportedByProject;
23322332

23332333
// Editor callback to get project-wide actions
23342334
internal static Func<InputActionAsset> s_GetProjectWideActions;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,14 @@ public float scrollWheelDeltaPerTick
335335

336336
#if UNITY_EDITOR
337337

338-
// These fields are set by InputSystemEditorInitializer to avoid direct Editor dependencies
339-
internal bool m_IsInPlayMode;
340-
internal bool m_IsEditorActive = true;
341-
internal bool m_IsEditorPaused;
342-
343-
public bool isInPlayMode => m_IsInPlayMode;
344-
public bool isEditorActive => m_IsEditorActive;
345-
public bool isEditorPaused => m_IsEditorPaused;
338+
// These delegates are set by InputSystemEditorInitializer to avoid direct Editor dependencies
339+
internal Func<bool> m_IsInPlayMode;
340+
internal Func<bool> m_IsEditorActive;
341+
internal Func<bool> m_IsEditorPaused;
342+
343+
public bool isInPlayMode => m_IsInPlayMode?.Invoke() ?? false;
344+
public bool isEditorActive => m_IsEditorActive?.Invoke() ?? true;
345+
public bool isEditorPaused => m_IsEditorPaused?.Invoke() ?? false;
346346

347347
// Unity Remote callbacks - set by Editor
348348
internal Action<Func<IntPtr, bool>> m_SetUnityRemoteMessageHandler;

0 commit comments

Comments
 (0)