diff --git a/Assets/Tests/InputSystem/APIVerificationTests.cs b/Assets/Tests/InputSystem/APIVerificationTests.cs index 502279c8da..03fd7e5275 100644 --- a/Assets/Tests/InputSystem/APIVerificationTests.cs +++ b/Assets/Tests/InputSystem/APIVerificationTests.cs @@ -243,12 +243,9 @@ public void API_MonoBehavioursHaveHelpUrls() var monoBehaviourTypes = typeof(InputSystem).Assembly.ExportedTypes.Where(t => t.IsPublic && !t.IsAbstract && !IgnoreTypeForDocsByName(t.FullName) && !IgnoreTypeForDocsByNamespace(t.Namespace) && typeof(MonoBehaviour).IsAssignableFrom(t)); - var monoBehaviourTypesHelpUrls = - monoBehaviourTypes.Where(t => t.GetCustomAttribute() != null) - .Select(t => t.GetCustomAttribute().URL); - var monoBehaviourTypesWithoutHelpUrls = - monoBehaviourTypes.Where(t => t.GetCustomAttribute() == null); + var monoBehaviourTypesHelpUrls = monoBehaviourTypes.Where(t => t.GetCustomAttributes().Any()).Select(t => t.GetCustomAttributes().First().URL); + var monoBehaviourTypesWithoutHelpUrls = monoBehaviourTypes.Where(t => !t.GetCustomAttributes().Any()); Assert.That(monoBehaviourTypesWithoutHelpUrls, Is.Empty); Assert.That(monoBehaviourTypesHelpUrls, Has.All.StartWith(InputSystem.kDocUrl)); } diff --git a/Assets/Tests/InputSystem/DocumentationBasedAPIVerficationTests.cs b/Assets/Tests/InputSystem/DocumentationBasedAPIVerficationTests.cs index 7c6c1cc9c9..1b0fb6f378 100644 --- a/Assets/Tests/InputSystem/DocumentationBasedAPIVerficationTests.cs +++ b/Assets/Tests/InputSystem/DocumentationBasedAPIVerficationTests.cs @@ -127,7 +127,7 @@ public void API_MonoBehaviourHelpUrlsAreValid() typeof(MonoBehaviour).IsAssignableFrom(t)); var monoBehaviourTypesWithHelpUrls = monoBehaviourTypes - .Where(t => t.GetCustomAttribute() != null); + .Where(t => t.GetCustomAttributes().Any()); var brokenHelpUrlErrors = new StringBuilder(); @@ -135,7 +135,8 @@ public void API_MonoBehaviourHelpUrlsAreValid() foreach (var monoBehaviorTypeWithHelpUrl in monoBehaviourTypesWithHelpUrls) { // Get url - var url = monoBehaviorTypeWithHelpUrl.GetCustomAttribute().URL; + var test = monoBehaviorTypeWithHelpUrl.GetCustomAttributes(); + var url = test.FirstOrDefault()?.URL; // Parse file path and anchor. var path = url.Substring(InputSystem.kDocUrl.Length); diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index c7360c52a6..374d6fd583 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed auto-save not working for Input System actions in Project Settings when both the Project Settings and Input System Actions windows were open [UUM-134035](https://jira.unity3d.com/browse/UUM-134035) - Improved New Input System warning dialog, Native Device Inputs Not Enabled [UUM-132151]. - Fixed caching for InputControlPath display name [ISX-2501](https://jira.unity3d.com/browse/ISX-2501) +- Fixed editor closing and not saving the input asset when clicking cancel in the dialog prompt [UUM-134748](https://jira.unity3d.com/browse/UUM-134748) ### Changed diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index 9039007cb1..3dbd534b67 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -24,6 +24,7 @@ static InputActionsEditorWindow() private string m_AssetJson; private bool m_IsDirty; + private bool m_IsEditorQuitting; private StateContainer m_StateContainer; private InputActionsEditorView m_View; @@ -333,11 +334,21 @@ private void DirtyInputActionsEditorWindow(InputActionsEditorState newState) private void OnEnable() { analytics.Begin(); + EditorApplication.wantsToQuit += OnWantsToQuit; } private void OnDisable() { analytics.End(); + EditorApplication.wantsToQuit -= OnWantsToQuit; + } + + private bool OnWantsToQuit() + { + // Here the user will be prompted + bool isAllowedToQuit = CheckCanCloseAndPromptIfDirty(false); + m_IsEditorQuitting = isAllowedToQuit; + return m_IsEditorQuitting; } private void OnFocus() @@ -362,16 +373,22 @@ private void OnLostFocus() analytics.RegisterEditorFocusOut(); } - private void HandleOnDestroy() + /// + /// Shows a dialog when trying to close an input asset without saving changes. + /// + /// If true, reopens the editor window when user cancels. + /// Returns true if you should allow the Unity Editor to close. + private bool CheckCanCloseAndPromptIfDirty(bool rebuildUIOnCancel) { // Do we have unsaved changes that we need to ask the user to save or discard? - if (!m_IsDirty) - return; + // Early out if asset up to date or editor closing. + if (!m_IsDirty || m_IsEditorQuitting) + return true; // Get target asset path from GUID, if this fails file no longer exists and we need to abort. var assetPath = AssetDatabase.GUIDToAssetPath(m_AssetGUID); if (string.IsNullOrEmpty(assetPath)) - return; + return true; // Prompt user with a dialog var result = Dialog.InputActionAsset.ShowSaveChanges(assetPath); @@ -379,14 +396,18 @@ private void HandleOnDestroy() { case Dialog.Result.Save: Save(isAutoSave: false); - break; + return true; case Dialog.Result.Cancel: - // Cancel editor quit. (open new editor window with the edited asset) - ReshowEditorWindowWithUnsavedChanges(); - break; + if (rebuildUIOnCancel) + { + // Cancel editor quit. (open new editor window with the edited asset) + ReshowEditorWindowWithUnsavedChanges(); + } + + return false; case Dialog.Result.Discard: // Don't save, quit - reload the old asset from the json to prevent the asset from being dirtied - break; + return true; default: throw new ArgumentOutOfRangeException(nameof(result)); } @@ -394,7 +415,7 @@ private void HandleOnDestroy() private void OnDestroy() { - HandleOnDestroy(); + CheckCanCloseAndPromptIfDirty(true); // Clean-up CleanupStateContainer();