From 6c659adef96f422a29afd9973312cd95dc6ed8ce Mon Sep 17 00:00:00 2001 From: JosepMariaPujol Date: Sat, 21 Mar 2026 09:24:57 +0100 Subject: [PATCH] Updating to UITOOLKIT input asset editor --- .../InputActionImporterEditor.cs | 2 +- .../Editor/InputAssetEditorUtils.cs | 29 +++++++++++++------ .../Editor/Settings/InputSettingsProvider.cs | 18 +++++++----- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporterEditor.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporterEditor.cs index f117089189..1155ad31af 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporterEditor.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporterEditor.cs @@ -39,7 +39,7 @@ public override void OnInspectorGUI() EditorGUILayout.Space(); // Project-wide Input Actions Asset UI. - InputAssetEditorUtils.DrawMakeActiveGui(InputSystem.actions, inputActionAsset, + InputAssetEditorUtils.CreateMakeActiveGui(InputSystem.actions, inputActionAsset, inputActionAsset ? inputActionAsset.name : "Null", "Project-wide Input Actions", (value) => InputSystem.actions = value, !EditorApplication.isPlayingOrWillChangePlaymode); diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs index e9aede7015..faf9800be8 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputAssetEditorUtils.cs @@ -3,6 +3,7 @@ using System; using System.IO; using UnityEditor; +using UnityEngine.UIElements; namespace UnityEngine.InputSystem.Editor { @@ -19,7 +20,7 @@ internal enum DialogResult InvalidPath, /// - /// The dialog was cancelled by the user and the path is invalid. + /// The dialog was canceled by the user and the path is invalid. /// Cancelled, @@ -82,13 +83,15 @@ internal static T CreateAsset(T asset, string relativePath) where T : Scripta return asset; } - public static void DrawMakeActiveGui(T current, T target, string targetName, string entity, Action apply, bool allowAssignActive = true) + public static VisualElement CreateMakeActiveGui(T current, T target, string targetName, string entity, Action apply, bool allowAssignActive = true) where T : ScriptableObject { + var container = new VisualElement(); + if (current == target) { - EditorGUILayout.HelpBox($"These actions are assigned as the {entity}.", MessageType.Info); - return; + container.Add(new HelpBox($"These actions are assigned as the {entity}.", HelpBoxMessageType.Info)); + return container; } string currentlyActiveAssetsPath = null; @@ -96,11 +99,19 @@ public static void DrawMakeActiveGui(T current, T target, string targetName, 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)) - apply(target); - GUI.enabled = true; + + container.Add(new HelpBox( + $"These actions are not assigned as the {entity} for the Input System. {currentlyActiveAssetsPath ?? ""}", + HelpBoxMessageType.Warning)); + + var assignButton = new Button(() => apply(target)) + { + text = $"Assign as the {entity}" + }; + assignButton.SetEnabled(allowAssignActive); + container.Add(assignButton); + + return container; } public static bool IsValidFileExtension(string path) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs index 1ac676a022..a120311d33 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs @@ -489,17 +489,21 @@ internal static void ForceReload() [CustomEditor(typeof(InputSettings))] internal class InputSettingsEditor : UnityEditor.Editor { - public override void OnInspectorGUI() + public override VisualElement CreateInspectorGUI() { - EditorGUILayout.Space(); + var root = new VisualElement(); - if (GUILayout.Button("Open Input Settings Window", GUILayout.Height(30))) - InputSettingsProvider.Open(); + var openButton = new Button(() => InputSettingsProvider.Open()) + { + text = "Open Input Settings Window", + style = { height = 30 } + }; + root.Add(openButton); - EditorGUILayout.Space(); + root.Add(InputAssetEditorUtils.CreateMakeActiveGui(InputSystem.settings, target as InputSettings, + target.name, "settings", (value) => InputSystem.settings = value)); - InputAssetEditorUtils.DrawMakeActiveGui(InputSystem.settings, target as InputSettings, - target.name, "settings", (value) => InputSystem.settings = value); + return root; } protected override bool ShouldHideOpenButton()