diff --git a/Source/Editor/CustomEditors/Editors/InputEditor.cs b/Source/Editor/CustomEditors/Editors/InputEditor.cs index 3f8aaf093..416626e81 100644 --- a/Source/Editor/CustomEditors/Editors/InputEditor.cs +++ b/Source/Editor/CustomEditors/Editors/InputEditor.cs @@ -1,5 +1,5 @@ - -using System; +// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. + using System.Collections.Generic; using FlaxEngine; using FlaxEngine.GUI; @@ -13,31 +13,24 @@ namespace FlaxEditor.CustomEditors.Editors public class InputEventEditor : CustomEditor { private Dropdown _dropdown; - + /// public override DisplayStyle Style => DisplayStyle.Inline; - + /// public override void Initialize(LayoutElementsContainer layout) { var dropdownElement = layout.Custom(); _dropdown = dropdownElement.CustomControl; - var eventNames = new List(); + var names = new List(); foreach (var mapping in Input.ActionMappings) { - if (eventNames.Contains(mapping.Name)) - continue; - eventNames.Add(mapping.Name); + if (!names.Contains(mapping.Name)) + names.Add(mapping.Name); } - _dropdown.Items = eventNames; - if (Values[0] is InputEvent value) - { - if (eventNames.Contains(value.Name)) - { - _dropdown.SelectedItem = value.Name; - } - } - + _dropdown.Items = names; + if (Values[0] is InputEvent inputEvent && names.Contains(inputEvent.Name)) + _dropdown.SelectedItem = inputEvent.Name; _dropdown.SelectedIndexChanged += OnSelectedIndexChanged; } @@ -45,7 +38,7 @@ namespace FlaxEditor.CustomEditors.Editors { SetValue(new InputEvent(dropdown.SelectedItem)); } - + /// public override void Refresh() { @@ -53,17 +46,11 @@ namespace FlaxEditor.CustomEditors.Editors if (HasDifferentValues) { - } else { - if (Values[0] is InputEvent eventValue) - { - if (_dropdown.Items.Contains(eventValue.Name) && string.Equals(_dropdown.SelectedItem, eventValue.Name, StringComparison.Ordinal)) - { - _dropdown.SelectedItem = eventValue.Name; - } - } + if (Values[0] is InputEvent inputEvent && _dropdown.Items.Contains(inputEvent.Name)) + _dropdown.SelectedItem = inputEvent.Name; } } @@ -73,10 +60,9 @@ namespace FlaxEditor.CustomEditors.Editors if (_dropdown != null) _dropdown.SelectedIndexChanged -= OnSelectedIndexChanged; _dropdown = null; - base.Deinitialize(); } } - + /// /// Default implementation of the inspector used to edit input axis properties. /// @@ -84,7 +70,7 @@ namespace FlaxEditor.CustomEditors.Editors public class InputAxisEditor : CustomEditor { private Dropdown _dropdown; - + /// public override DisplayStyle Style => DisplayStyle.Inline; @@ -93,21 +79,15 @@ namespace FlaxEditor.CustomEditors.Editors { var dropdownElement = layout.Custom(); _dropdown = dropdownElement.CustomControl; - var axisNames = new List(); + var names = new List(); foreach (var mapping in Input.AxisMappings) { - if (axisNames.Contains(mapping.Name)) - continue; - axisNames.Add(mapping.Name); - } - _dropdown.Items = axisNames; - if (Values[0] is InputAxis value) - { - if (axisNames.Contains(value.Name)) - { - _dropdown.SelectedItem = value.Name; - } + if (!names.Contains(mapping.Name)) + names.Add(mapping.Name); } + _dropdown.Items = names; + if (Values[0] is InputAxis inputAxis && names.Contains(inputAxis.Name)) + _dropdown.SelectedItem = inputAxis.Name; _dropdown.SelectedIndexChanged += OnSelectedIndexChanged; } @@ -123,27 +103,20 @@ namespace FlaxEditor.CustomEditors.Editors if (HasDifferentValues) { - } else { - if (Values[0] is InputAxis axisValue) - { - if (_dropdown.Items.Contains(axisValue.Name) && string.Equals(_dropdown.SelectedItem, axisValue.Name, StringComparison.Ordinal)) - { - _dropdown.SelectedItem = axisValue.Name; - } - } + if (Values[0] is InputAxis inputAxis && _dropdown.Items.Contains(inputAxis.Name)) + _dropdown.SelectedItem = inputAxis.Name; } } - + /// protected override void Deinitialize() { if (_dropdown != null) _dropdown.SelectedIndexChanged -= OnSelectedIndexChanged; _dropdown = null; - base.Deinitialize(); } } } diff --git a/Source/Engine/UI/UICanvas.cs b/Source/Engine/UI/UICanvas.cs index 024fb8be0..8cb43af62 100644 --- a/Source/Engine/UI/UICanvas.cs +++ b/Source/Engine/UI/UICanvas.cs @@ -282,7 +282,7 @@ namespace FlaxEngine [EditorOrder(530), EditorDisplay("Navigation", "Navigate Left")] [Tooltip("The input action for performing UI navigation Left (from Input Settings).")] public InputEvent NavigateLeft { get; set; } = new InputEvent("NavigateLeft"); - + /// /// The input action for performing UI navigation Right (from Input Settings). /// @@ -775,7 +775,7 @@ namespace FlaxEngine jsonWriter.WriteValue(NavigateSubmit.Name); jsonWriter.WriteEndObject(); } - + jsonWriter.WriteEndObject(); }