Skip to content

Commit 8380050

Browse files
NEW: Add option to reset project-wide actions to original state (ISX-1564) (#1793)
* restore default settings * made left click work on menu button * hide menu for project input action asset * fixed icon for reset menu * added changelog * PR refactor * applied event change for postSaveAction as well --------- Co-authored-by: James McGill <[email protected]>
1 parent 62dd874 commit 8380050

File tree

9 files changed

+57
-19
lines changed

9 files changed

+57
-19
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ however, it has to be formatted properly to pass verification tests.
2626
- Support for [Game rotation vector](https://developer.android.com/reference/android/hardware/Sensor#TYPE_GAME_ROTATION_VECTOR) sensor on Android
2727
- Duplicate Input Action Items in the new Input Action Asset Editor with Ctrl+D (Windows) or Cmd+D (Mac)
2828
- Selection of InputActionReferences from project-wide actions on fields that are of type InputActionReference. Uses a new advanced object picker that allows better searching and filtering of actions.
29+
- Reset project wide Input Settings to default via a new Kebab-menu in Input System Project Settings.
2930

3031
### Fixed
3132
- Partially fixed case ISX-1357 (Investigate performance regressing over time). A sample showed that leaving an InputActionMap enabled could lead to an internal list of listeners growing. This leads to slow-down, so we now warn if we think this is happening.

Packages/com.unity.inputsystem/InputSystem/Editor/ProjectWideActions/ProjectWideActionsAsset.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ internal static InputActionAsset GetOrCreate()
5151
return CreateNewActionAsset();
5252
}
5353

54-
private static InputActionAsset CreateNewActionAsset()
54+
internal static InputActionAsset CreateNewActionAsset()
5555
{
5656
var json = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, s_DefaultAssetPath));
5757

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

+10
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,16 @@ public static Command ChangeCompositeName(int actionMapIndex, int bindingIndex,
366366
return state;
367367
};
368368
}
369+
370+
public static Command ResetGlobalInputAsset(Action<InputActionAsset> postResetAction)
371+
{
372+
return (in InputActionsEditorState state) =>
373+
{
374+
var asset = ProjectWideActionsAsset.CreateNewActionAsset();
375+
postResetAction?.Invoke(asset);
376+
return state;
377+
};
378+
}
369379
}
370380
}
371381

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ private void BuildUI()
9696
m_StateContainer = new StateContainer(m_RootVisualElement, m_State);
9797
m_StateContainer.StateChanged += OnStateChanged;
9898
m_RootVisualElement.styleSheets.Add(InputActionsEditorWindowUtils.theme);
99-
new InputActionsEditorView(m_RootVisualElement, m_StateContainer, null);
99+
var view = new InputActionsEditorView(m_RootVisualElement, m_StateContainer);
100+
view.postResetAction += OnResetAsset;
100101
m_StateContainer.Initialize();
101102

102103
// Hide the save / auto save buttons in the project wide input actions
@@ -109,6 +110,12 @@ private void BuildUI()
109110
}
110111
}
111112

113+
private void OnResetAsset(InputActionAsset newAsset)
114+
{
115+
var serializedAsset = new SerializedObject(newAsset);
116+
m_State = new InputActionsEditorState(serializedAsset);
117+
}
118+
112119
[SettingsProvider]
113120
public static SettingsProvider CreateGlobalInputActionsEditorProvider()
114121
{

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ private void BuildUI()
169169
stateContainer.StateChanged += OnStateChanged;
170170

171171
rootVisualElement.styleSheets.Add(InputActionsEditorWindowUtils.theme);
172-
var view = new InputActionsEditorView(rootVisualElement, stateContainer, PostSaveAction);
172+
var view = new InputActionsEditorView(rootVisualElement, stateContainer);
173+
view.postSaveAction += PostSaveAction;
173174
stateContainer.Initialize();
174175
}
175176

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Resources/InputActionsEditor.uxml

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
<Style src="project://database/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Resources/InputActionsEditorStyles.uss?fileID=7433441132597879392&amp;guid=7dac9c49a90bca4499371d0adc9b617b&amp;type=3#InputActionsEditorStyles" />
33
<ui:VisualElement name="header" class="header">
44
<ui:Label text="Input Actions" display-tooltip-when-elided="true" name="title-label" class="header-label" style="width: auto; margin-left: 0; margin-right: 0; margin-top: 0; margin-bottom: 0;" />
5-
<uie:ToolbarSearchField focusable="true" name="search-actions-text-field" class="search-field" />
5+
<uie:ToolbarSearchField focusable="true" name="search-actions-text-field" class="search-field" style="display: none;" />
6+
<ui:VisualElement name="asset-menu" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); width: 16px; flex-shrink: 0; -unity-background-scale-mode: scale-to-fit;" />
67
</ui:VisualElement>
78
<ui:VisualElement name="control-schemes-toolbar-container">
89
<uie:Toolbar>
910
<ui:VisualElement style="flex-direction: row; flex-grow: 1;">
1011
<uie:ToolbarMenu display-tooltip-when-elided="true" text="No Control Schemes" name="control-schemes-toolbar-menu" style="min-width: 135px;" />
1112
<uie:ToolbarMenu display-tooltip-when-elided="true" text="All Devices" enabled="false" name="control-schemes-filter-toolbar-menu" />
1213
</ui:VisualElement>
13-
<ui:VisualElement style="flex-direction: row; justify-content: flex-end;" name="save-asset-toolbar-container">
14+
<ui:VisualElement name="save-asset-toolbar-container" style="flex-direction: row; justify-content: flex-end;">
1415
<uie:ToolbarButton text="Save Asset" display-tooltip-when-elided="true" name="save-asset-toolbar-button" style="align-items: auto;" />
1516
<uie:ToolbarToggle focusable="false" label="Auto-Save" name="auto-save-toolbar-toggle" style="width: 69px;" />
1617
</ui:VisualElement>

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Resources/InputActionsEditorStyles.uss

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
/*****************************************************************************/
2-
/* Global */
3-
/*****************************************************************************/
4-
51
.unity-input-actions-editor-hidden {
62
display: none;
73
}
84

