diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 1a8cd8269e..809d8ab632 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -15,6 +15,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed an issue where a composite binding would not be consecutively triggered after ResetDevice() has been called from the associated 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 an issue where a composite binding would not be consecutively triggered after disabling actions while there are action modifiers in progress [ISXB-505](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-505). +- Fixed prefabs and 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) ## [1.8.2] - 2024-04-29 diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputEditor.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputEditor.cs index 985dad7ad7..265f496b71 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputEditor.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputEditor.cs @@ -84,25 +84,42 @@ public override void OnInspectorGUI() if (m_ControlSchemeOptions != null && m_ControlSchemeOptions.Length > 1) // Don't show if is the only option. { // Default control scheme picker. - - var selected = EditorGUILayout.Popup(m_DefaultControlSchemeText, m_SelectedDefaultControlScheme, - m_ControlSchemeOptions); + 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 rect = EditorGUILayout.GetControlRect(); + var label = EditorGUI.BeginProperty(rect, m_DefaultControlSchemeText, m_DefaultControlSchemeProperty); + var selected = EditorGUI.Popup(rect, label, m_SelectedDefaultControlScheme, m_ControlSchemeOptions); + EditorGUI.EndProperty(); if (selected != m_SelectedDefaultControlScheme) { if (selected == 0) { 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" + 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; + + rect = EditorGUILayout.GetControlRect(); + label = EditorGUI.BeginProperty(rect, m_AutoSwitchText, m_NeverAutoSwitchControlSchemesProperty); var neverAutoSwitchValueOld = m_NeverAutoSwitchControlSchemesProperty.boolValue; - var neverAutoSwitchValueNew = !EditorGUILayout.Toggle(m_AutoSwitchText, !neverAutoSwitchValueOld); + var neverAutoSwitchValueNew = !EditorGUI.Toggle(rect, label, !neverAutoSwitchValueOld); + EditorGUI.EndProperty(); if (neverAutoSwitchValueOld != neverAutoSwitchValueNew) { m_NeverAutoSwitchControlSchemesProperty.boolValue = neverAutoSwitchValueNew; @@ -112,9 +129,11 @@ public override void OnInspectorGUI() if (m_ActionMapOptions != null && m_ActionMapOptions.Length > 0) { // Default action map picker. - - var selected = EditorGUILayout.Popup(m_DefaultActionMapText, m_SelectedDefaultActionMap, + var rect = EditorGUILayout.GetControlRect(); + var label = EditorGUI.BeginProperty(rect, m_DefaultActionMapText, m_DefaultActionMapProperty); + var selected = EditorGUI.Popup(rect, label, m_SelectedDefaultActionMap, m_ActionMapOptions); + EditorGUI.EndProperty(); if (selected != m_SelectedDefaultActionMap) { if (selected == 0) @@ -424,6 +443,7 @@ private void OnActionAssetChange() m_ActionNames = null; m_SelectedDefaultActionMap = -1; m_SelectedDefaultControlScheme = -1; + m_InvalidDefaultControlSchemeName = null; return; } @@ -486,22 +506,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("")); - ////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 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 + if (m_SelectedDefaultControlScheme == 0) + { + m_InvalidDefaultControlSchemeName = selectedDefaultControlScheme; + m_SelectedDefaultControlScheme = 1; + controlSchemesNames.Insert(0, $"{selectedDefaultControlScheme}{L10n.Tr("")}"); + } } - if (m_SelectedDefaultControlScheme <= 0) + else + { playerInput.defaultControlScheme = null; + } + + m_ControlSchemeOptions = new GUIContent[controlSchemesNames.Count + 1]; + m_ControlSchemeOptions[0] = new GUIContent(EditorGUIUtility.TrTextContent("")); + 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) @@ -562,6 +596,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;