Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Prefabs and missing default control scheme in the inspector view of playerinput (ISXB-818) #1932

Merged
merged 5 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ however, it has to be formatted properly to pass verification tests.
- Fixed Composite binding isn't triggered after ResetDevice() called during Action handler [ISXB-746](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-746)
- Fixed resource designation for "d_InputControl" icon to address CI failure
- Fixed Composite binding isn't triggered after disabling action while there are in progress [ISXB-505](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-505)
- Fixed Missing default control scheme used by PlayerInput component are now correctly shown in the inspector [ISXB-818](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-818)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct to assume the behavior with a missing control scheme is equivalent to having it set to Any (ignoring Inspector representation)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this is mainly targeting representation of control scheme when opening a project/asset with a previously configured control scheme that no longer exist, or e.g. deleting a control scheme.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct to assume the behavior with a missing control scheme is equivalent to having it set to Any (ignoring Inspector representation)?

yes


## [1.8.2] - 2024-04-29

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ public override void OnInspectorGUI()
if (m_ControlSchemeOptions != null && m_ControlSchemeOptions.Length > 1) // Don't show if <Any> is the only option.
{
// Default control scheme picker.

Color currentBg = GUI.backgroundColor;
// if the invalid DefaultControlSchemeName is selected set the popup draw the BG color in red
if (m_InvalidDefaultControlSchemeName != null && m_SelectedDefaultControlScheme == 1)
GUI.backgroundColor = Color.red;
var selected = EditorGUILayout.Popup(m_DefaultControlSchemeText, m_SelectedDefaultControlScheme,
m_ControlSchemeOptions);
if (selected != m_SelectedDefaultControlScheme)
Expand All @@ -93,13 +96,20 @@ public override void OnInspectorGUI()
{
m_DefaultControlSchemeProperty.stringValue = null;
}
// if there is an invalid default scheme name it will be at rank 1.
// we use m_InvalidDefaultControlSchemeName to prevent usage of the string with "name<Not Found>"
else if (m_InvalidDefaultControlSchemeName != null && selected == 1)
{
m_DefaultControlSchemeProperty.stringValue = m_InvalidDefaultControlSchemeName;
}
else
{
m_DefaultControlSchemeProperty.stringValue =
m_ControlSchemeOptions[selected].text;
m_DefaultControlSchemeProperty.stringValue = m_ControlSchemeOptions[selected].text;
}
m_SelectedDefaultControlScheme = selected;
}
// Restore the initial color
GUI.backgroundColor = currentBg;

var neverAutoSwitchValueOld = m_NeverAutoSwitchControlSchemesProperty.boolValue;
var neverAutoSwitchValueNew = !EditorGUILayout.Toggle(m_AutoSwitchText, !neverAutoSwitchValueOld);
Expand Down Expand Up @@ -424,6 +434,7 @@ private void OnActionAssetChange()
m_ActionNames = null;
m_SelectedDefaultActionMap = -1;
m_SelectedDefaultControlScheme = -1;
m_InvalidDefaultControlSchemeName = null;
return;
}

Expand Down Expand Up @@ -486,22 +497,36 @@ void AddEntry(InputAction action, PlayerInput.ActionEvent actionEvent)

// Read out control schemes.
var selectedDefaultControlScheme = playerInput.defaultControlScheme;
m_InvalidDefaultControlSchemeName = null;
m_SelectedDefaultControlScheme = 0;
var controlSchemes = asset.controlSchemes;
m_ControlSchemeOptions = new GUIContent[controlSchemes.Count + 1];
m_ControlSchemeOptions[0] = new GUIContent(EditorGUIUtility.TrTextContent("<Any>"));
////TODO: sort alphabetically
for (var i = 0; i < controlSchemes.Count; ++i)
{
var name = controlSchemes[i].name;
m_ControlSchemeOptions[i + 1] = new GUIContent(name);
////TODO: sort alphabetically and ensure that the order is the same in the schemes editor
var controlSchemesNames = asset.controlSchemes.Select(cs => cs.name).ToList();

if (selectedDefaultControlScheme != null && string.Compare(name, selectedDefaultControlScheme,
StringComparison.InvariantCultureIgnoreCase) == 0)
m_SelectedDefaultControlScheme = i + 1;
// try to find the selected Default Control Scheme
if (!string.IsNullOrEmpty(selectedDefaultControlScheme))
{
// +1 since <Any> will be the first in the list
m_SelectedDefaultControlScheme = 1 + controlSchemesNames.FindIndex(name => string.Compare(name, selectedDefaultControlScheme,
StringComparison.InvariantCultureIgnoreCase) == 0);
// if not found, will insert the invalid name next to <Any>
if (m_SelectedDefaultControlScheme == 0)
{
m_InvalidDefaultControlSchemeName = selectedDefaultControlScheme;
m_SelectedDefaultControlScheme = 1;
controlSchemesNames.Insert(0, $"{selectedDefaultControlScheme}{L10n.Tr("<Not Found>")}");
}
}
if (m_SelectedDefaultControlScheme <= 0)
else
{
playerInput.defaultControlScheme = null;
}

m_ControlSchemeOptions = new GUIContent[controlSchemesNames.Count + 1];
m_ControlSchemeOptions[0] = new GUIContent(EditorGUIUtility.TrTextContent("<Any>"));
for (var i = 0; i < controlSchemesNames.Count; ++i)
{
m_ControlSchemeOptions[i + 1] = new GUIContent(controlSchemesNames[i]);
}

// Read out action maps.
var selectedDefaultActionMap = !string.IsNullOrEmpty(playerInput.defaultActionMap)
Expand Down Expand Up @@ -562,6 +587,7 @@ void AddEntry(InputAction action, PlayerInput.ActionEvent actionEvent)
[NonSerialized] private int[] m_ActionMapIndices;
[NonSerialized] private int m_NumActionMaps;
[NonSerialized] private int m_SelectedDefaultControlScheme;
[NonSerialized] private string m_InvalidDefaultControlSchemeName;
[NonSerialized] private GUIContent[] m_ControlSchemeOptions;
[NonSerialized] private int m_SelectedDefaultActionMap;
[NonSerialized] private GUIContent[] m_ActionMapOptions;
Expand Down