5+
.asset-menu-button-dark-theme {
6+
background-image: resource('d__Menu.png');
7+
}
8+
9+
.asset-menu-button {
10+
background-image: resource('_Menu.png');
11+
-unity-background-scale-mode: scale-to-fit;
12+
}
13+
914
.body-panel-container {
1015
min-width: 150px;
1116
border-top-width: 1px;
@@ -29,7 +34,7 @@
2934
border-width: 0;
3035
}
3136

32-
#add-new-action-button {
37+
#add-new-action-button {
3338
background-color: transparent;
3439
border-width: 0;
3540
}
@@ -171,12 +176,12 @@
171176
.name-and-parameters-list-view .delete {
172177
background-image: resource('Toolbar Minus.png');
173178
}
179+
174180
.name-and-parameters-list-view .deleteDarkTheme {
175181
background-image: resource('d_Toolbar Minus.png');
176182
}
177183

178184
.search-field {
179-
/* hide while not implemented */
180185
display: none;
181186
width: 190px;
182187
}

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

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ internal static class ContextMenu
1717

1818
private static readonly string add_Action_String = "Add Action";
1919
private static readonly string add_Binding_String = "Add Binding";
20-
private static readonly string add_positiveNegative_Binding_String = "Add Positive\\Negative Binding";
21-
private static readonly string add_oneModifier_Binding_String = "Add Binding With One Modifier";
22-
private static readonly string add_twoModifier_Binding_String = "Add Binding With Two Modifiers";
2320
public static void GetContextMenuForActionMapItem(InputActionMapsTreeViewItem treeViewItem)
2421
{
2522
var _ = new ContextualMenuManipulator(menuEvent =>

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

+21-5
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ internal class InputActionsEditorView : ViewBase<InputActionsEditorView.ViewStat
1212
{
1313
private const string saveButtonId = "save-asset-toolbar-button";
1414
private const string autoSaveToggleId = "auto-save-toolbar-toggle";
15+
private const string menuButtonId = "asset-menu";
1516

16-
Action m_PostSaveAction;
17+
internal Action postSaveAction;
18+
internal Action<InputActionAsset> postResetAction;
1719

18-
public InputActionsEditorView(VisualElement root, StateContainer stateContainer, Action mpostSaveAction)
20+
public InputActionsEditorView(VisualElement root, StateContainer stateContainer)
1921
: base(stateContainer)
2022
{
2123
m_Root = root;
22-
m_PostSaveAction = mpostSaveAction;
2324
BuildUI();
2425
}
2526

@@ -51,6 +52,16 @@ public void BuildUI()
5152
autoSaveToggle.value = InputEditorUserSettings.autoSaveInputActionAssets;
5253
autoSaveToggle.RegisterValueChangedCallback(OnAutoSaveToggle);
5354

55+
56+
var assetMenuButton = m_Root.Q<VisualElement>(name: menuButtonId);
57+
var isGlobalAsset = stateContainer.GetState().serializedObject.targetObject.name == "ProjectWideInputActions";
58+
assetMenuButton.visible = isGlobalAsset;
59+
assetMenuButton.AddToClassList(EditorGUIUtility.isProSkin ? "asset-menu-button-dark-theme" : "asset-menu-button");
60+
var _ = new ContextualMenuManipulator(menuEvent =>
61+
{
62+
menuEvent.menu.AppendAction("Reset", _ => OnReset());
63+
}) { target = assetMenuButton, activators = { new ManipulatorActivationFilter() {button = MouseButton.LeftMouse} }};
64+
5465
// only register the state changed event here in the parent. Changes will be cascaded
5566
// into child views.
5667
stateContainer.StateChanged += OnStateChanged;
@@ -65,14 +76,19 @@ public void BuildUI()
6576
});
6677
}
6778

79+
private void OnReset()
80+
{
81+
Dispatch(Commands.ResetGlobalInputAsset(postResetAction));
82+
}
83+
6884
private void OnSaveButton()
6985
{
70-
Dispatch(Commands.SaveAsset(m_PostSaveAction));
86+
Dispatch(Commands.SaveAsset(postSaveAction));
7187
}
7288

7389
private void OnAutoSaveToggle(ChangeEvent<bool> evt)
7490
{
75-
Dispatch(Commands.ToggleAutoSave(evt.newValue, m_PostSaveAction));
91+
Dispatch(Commands.ToggleAutoSave(evt.newValue, postSaveAction));
7692
}
7793

7894
public override void RedrawUI(ViewState viewState)

0 commit comments

Comments
 (0)