Skip to content
Open
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
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Removed 32-bit compilation check for HID on Windows players, which had no impact anymore. (ISX-2543)
- Migrated sample scenes to use Universal Render Pipeline (URP) with Built-in Render Pipeline fallback shaders. The URP package is now required to run the samples. (ISX-2343)
- Changed the UI for `Actions.inputactions` asset to use UI Toolkit framework.
- Changed the UI for `InputSystem.inputsettings` asset to use UI Toolkit framework.

### Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.IO;
using UnityEditor;
using UnityEngine.UIElements;

namespace UnityEngine.InputSystem.Editor
{
Expand All @@ -19,7 +20,7 @@
InvalidPath,

/// <summary>
/// The dialog was cancelled by the user and the path is invalid.
/// The dialog was canceled by the user and the path is invalid.
Comment thread
josepmariapujol-unity marked this conversation as resolved.
Comment thread
josepmariapujol-unity marked this conversation as resolved.
/// </summary>
Cancelled,

Expand Down Expand Up @@ -82,12 +83,32 @@
return asset;
}

public static void DrawMakeActiveGui<T>(T current, T target, string targetName, string entity, Action<T> apply, bool allowAssignActive = true)
public static VisualElement CreateMakeActiveGui<T>(Func<T> getCurrent, T target, string targetName, string entity,
Action<T> apply, Action<Action> subscribeToChanges, Action<Action> unsubscribeFromChanges,
bool allowAssignActive = true)
where T : ScriptableObject
{
var container = new VisualElement();

Check warning on line 91 in Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs#L91

Added line #L91 was not covered by tests

void Refresh() => PopulateMakeActiveGui(container, getCurrent(), target, entity, apply, allowAssignActive);

Check warning on line 93 in Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs#L93

Added line #L93 was not covered by tests

Refresh();

Check warning on line 95 in Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs#L95

Added line #L95 was not covered by tests

// Subscribe for as long as the element is part of a panel, matching the pattern used in InputParameterEditor.
container.RegisterCallback<AttachToPanelEvent>(_ => subscribeToChanges(Refresh));
container.RegisterCallback<DetachFromPanelEvent>(_ => unsubscribeFromChanges(Refresh));

Check warning on line 99 in Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs#L98-L99

Added lines #L98 - L99 were not covered by tests

return container;
}

Check warning on line 102 in Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs#L101-L102

Added lines #L101 - L102 were not covered by tests

private static void PopulateMakeActiveGui<T>(VisualElement container, T current, T target, string entity, Action<T> apply, bool allowAssignActive)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium
The transition from IMGUI to UI Toolkit introduces a behavior regression where the UI remains stale if the active asset (e.g., InputSystem.settings) is changed from another window (like Project Settings) or via an Undo operation.

The previous IMGUI implementation re-evaluated InputSystem.settings on every repaint, ensuring the UI always reflected the current state. In the new UI Toolkit version, CreateInspectorGUI is called once, and the state only updates locally when the "Assign" button is clicked. If the setting is changed elsewhere, this inspector will continue to show incorrect information until the selection is changed and returned to.

Consider implementing a simple poll using container.schedule.Execute(...) or subscribing to an event (if available) to ensure the UI stays in sync with the global state.

🤖 Helpful? 👍/👎

where T : ScriptableObject
{
container.Clear();

Check warning on line 107 in Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs#L106-L107

Added lines #L106 - L107 were not covered by tests

if (current == target)
{
EditorGUILayout.HelpBox($"These actions are assigned as the {entity}.", MessageType.Info);
container.Add(new HelpBox($"These actions are assigned as the {entity}.", HelpBoxMessageType.Info));

Check warning on line 111 in Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs#L111

Added line #L111 was not covered by tests
Comment thread
josepmariapujol-unity marked this conversation as resolved.
return;
}

Expand All @@ -96,11 +117,21 @@
currentlyActiveAssetsPath = AssetDatabase.GetAssetPath(current);
if (!string.IsNullOrEmpty(currentlyActiveAssetsPath))
currentlyActiveAssetsPath = $" The actions currently assigned as the {entity} are: {currentlyActiveAssetsPath}. ";
EditorGUILayout.HelpBox($"These actions are not assigned as the {entity} for the Input System. {currentlyActiveAssetsPath??""}", MessageType.Warning);
GUI.enabled = allowAssignActive;
if (GUILayout.Button($"Assign as the {entity}", EditorStyles.miniButton))

container.Add(new HelpBox(

Check warning on line 121 in Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs#L121

Added line #L121 was not covered by tests
Comment thread
josepmariapujol-unity marked this conversation as resolved.
$"These actions are not assigned as the {entity} for the Input System. {currentlyActiveAssetsPath ?? ""}",
Comment thread
josepmariapujol-unity marked this conversation as resolved.
HelpBoxMessageType.Warning));

var assignButton = new Button(() =>
{

Check warning on line 126 in Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs#L125-L126

Added lines #L125 - L126 were not covered by tests
apply(target);
GUI.enabled = true;
PopulateMakeActiveGui(container, target, target, entity, apply, allowAssignActive);
})

Check warning on line 129 in Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs#L128-L129

Added lines #L128 - L129 were not covered by tests
{
text = $"Assign as the {entity}"
};
assignButton.SetEnabled(allowAssignActive);
container.Add(assignButton);

Check warning on line 134 in Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs#L133-L134

Added lines #L133 - L134 were not covered by tests
}

public static bool IsValidFileExtension(string path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,17 +489,36 @@
[CustomEditor(typeof(InputSettings))]
internal class InputSettingsEditor : UnityEditor.Editor
{
public override void OnInspectorGUI()
public override VisualElement CreateInspectorGUI()
{
EditorGUILayout.Space();
var root = new VisualElement();

Check warning on line 494 in Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs#L494

Added line #L494 was not covered by tests

if (GUILayout.Button("Open Input Settings Window", GUILayout.Height(30)))
InputSettingsProvider.Open();

EditorGUILayout.Space();
var openButton = new Button(() => InputSettingsProvider.Open())

Check warning on line 496 in Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs#L496

Added line #L496 was not covered by tests
{
text = "Open Input Settings Window",
style = { minHeight = 30, whiteSpace = WhiteSpace.Normal }
};
root.Add(openButton);

Check warning on line 501 in Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs#L501

Added line #L501 was not covered by tests

// UndoRedoCallback is void(), not Action, so an adapter is required.
// The variable is shared between the two lambdas so the same instance is removed on unsubscribe.
Undo.UndoRedoCallback undoRedoAdapter = null;
root.Add(InputAssetEditorUtils.CreateMakeActiveGui(
() => InputSystem.settings, target as InputSettings,
target.name, "settings", (value) => InputSystem.settings = value,

Check warning on line 508 in Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs#L505-L508

Added lines #L505 - L508 were not covered by tests
handler =>
{
InputSystem.onSettingsChange += handler;
undoRedoAdapter = () => handler();
Undo.undoRedoPerformed += undoRedoAdapter;
},

Check warning on line 514 in Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs#L510-L514

Added lines #L510 - L514 were not covered by tests
handler =>
{
InputSystem.onSettingsChange -= handler;
Undo.undoRedoPerformed -= undoRedoAdapter;
}));

Check warning on line 519 in Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs#L516-L519

Added lines #L516 - L519 were not covered by tests

InputAssetEditorUtils.DrawMakeActiveGui(InputSystem.settings, target as InputSettings,
target.name, "settings", (value) => InputSystem.settings = value);
return root;

Check warning on line 521 in Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs#L521

Added line #L521 was not covered by tests
}

protected override bool ShouldHideOpenButton()
Expand Down
Loading