Skip to content

Commit 6b3acd1

Browse files
Merge branch 'develop' into bugfix/uum-138143-button-press-points-for-stickcontrol-and-vector2-add-functionality
2 parents f5500dc + 2255883 commit 6b3acd1

4 files changed

Lines changed: 80 additions & 15 deletions

File tree

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2929
- Removed 32-bit compilation check for HID on Windows players, which had no impact anymore. (ISX-2543)
3030
- 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)
3131
- Changed the UI for `Actions.inputactions` asset to use UI Toolkit framework.
32+
- Changed the UI for `InputSystem.inputsettings` asset to use UI Toolkit framework.
3233

3334
### Added
3435

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

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.IO;
55
using UnityEditor;
6+
using UnityEngine.UIElements;
67

78
namespace UnityEngine.InputSystem.Editor
89
{
@@ -82,12 +83,32 @@ internal static T CreateAsset<T>(T asset, string relativePath) where T : Scripta
8283
return asset;
8384
}
8485

85-
public static void DrawMakeActiveGui<T>(T current, T target, string targetName, string entity, Action<T> apply, bool allowAssignActive = true)
86+
public static VisualElement CreateMakeActiveGui<T>(Func<T> getCurrent, T target, string targetName, string entity,
87+
Action<T> apply, Action<Action> subscribeToChanges, Action<Action> unsubscribeFromChanges,
88+
bool allowAssignActive = true)
8689
where T : ScriptableObject
8790
{
91+
var container = new VisualElement();
92+
93+
void Refresh() => PopulateMakeActiveGui(container, getCurrent(), target, entity, apply, allowAssignActive);
94+
95+
Refresh();
96+
97+
// Subscribe for as long as the element is part of a panel, matching the pattern used in InputParameterEditor.
98+
container.RegisterCallback<AttachToPanelEvent>(_ => subscribeToChanges(Refresh));
99+
container.RegisterCallback<DetachFromPanelEvent>(_ => unsubscribeFromChanges(Refresh));
100+
101+
return container;
102+
}
103+
104+
private static void PopulateMakeActiveGui<T>(VisualElement container, T current, T target, string entity, Action<T> apply, bool allowAssignActive)
105+
where T : ScriptableObject
106+
{
107+
container.Clear();
108+
88109
if (current == target)
89110
{
90-
EditorGUILayout.HelpBox($"These actions are assigned as the {entity}.", MessageType.Info);
111+
container.Add(new HelpBox($"These actions are assigned as the {entity}.", HelpBoxMessageType.Info));
91112
return;
92113
}
93114

@@ -96,11 +117,26 @@ public static void DrawMakeActiveGui<T>(T current, T target, string targetName,
96117
currentlyActiveAssetsPath = AssetDatabase.GetAssetPath(current);
97118
if (!string.IsNullOrEmpty(currentlyActiveAssetsPath))
98119
currentlyActiveAssetsPath = $" The actions currently assigned as the {entity} are: {currentlyActiveAssetsPath}. ";
99-
EditorGUILayout.HelpBox($"These actions are not assigned as the {entity} for the Input System. {currentlyActiveAssetsPath??""}", MessageType.Warning);
100-
GUI.enabled = allowAssignActive;
101-
if (GUILayout.Button($"Assign as the {entity}", EditorStyles.miniButton))
120+
121+
container.Add(new HelpBox(
122+
$"These actions are not assigned as the {entity} for the Input System. {currentlyActiveAssetsPath ?? ""}",
123+
HelpBoxMessageType.Warning));
124+
125+
var assignButton = new Button(() =>
126+
{
102127
apply(target);
103-
GUI.enabled = true;
128+
PopulateMakeActiveGui(container, target, target, entity, apply, allowAssignActive);
129+
})
130+
{
131+
text = $"Assign as the {entity}",
132+
style =
133+
{
134+
minHeight = 30,
135+
whiteSpace = WhiteSpace.Normal
136+
}
137+
};
138+
assignButton.SetEnabled(allowAssignActive);
139+
container.Add(assignButton);
104140
}
105141

106142
public static bool IsValidFileExtension(string path)

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,17 +489,36 @@ internal static void ForceReload()
489489
[CustomEditor(typeof(InputSettings))]
490490
internal class InputSettingsEditor : UnityEditor.Editor
491491
{
492-
public override void OnInspectorGUI()
492+
public override VisualElement CreateInspectorGUI()
493493
{
494-
EditorGUILayout.Space();
494+
var root = new VisualElement();
495495

496-
if (GUILayout.Button("Open Input Settings Window", GUILayout.Height(30)))
497-
InputSettingsProvider.Open();
498-
499-
EditorGUILayout.Space();
496+
var openButton = new Button(() => InputSettingsProvider.Open())
497+
{
498+
text = "Open Input Settings Window",
499+
style = { minHeight = 30, whiteSpace = WhiteSpace.Normal }
500+
};
501+
root.Add(openButton);
502+
503+
// UndoRedoCallback is void(), not Action, so an adapter is required.
504+
// The variable is shared between the two lambdas so the same instance is removed on unsubscribe.
505+
Undo.UndoRedoCallback undoRedoAdapter = null;
506+
root.Add(InputAssetEditorUtils.CreateMakeActiveGui(
507+
() => InputSystem.settings, target as InputSettings,
508+
target.name, "settings", (value) => InputSystem.settings = value,
509+
handler =>
510+
{
511+
InputSystem.onSettingsChange += handler;
512+
undoRedoAdapter = () => handler();
513+
Undo.undoRedoPerformed += undoRedoAdapter;
514+
},
515+
handler =>
516+
{
517+
InputSystem.onSettingsChange -= handler;
518+
Undo.undoRedoPerformed -= undoRedoAdapter;
519+
}));
500520

501-
InputAssetEditorUtils.DrawMakeActiveGui(InputSystem.settings, target as InputSettings,
502-
target.name, "settings", (value) => InputSystem.settings = value);
521+
return root;
503522
}
504523

505524
protected override bool ShouldHideOpenButton()

Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.LegacyFocusHandling.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)