Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Assets/Tests/InputSystem/APIVerificationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HelpURLAttribute>() != null)
.Select(t => t.GetCustomAttribute<HelpURLAttribute>().URL);
var monoBehaviourTypesWithoutHelpUrls =
monoBehaviourTypes.Where(t => t.GetCustomAttribute<HelpURLAttribute>() == null);

var monoBehaviourTypesHelpUrls = monoBehaviourTypes.Where(t => t.GetCustomAttributes<HelpURLAttribute>().Any()).Select(t => t.GetCustomAttributes<HelpURLAttribute>().First().URL);
var monoBehaviourTypesWithoutHelpUrls = monoBehaviourTypes.Where(t => !t.GetCustomAttributes<HelpURLAttribute>().Any());
Assert.That(monoBehaviourTypesWithoutHelpUrls, Is.Empty);
Assert.That(monoBehaviourTypesHelpUrls, Has.All.StartWith(InputSystem.kDocUrl));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,16 @@ public void API_MonoBehaviourHelpUrlsAreValid()
typeof(MonoBehaviour).IsAssignableFrom(t));

var monoBehaviourTypesWithHelpUrls = monoBehaviourTypes
.Where(t => t.GetCustomAttribute<HelpURLAttribute>() != null);
.Where(t => t.GetCustomAttributes<HelpURLAttribute>().Any());

var brokenHelpUrlErrors = new StringBuilder();

// Ensure the links are actually valid.
foreach (var monoBehaviorTypeWithHelpUrl in monoBehaviourTypesWithHelpUrls)
{
// Get url
var url = monoBehaviorTypeWithHelpUrl.GetCustomAttribute<HelpURLAttribute>().URL;
var test = monoBehaviorTypeWithHelpUrl.GetCustomAttributes<HelpURLAttribute>();
var url = test.FirstOrDefault()?.URL;

// Parse file path and anchor.
var path = url.Substring(InputSystem.kDocUrl.Length);
Expand Down
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

private string m_AssetJson;
private bool m_IsDirty;
private bool m_IsEditorQuitting;

private StateContainer m_StateContainer;
private InputActionsEditorView m_View;
Expand Down Expand Up @@ -333,11 +334,21 @@
private void OnEnable()
{
analytics.Begin();
EditorApplication.wantsToQuit += OnWantsToQuit;
}

private void OnDisable()
{
analytics.End();
EditorApplication.wantsToQuit -= OnWantsToQuit;
}

private bool OnWantsToQuit()
{

Check warning on line 347 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs#L347

Added line #L347 was not covered by tests
// Here the user will be prompted
bool isAllowedToQuit = CheckCanCloseAndPromptIfDirty(false);
m_IsEditorQuitting = isAllowedToQuit;
return m_IsEditorQuitting;

Check warning on line 351 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs#L349-L351

Added lines #L349 - L351 were not covered by tests
}

private void OnFocus()
Expand All @@ -362,39 +373,49 @@
analytics.RegisterEditorFocusOut();
}

private void HandleOnDestroy()
/// <summary>
/// Shows a dialog when trying to close an input asset without saving changes.
/// </summary>
/// <param name="rebuildUIOnCancel">If true, reopens the editor window when user cancels.</param>
/// <returns> Returns true if you should allow the Unity Editor to close. </returns>
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;

Check warning on line 391 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs#L391

Added line #L391 was not covered by tests

// Prompt user with a dialog
var result = Dialog.InputActionAsset.ShowSaveChanges(assetPath);
switch (result)
{
case Dialog.Result.Save:
Save(isAutoSave: false);
break;
return true;

Check warning on line 399 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs#L399

Added line #L399 was not covered by tests
case Dialog.Result.Cancel:
// Cancel editor quit. (open new editor window with the edited asset)
ReshowEditorWindowWithUnsavedChanges();
break;
if (rebuildUIOnCancel)
{

Check warning on line 402 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs#L401-L402

Added lines #L401 - L402 were not covered by tests
// Cancel editor quit. (open new editor window with the edited asset)
ReshowEditorWindowWithUnsavedChanges();
}

Check warning on line 405 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs#L404-L405

Added lines #L404 - L405 were not covered by tests

return false;

Check warning on line 407 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs#L407

Added line #L407 was not covered by tests
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));
}
}

private void OnDestroy()
{
HandleOnDestroy();
CheckCanCloseAndPromptIfDirty(true);

// Clean-up
CleanupStateContainer();
Expand Down