Skip to content

Commit 33a398f

Browse files
committed
Split InitializeEditorHooks into registration helpers
1 parent 060f76b commit 33a398f

1 file changed

Lines changed: 65 additions & 31 deletions

File tree

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

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -250,59 +250,93 @@ internal static void InitializeInEditor(bool calledFromCtor, IInputRuntime runti
250250

251251
private static void InitializeEditorHooks()
252252
{
253-
InputSystem.s_OnActionsChanging = ValidateAndTrackActions;
253+
RegisterPlayModeHooks();
254+
RegisterAnalyticsHooks();
255+
RegisterAssetDatabaseHooks();
256+
#if UNITY_INPUT_SYSTEM_ENABLE_UI || PACKAGE_DOCS_GENERATION
257+
RegisterUIModuleHooks();
258+
#endif
259+
RegisterNativeInputRuntimeHooks();
260+
RegisterRemotingHooks();
261+
RegisterAssemblyReloadHooks();
262+
RegisterTestHooks();
263+
}
264+
265+
private static void RegisterPlayModeHooks()
266+
{
254267
InputSystem.s_ShouldEnableActions = ShouldEnableActions;
268+
InputSystem.s_OnPlayModeChangeCallback = change => OnPlayModeChange((PlayModeStateChange)change);
269+
InputSystem.s_OnProjectChangeCallback = OnProjectChange;
270+
InputSystem.s_IsDomainReloadDisabled = IsDomainReloadDisabledForPlayMode;
271+
InputSystem.s_EditorGlobalInitializeCallback = OnGlobalInitialize;
272+
273+
InputSystem.s_Manager.m_AddDevicesNotSupportedByProject = () => InputEditorUserSettings.addDevicesNotSupportedByProject;
274+
}
275+
276+
private static void RegisterAnalyticsHooks()
277+
{
255278
InputAnalytics.s_IsNewSystemBackendsEnabled = ShouldEnableActionsNewBackend;
256279
InputAnalytics.s_IsOldSystemBackendsEnabled = ShouldEnableActionsOldBackend;
257-
258280
InputActionSetupExtensions.s_ApiUsageCallback = RegisterSetupApiUsage;
259281
InputActionSetupExtensions.s_SuppressAnalytics = SuppressSetupAnalytics;
282+
}
260283

261-
#if UNITY_INPUT_SYSTEM_ENABLE_UI || PACKAGE_DOCS_GENERATION
262-
UnityEngine.InputSystem.UI.InputSystemUIInputModule.s_OnReset = OnUIInputModuleReset;
263-
#endif
264-
284+
private static void RegisterAssetDatabaseHooks()
285+
{
286+
InputSystem.s_OnActionsChanging = ValidateAndTrackActions;
265287
InputActionAsset.s_OnMarkAsDirty = DirtyAssetTracker.TrackDirtyInputActionAsset;
266288
InputManager.s_GetProjectWideActions = () => ProjectWideActionsBuildProvider.actionsToIncludeInPlayerBuild;
267-
InputSystem.s_Manager.m_AddDevicesNotSupportedByProject = () => InputEditorUserSettings.addDevicesNotSupportedByProject;
268289

269-
InputSystem.s_OnPlayModeChangeCallback = change => OnPlayModeChange((PlayModeStateChange)change);
270-
InputSystem.s_OnProjectChangeCallback = OnProjectChange;
290+
InputActionReference.s_IsSubAsset = AssetDatabase.IsSubAsset;
291+
InputActionReference.s_GetAssetPath = AssetDatabase.GetAssetPath;
292+
InputActionReference.s_LoadMainAssetAtPath = AssetDatabase.LoadMainAssetAtPath;
293+
}
271294

272-
InputSystem.s_IsDomainReloadDisabled = IsDomainReloadDisabledForPlayMode;
273-
InputSystem.s_EditorGlobalInitializeCallback = OnGlobalInitialize;
295+
#if UNITY_INPUT_SYSTEM_ENABLE_UI || PACKAGE_DOCS_GENERATION
296+
private static void RegisterUIModuleHooks()
297+
{
298+
UnityEngine.InputSystem.UI.InputSystemUIInputModule.s_OnReset = OnUIInputModuleReset;
299+
}
274300

275-
// Register test hook callbacks
276-
InputSystem.s_TestHookInitializeForPlayModeTests = TestHook_InitializeForPlayModeTests;
277-
#if !ENABLE_CORECLR
278-
InputSystem.s_TestHookSimulateDomainReload = TestHook_SimulateDomainReload;
279301
#endif
280-
InputSystem.s_TestHookEditorCleanup = TestHook_EditorCleanup;
281302

282-
if (InputRuntime.s_Instance is NativeInputRuntime nativeRuntime)
283-
{
284-
nativeRuntime.m_IsInPlayMode = () => EditorApplication.isPlaying;
285-
nativeRuntime.m_IsEditorPaused = () => EditorApplication.isPaused;
286-
nativeRuntime.m_IsEditorActive = () => InternalEditorUtility.isApplicationActive;
303+
private static void RegisterNativeInputRuntimeHooks()
304+
{
305+
if (InputRuntime.s_Instance is not NativeInputRuntime nativeRuntime)
306+
return;
287307

288-
nativeRuntime.m_RegisterWantsToQuit = RegisterWantsToQuit;
289-
nativeRuntime.m_UnregisterWantsToQuit = UnregisterWantsToQuit;
308+
nativeRuntime.m_IsInPlayMode = () => EditorApplication.isPlaying;
309+
nativeRuntime.m_IsEditorPaused = () => EditorApplication.isPaused;
310+
nativeRuntime.m_IsEditorActive = () => InternalEditorUtility.isApplicationActive;
290311

291-
nativeRuntime.m_SetUnityRemoteMessageHandler = SetUnityRemoteMessageHandler;
292-
nativeRuntime.m_SetUnityRemoteGyroEnabledCallback = SetUnityRemoteGyroEnabled;
293-
nativeRuntime.m_SetUnityRemoteGyroUpdateIntervalCallback = SetUnityRemoteGyroUpdateInterval;
312+
nativeRuntime.m_RegisterWantsToQuit = RegisterWantsToQuit;
313+
nativeRuntime.m_UnregisterWantsToQuit = UnregisterWantsToQuit;
294314

295-
nativeRuntime.m_SendEditorAnalytic = SendEditorAnalytic;
296-
}
315+
nativeRuntime.m_SetUnityRemoteMessageHandler = SetUnityRemoteMessageHandler;
316+
nativeRuntime.m_SetUnityRemoteGyroEnabledCallback = SetUnityRemoteGyroEnabled;
317+
nativeRuntime.m_SetUnityRemoteGyroUpdateIntervalCallback = SetUnityRemoteGyroUpdateInterval;
297318

319+
nativeRuntime.m_SendEditorAnalytic = SendEditorAnalytic;
320+
}
321+
322+
private static void RegisterRemotingHooks()
323+
{
298324
RemoteInputPlayerConnection.s_GetInstance = RemoteInputPlayerConnectionEditor.GetInstance;
325+
}
299326

327+
private static void RegisterAssemblyReloadHooks()
328+
{
300329
EnhancedTouch.EnhancedTouchSupport.s_BeforeAssemblyReloadCallback = RegisterBeforeAssemblyReload;
301330
EnhancedTouch.EnhancedTouchSupport.s_UnregisterBeforeAssemblyReloadCallback = UnregisterBeforeAssemblyReload;
331+
}
302332

303-
InputActionReference.s_IsSubAsset = AssetDatabase.IsSubAsset;
304-
InputActionReference.s_GetAssetPath = AssetDatabase.GetAssetPath;
305-
InputActionReference.s_LoadMainAssetAtPath = AssetDatabase.LoadMainAssetAtPath;
333+
private static void RegisterTestHooks()
334+
{
335+
InputSystem.s_TestHookInitializeForPlayModeTests = TestHook_InitializeForPlayModeTests;
336+
#if !ENABLE_CORECLR
337+
InputSystem.s_TestHookSimulateDomainReload = TestHook_SimulateDomainReload;
338+
#endif
339+
InputSystem.s_TestHookEditorCleanup = TestHook_EditorCleanup;
306340
}
307341

308342
private static void SetUpEditorRemoting()

0 commit comments

Comments
 (0)