Skip to content

Commit cf79402

Browse files
Schedule container auto refresh active gui
1 parent 2002822 commit cf79402

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,24 @@ internal static T CreateAsset<T>(T asset, string relativePath) where T : Scripta
8383
return asset;
8484
}
8585

86-
public static VisualElement CreateMakeActiveGui<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, Action<T> apply, bool allowAssignActive = true)
8787
where T : ScriptableObject
8888
{
8989
var container = new VisualElement();
90-
PopulateMakeActiveGui(container, current, target, entity, apply, allowAssignActive);
90+
var lastKnownCurrent = getCurrent();
91+
PopulateMakeActiveGui(container, lastKnownCurrent, target, entity, apply, allowAssignActive);
92+
93+
// Poll for external changes to the active asset (e.g. from Project Settings or Undo).
94+
// The scheduled item is automatically stopped when the element leaves the panel.
95+
container.schedule.Execute(() =>
96+
{
97+
var current = getCurrent();
98+
if (current == lastKnownCurrent)
99+
return;
100+
lastKnownCurrent = current;
101+
PopulateMakeActiveGui(container, current, target, entity, apply, allowAssignActive);
102+
}).Every(500);
103+
91104
return container;
92105
}
93106

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ public override VisualElement CreateInspectorGUI()
500500
};
501501
root.Add(openButton);
502502

503-
root.Add(InputAssetEditorUtils.CreateMakeActiveGui(InputSystem.settings, target as InputSettings,
503+
root.Add(InputAssetEditorUtils.CreateMakeActiveGui(() => InputSystem.settings, target as InputSettings,
504504
target.name, "settings", (value) => InputSystem.settings = value));
505505

506506
return root;

0 commit comments

Comments
 (0)