Skip to content

Commit 7b43564

Browse files
Add better fix for the control schemes view closing on autosave.
We now just don't autosave in this case as there is no need.
1 parent e8ed485 commit 7b43564

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

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

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private static GUIContent GetEditorTitle(InputActionAsset asset, bool isDirty)
168168
return new GUIContent(text);
169169
}
170170

171-
private void SetAsset(InputActionAsset asset, string actionToSelect = null, string actionMapToSelect = null, bool shouldClearRootVisualElement = true)
171+
private void SetAsset(InputActionAsset asset, string actionToSelect = null, string actionMapToSelect = null)
172172
{
173173
var existingWorkingCopy = m_AssetObjectForEditing;
174174

@@ -189,7 +189,7 @@ private void SetAsset(InputActionAsset asset, string actionToSelect = null, stri
189189
m_State = m_State.SelectAction(actionToSelect);
190190
}
191191

192-
BuildUI(shouldClearRootVisualElement);
192+
BuildUI();
193193
}
194194
catch (Exception e)
195195
{
@@ -262,7 +262,7 @@ private void CleanupStateContainer()
262262
}
263263
}
264264

265-
private void BuildUI(bool shouldClearRoot = true)
265+
private void BuildUI()
266266
{
267267
CleanupStateContainer();
268268

@@ -271,32 +271,13 @@ private void BuildUI(bool shouldClearRoot = true)
271271

272272
m_StateContainer = new StateContainer(m_State, m_AssetGUID);
273273
m_StateContainer.StateChanged += OnStateChanged;
274-
IEnumerable<VisualElement> children = null;
275-
if (!shouldClearRoot)
276-
{
277-
children = new List<VisualElement>(rootVisualElement.hierarchy.Children());
278-
}
279274

280275
rootVisualElement.Clear();
281276

282277
if (!rootVisualElement.styleSheets.Contains(InputActionsEditorWindowUtils.theme))
283278
rootVisualElement.styleSheets.Add(InputActionsEditorWindowUtils.theme);
284279
m_View = new InputActionsEditorView(rootVisualElement, m_StateContainer, false, () => Save(isAutoSave: false));
285280
m_StateContainer.Initialize(rootVisualElement.Q("action-editor"));
286-
287-
if (children != null)
288-
{
289-
foreach (var child in children)
290-
{
291-
for (int i = rootVisualElement.hierarchy.childCount - 1; i >= 0; i--)
292-
{
293-
if (rootVisualElement.hierarchy.ElementAt(i).name != child.name)
294-
{
295-
rootVisualElement.hierarchy.Add(child);
296-
}
297-
}
298-
}
299-
}
300281
}
301282

302283
private void OnStateChanged(InputActionsEditorState newState, UIRebuildMode editorRebuildMode)
@@ -388,7 +369,7 @@ private void OnLostFocus()
388369
// This code should be cleaned up once we migrate the InputControl stuff from ImGUI completely.
389370
// Since at that point it stops being a separate window that steals focus.
390371
// (See case ISXB-1221)
391-
if (!InputControlPathEditor.IsShowingDropdown)
372+
if (!InputControlPathEditor.IsShowingDropdown && !ControlSchemesView.IsShowingControlSchemeView)
392373
Save(isAutoSave: true);
393374
#endif
394375

@@ -534,7 +515,7 @@ public void OnAssetImported()
534515
}
535516

536517
// We set shouldClearRootVisualElement to false here as we don't want the root visual element's child elements to be closed during an auto save.
537-
SetAsset(AssetDatabase.LoadAssetAtPath<InputActionAsset>(assetPath), shouldClearRootVisualElement: false);
518+
SetAsset(AssetDatabase.LoadAssetAtPath<InputActionAsset>(assetPath));
538519
}
539520

540521
#endregion

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ internal class ControlSchemesView : ViewBase<InputControlScheme>
1414
private string m_NewName;
1515
public event Action<ViewBase<InputControlScheme>> OnClosing;
1616

17+
/// <summary>
18+
/// This property is only set from this class in order to communicate that we're showing the control schemes view at the moment
19+
/// It's employed to skip auto-saving, because that complicates the save causing this window to close when adding a new device type.
20+
/// </summary>
21+
internal static bool IsShowingControlSchemeView { get; private set; }
22+
1723
public ControlSchemesView(VisualElement root, StateContainer stateContainer, bool updateExisting = false)
1824
: base(root, stateContainer)
1925
{
26+
IsShowingControlSchemeView = true;
2027
m_UpdateExisting = updateExisting;
2128

2229
var controlSchemeEditor = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
@@ -118,6 +125,7 @@ public override void RedrawUI(InputControlScheme viewState)
118125

119126
public override void DestroyView()
120127
{
128+
IsShowingControlSchemeView = false;
121129
m_ModalWindow.RemoveFromHierarchy();
122130
}
123131

@@ -137,6 +145,8 @@ private void Cancel()
137145

138146
private void CloseView()
139147
{
148+
IsShowingControlSchemeView = false;
149+
140150
// Closing the View without explicitly selecting "Save" or "Cancel" holds the values in the
141151
// current UI state but won't persist them; the Asset Editor state isn't dirtied.
142152
//

0 commit comments

Comments
 (0)