Skip to content

Commit c163d99

Browse files
committed
Added a UI rebuild mode enum and added it as a defaulted parameter to the state container dispatch and view base OnStateChanged - this gives us control over which state changes cause a UI rebuild
1 parent 7924b18 commit c163d99

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private void OnFocusOut(FocusOutEvent @event = null)
176176
DelayFocusLost(element == null);
177177
}
178178

179-
private void OnStateChanged(InputActionsEditorState newState)
179+
private void OnStateChanged(InputActionsEditorState newState, UIRebuildMode editorRebuildMode)
180180
{
181181
#if UNITY_INPUT_SYSTEM_INPUT_ACTIONS_EDITOR_AUTO_SAVE_ON_FOCUS_LOST
182182
// No action, auto-saved on edit-focus lost

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private void BuildUI()
237237
m_StateContainer.Initialize(rootVisualElement.Q("action-editor"));
238238
}
239239

240-
private void OnStateChanged(InputActionsEditorState newState)
240+
private void OnStateChanged(InputActionsEditorState newState, UIRebuildMode editorRebuildMode)
241241
{
242242
DirtyInputActionsEditorWindow(newState);
243243
m_State = newState;

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@
77

88
namespace UnityEngine.InputSystem.Editor
99
{
10+
// Enum used to dictate if a state change should rebuild the Input Actions editor UI
11+
internal enum UIRebuildMode
12+
{
13+
None,
14+
Rebuild,
15+
}
16+
1017
internal class StateContainer
1118
{
12-
public event Action<InputActionsEditorState> StateChanged;
19+
public event Action<InputActionsEditorState, UIRebuildMode> StateChanged;
1320

1421
private VisualElement m_RootVisualElement;
1522
private InputActionsEditorState m_State;
@@ -21,7 +28,7 @@ public StateContainer(InputActionsEditorState initialState, string assetGUID)
2128
this.assetGUID = assetGUID;
2229
}
2330

24-
public void Dispatch(Command command)
31+
public void Dispatch(Command command, UIRebuildMode editorRebuildMode = UIRebuildMode.Rebuild)
2532
{
2633
if (command == null)
2734
throw new ArgumentNullException(nameof(command));
@@ -36,7 +43,7 @@ public void Dispatch(Command command)
3643
// catch exceptions here or the UIToolkit scheduled event will keep firing forever.
3744
try
3845
{
39-
StateChanged?.Invoke(m_State);
46+
StateChanged?.Invoke(m_State, editorRebuildMode);
4047
}
4148
catch (Exception e)
4249
{
@@ -55,9 +62,9 @@ public void Initialize(VisualElement rootVisualElement)
5562
m_RootVisualElement.Unbind();
5663
m_RootVisualElement.TrackSerializedObjectValue(m_State.serializedObject, so =>
5764
{
58-
StateChanged?.Invoke(m_State);
65+
StateChanged?.Invoke(m_State, UIRebuildMode.Rebuild);
5966
});
60-
StateChanged?.Invoke(m_State);
67+
StateChanged?.Invoke(m_State, UIRebuildMode.Rebuild);
6168
rootVisualElement.Bind(m_State.serializedObject);
6269
}
6370

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public override void RedrawUI(ViewState viewState)
4242

4343
viewState.parameterListView.onChange = () =>
4444
{
45-
Dispatch(Commands.UpdatePathNameAndValues(viewState.parameterListView.GetParameters(), viewState.selectedBindingPath));
45+
Dispatch(Commands.UpdatePathNameAndValues(viewState.parameterListView.GetParameters(), viewState.selectedBindingPath), UIRebuildMode.None);
4646
};
4747
viewState.parameterListView.OnDrawVisualElements(rootElement);
4848
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ protected ViewBase(VisualElement root, StateContainer stateContainer)
2626
m_ChildViews = new List<IView>();
2727
}
2828

29-
protected void OnStateChanged(InputActionsEditorState state)
29+
protected void OnStateChanged(InputActionsEditorState state, UIRebuildMode editorRebuildMode)
3030
{
31+
// Return early if rebuilding the editor UI isn't required (ISXB-1171)
32+
if (editorRebuildMode == UIRebuildMode.None)
33+
return;
34+
3135
UpdateView(state);
3236
}
3337

@@ -70,9 +74,9 @@ public void DestroyChildView<TView>(TView view) where TView : IView
7074
view.DestroyView();
7175
}
7276

73-
public void Dispatch(Command command)
77+
public void Dispatch(Command command, UIRebuildMode editorRebuildMode = UIRebuildMode.Rebuild)
7478
{
75-
stateContainer.Dispatch(command);
79+
stateContainer.Dispatch(command, editorRebuildMode);
7680
}
7781

7882
public abstract void RedrawUI(TViewState viewState);

0 commit comments

Comments
 (0)