Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,16 @@
{
return (in InputActionsEditorState state) =>
{
var controlSchemeSerializedProperty = state.selectedControlSchemeIndex == -1 ? null :
state.serializedObject
.FindProperty(nameof(InputActionAsset.m_ControlSchemes))
.GetArrayElementAtIndex(state.selectedControlSchemeIndex);
SerializedProperty controlSchemeSerializedProperty = null;
var serializedProperty = state.serializedObject

Check warning on line 149 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/ControlSchemeCommands.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/ControlSchemeCommands.cs#L148-L149

Added lines #L148 - L149 were not covered by tests
.FindProperty(nameof(InputActionAsset.m_ControlSchemes));

if (state.selectedControlSchemeIndex < serializedProperty.arraySize)
{
controlSchemeSerializedProperty = state.selectedControlSchemeIndex == -1 ? null :

Check warning on line 154 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/ControlSchemeCommands.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/ControlSchemeCommands.cs#L152-L154

Added lines #L152 - L154 were not covered by tests
serializedProperty
.GetArrayElementAtIndex(state.selectedControlSchemeIndex);
}

Check warning on line 157 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/ControlSchemeCommands.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/ControlSchemeCommands.cs#L157

Added line #L157 was not covered by tests

if (controlSchemeSerializedProperty == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ private void RemoveDeviceRequirement()
public override void RedrawUI(InputControlScheme viewState)
{
rootElement.Q<TextField>(kControlSchemeNameTextField).value = string.IsNullOrEmpty(m_NewName) ? viewState.name : m_NewName;

m_ListView.itemsSource?.Clear();
m_ListView.itemsSource = viewState.deviceRequirements.Count > 0 ?
viewState.deviceRequirements.Select(r => (r.controlPath, r.isOptional)).ToList() :
Expand All @@ -128,7 +127,7 @@ private void SaveAndClose()
CloseView();
}

private void Cancel()
internal void Cancel()
{
// Reload the selected ControlScheme values from the SerilaizedProperty and throw away any changes
Dispatch(ControlSchemeCommands.ResetSelectedControlScheme());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
Expand All @@ -23,6 +24,8 @@
private readonly ToolbarButton m_SaveButton;

private readonly Action m_SaveAction;

private ControlSchemesView m_ControlSchemesView;

public InputActionsEditorView(VisualElement root, StateContainer stateContainer, bool isProjectSettings,
Action saveAction)
Expand Down Expand Up @@ -104,6 +107,27 @@
});

s_OnPasteCutElements.Add(this);

Undo.undoRedoPerformed += CheckForInvalidControlSchemeInOneFrame;
}

private async void CheckForInvalidControlSchemeInOneFrame()
{

Check warning on line 115 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

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

Added line #L115 was not covered by tests
try
{
await Task.Delay(1);
var state = stateContainer.GetState();
var viewState = ViewStateSelector.GetViewState(state);
var elementAtOrDefault = viewState.controlSchemes?.ElementAtOrDefault(viewState.selectedControlSchemeIndex);
if (viewState.selectedControlSchemeIndex != -1 && elementAtOrDefault == default(InputControlScheme))
{
m_ControlSchemesView?.Cancel();
}
}
catch (Exception e)
{
Debug.LogException(e);
}

Check warning on line 130 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs#L117-L130

Added lines #L117 - L130 were not covered by tests
}

private void OnReset()
Expand Down Expand Up @@ -156,9 +180,8 @@

if (viewState.controlSchemes.Any())
{
m_ControlSchemesToolbar.text = viewState.selectedControlSchemeIndex == -1
? "All Control Schemes"
: viewState.controlSchemes.ElementAt(viewState.selectedControlSchemeIndex).name;
var elementAtOrDefault = viewState.controlSchemes.ElementAtOrDefault(viewState.selectedControlSchemeIndex);
m_ControlSchemesToolbar.text = elementAtOrDefault == default ? "All Control Schemes" : elementAtOrDefault.name;

Check warning on line 184 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs#L183-L184

Added lines #L183 - L184 were not covered by tests

m_ControlSchemesToolbar.menu.AppendAction("All Control Schemes", _ => SelectControlScheme(-1),
viewState.selectedControlSchemeIndex == -1 ? DropdownMenuAction.Status.Checked : DropdownMenuAction.Status.Normal);
Expand Down Expand Up @@ -186,7 +209,7 @@
return;
}
m_DevicesToolbar.SetEnabled(true);
var currentControlScheme = viewState.controlSchemes.ElementAt(viewState.selectedControlSchemeIndex);
var currentControlScheme = viewState.controlSchemes.ElementAtOrDefault(viewState.selectedControlSchemeIndex);

Check warning on line 212 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

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

Added line #L212 was not covered by tests
if (viewState.selectedDeviceIndex == -1)
m_DevicesToolbar.text = "All Devices";

Expand Down Expand Up @@ -228,12 +251,15 @@

private void ShowControlSchemeEditor(VisualElement parent, bool updateExisting = false)
{
var controlSchemesView = CreateChildView(new ControlSchemesView(parent, stateContainer, updateExisting));
controlSchemesView.UpdateView(stateContainer.GetState());

controlSchemesView.OnClosing += _ => DestroyChildView(controlSchemesView);
m_ControlSchemesView = CreateChildView(new ControlSchemesView(parent, stateContainer, updateExisting));
m_ControlSchemesView.UpdateView(stateContainer.GetState());
m_ControlSchemesView.OnClosing += _ =>
{
DestroyChildView(m_ControlSchemesView);
m_ControlSchemesView = null;
};

Check warning on line 260 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs#L254-L260

Added lines #L254 - L260 were not covered by tests
}

private void SelectControlScheme(int controlSchemeIndex)
{
Dispatch(ControlSchemeCommands.SelectControlScheme(controlSchemeIndex));
Expand All @@ -258,6 +284,7 @@
{
base.DestroyView();
s_OnPasteCutElements.Remove(this);
Undo.undoRedoPerformed -= CheckForInvalidControlSchemeInOneFrame;
}

public void OnPaste(InputActionsEditorState state)
Expand Down