diff --git a/Content/Editor/Scripting/ScriptTemplate.h b/Content/Editor/Scripting/ScriptTemplate.h index 61997c011..f52b767e3 100644 --- a/Content/Editor/Scripting/ScriptTemplate.h +++ b/Content/Editor/Scripting/ScriptTemplate.h @@ -5,6 +5,7 @@ API_CLASS() class %module%%class% : public Script { +API_AUTO_SERIALIZATION(); DECLARE_SCRIPTING_TYPE(%class%); // [Script] diff --git a/Source/Editor/Content/AssetItemConverter.cs b/Source/Editor/Content/AssetItemConverter.cs index cad604659..bd074b4ed 100644 --- a/Source/Editor/Content/AssetItemConverter.cs +++ b/Source/Editor/Content/AssetItemConverter.cs @@ -26,8 +26,7 @@ namespace FlaxEditor.Content { if (reader.TokenType == JsonToken.String) { - Guid id; - FlaxEngine.Json.JsonSerializer.ParseID((string)reader.Value, out id); + FlaxEngine.Json.JsonSerializer.ParseID((string)reader.Value, out Guid id); return Editor.Instance.ContentDatabase.Find(id); } diff --git a/Source/Editor/Content/Import/ImportFileEntry.cs b/Source/Editor/Content/Import/ImportFileEntry.cs index e14959f61..80cab94d3 100644 --- a/Source/Editor/Content/Import/ImportFileEntry.cs +++ b/Source/Editor/Content/Import/ImportFileEntry.cs @@ -113,8 +113,7 @@ namespace FlaxEditor.Content.Import extension = extension.ToLower(); // Check if use overriden type - ImportFileEntryHandler createDelegate; - if (FileTypes.TryGetValue(extension, out createDelegate)) + if (FileTypes.TryGetValue(extension, out ImportFileEntryHandler createDelegate)) return createDelegate(ref request); // Use default type diff --git a/Source/Editor/Content/Import/ImportFilesDialog.cs b/Source/Editor/Content/Import/ImportFilesDialog.cs index 2e3633d3b..c1d24f68c 100644 --- a/Source/Editor/Content/Import/ImportFilesDialog.cs +++ b/Source/Editor/Content/Import/ImportFilesDialog.cs @@ -32,7 +32,7 @@ namespace FlaxEditor.Content.Import var result = 0; for (int i = 0; i < _rootNode.ChildrenCount; i++) { - if (_rootNode.Children[i].Tag is ImportFileEntry fileEntry) + if (_rootNode.Children[i].Tag is ImportFileEntry) result++; } return result; @@ -215,8 +215,7 @@ namespace FlaxEditor.Content.Import var entries = new List(_rootNode.ChildrenCount); for (int i = 0; i < _rootNode.ChildrenCount; i++) { - var fileEntry = _rootNode.Children[i].Tag as ImportFileEntry; - if (fileEntry != null) + if (_rootNode.Children[i].Tag is ImportFileEntry fileEntry) entries.Add(fileEntry); } Editor.Instance.ContentImporting.LetThemBeImportedxD(entries); diff --git a/Source/Editor/Content/Items/ContentItem.cs b/Source/Editor/Content/Items/ContentItem.cs index 86741a432..2e75de940 100644 --- a/Source/Editor/Content/Items/ContentItem.cs +++ b/Source/Editor/Content/Items/ContentItem.cs @@ -599,7 +599,7 @@ namespace FlaxEditor.Content public override bool OnShowTooltip(out string text, out Vector2 location, out Rectangle area) { UpdateTooltipText(); - var result = base.OnShowTooltip(out text, out location, out area); + var result = base.OnShowTooltip(out text, out _, out area); location = Size * new Vector2(0.9f, 0.5f); return result; } diff --git a/Source/Editor/Content/Proxy/PrefabProxy.cs b/Source/Editor/Content/Proxy/PrefabProxy.cs index 276bc0d30..0c4c2de6b 100644 --- a/Source/Editor/Content/Proxy/PrefabProxy.cs +++ b/Source/Editor/Content/Proxy/PrefabProxy.cs @@ -74,12 +74,13 @@ namespace FlaxEditor.Content /// public override void Create(string outputPath, object arg) { - var actor = arg as Actor; - if (actor == null) + if (!(arg is Actor actor)) { // Create default prefab root object - actor = new EmptyActor(); - actor.Name = "Root"; + actor = new EmptyActor + { + Name = "Root" + }; // Cleanup it after usage Object.Destroy(actor, 20.0f); diff --git a/Source/Editor/Content/Tree/ContentTreeNode.cs b/Source/Editor/Content/Tree/ContentTreeNode.cs index 4370bc8e7..78cc7f2b5 100644 --- a/Source/Editor/Content/Tree/ContentTreeNode.cs +++ b/Source/Editor/Content/Tree/ContentTreeNode.cs @@ -120,9 +120,8 @@ namespace FlaxEditor.Content } else { - QueryFilterHelper.Range[] ranges; var text = Text; - if (QueryFilterHelper.Match(filterText, text, out ranges)) + if (QueryFilterHelper.Match(filterText, text, out QueryFilterHelper.Range[] ranges)) { // Update highlights if (_highlights == null) diff --git a/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs b/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs index b8491abfa..3f41bb9a6 100644 --- a/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/ActorEditor.cs @@ -33,8 +33,10 @@ namespace FlaxEditor.CustomEditors.Dedicated var scriptsMember = type.GetProperty("Scripts"); if (scriptsMember != ScriptMemberInfo.Null) { - var item = new ItemInfo(scriptsMember); - item.CustomEditor = new CustomEditorAttribute(typeof(ScriptsEditor)); + var item = new ItemInfo(scriptsMember) + { + CustomEditor = new CustomEditorAttribute(typeof(ScriptsEditor)) + }; items.Add(item); } @@ -195,9 +197,10 @@ namespace FlaxEditor.CustomEditors.Dedicated private TreeNode CreateDiffNode(CustomEditor editor) { - var node = new TreeNode(false); - - node.Tag = editor; + var node = new TreeNode(false) + { + Tag = editor + }; // Removed Script if (editor is RemovedScriptDummy removed) diff --git a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs index f577e9bae..1e4116894 100644 --- a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs @@ -493,8 +493,10 @@ namespace FlaxEditor.CustomEditors.Dedicated var index = (int)image.Tag; - var cm = new ContextMenu(); - cm.Tag = index; + var cm = new ContextMenu + { + Tag = index + }; cm.AddButton("Remove", OnClickMissingRemove); cm.Show(image, image.Size); } @@ -746,8 +748,10 @@ namespace FlaxEditor.CustomEditors.Dedicated var scriptType = TypeUtils.GetType(script.TypeName); var item = scriptType.ContentItem; - var cm = new ContextMenu(); - cm.Tag = script; + var cm = new ContextMenu + { + Tag = script + }; cm.AddButton("Remove", OnClickRemove).Icon = Editor.Instance.Icons.Cross12; cm.AddButton("Move up", OnClickMoveUp).Enabled = script.OrderInParent > 0; cm.AddButton("Move down", OnClickMoveDown).Enabled = script.OrderInParent < script.Actor.Scripts.Length - 1; diff --git a/Source/Editor/CustomEditors/Editors/GuidEditor.cs b/Source/Editor/CustomEditors/Editors/GuidEditor.cs index 8ff7691b8..acb6f85de 100644 --- a/Source/Editor/CustomEditors/Editors/GuidEditor.cs +++ b/Source/Editor/CustomEditors/Editors/GuidEditor.cs @@ -26,8 +26,7 @@ namespace FlaxEditor.CustomEditors.Editors private void OnEditEnd() { - Guid value; - if (Guid.TryParse(_element.Text, out value)) + if (Guid.TryParse(_element.Text, out Guid value)) { SetValue(value); } diff --git a/Source/Editor/CustomEditors/Editors/QuaternionEditor.cs b/Source/Editor/CustomEditors/Editors/QuaternionEditor.cs index c79d86a0f..338c8eca6 100644 --- a/Source/Editor/CustomEditors/Editors/QuaternionEditor.cs +++ b/Source/Editor/CustomEditors/Editors/QuaternionEditor.cs @@ -63,8 +63,7 @@ namespace FlaxEditor.CustomEditors.Editors float z = ZElement.FloatValue.Value; var isSliding = XElement.IsSliding || YElement.IsSliding || ZElement.IsSliding; var token = isSliding ? this : null; - Quaternion value; - Quaternion.Euler(x, y, z, out value); + Quaternion.Euler(x, y, z, out Quaternion value); SetValue(value, token); } diff --git a/Source/Editor/CustomEditors/Editors/TypeEditor.cs b/Source/Editor/CustomEditors/Editors/TypeEditor.cs index 885109c00..95b9d0f9d 100644 --- a/Source/Editor/CustomEditors/Editors/TypeEditor.cs +++ b/Source/Editor/CustomEditors/Editors/TypeEditor.cs @@ -261,13 +261,17 @@ namespace FlaxEditor.CustomEditors.Editors // Ensure to have valid drag helpers (uses lazy init) if (_dragActors == null) _dragActors = new DragActors(x => IsValid(TypeUtils.GetObjectType(x.Actor))); + if (_dragScripts == null) _dragScripts = new DragScripts(x => IsValid(TypeUtils.GetObjectType(x))); + if (_dragHandlers == null) { - _dragHandlers = new DragHandlers(); - _dragHandlers.Add(_dragActors); - _dragHandlers.Add(_dragScripts); + _dragHandlers = new DragHandlers + { + _dragActors, + _dragScripts + }; } _hasValidDragOver = _dragHandlers.OnDragEnter(data) != DragDropEffect.None; diff --git a/Source/Editor/CustomEditors/Elements/LabelElement.cs b/Source/Editor/CustomEditors/Elements/LabelElement.cs index 4dd2b0302..d8a91b52e 100644 --- a/Source/Editor/CustomEditors/Elements/LabelElement.cs +++ b/Source/Editor/CustomEditors/Elements/LabelElement.cs @@ -21,8 +21,10 @@ namespace FlaxEditor.CustomEditors.Elements /// public LabelElement() { - Label = new Label(0, 0, 100, 18); - Label.HorizontalAlignment = TextAlignment.Near; + Label = new Label(0, 0, 100, 18) + { + HorizontalAlignment = TextAlignment.Near + }; // TODO: auto height for label } diff --git a/Source/Editor/GUI/ContextMenu/ContextMenu.cs b/Source/Editor/GUI/ContextMenu/ContextMenu.cs index 45eff148e..04dded53c 100644 --- a/Source/Editor/GUI/ContextMenu/ContextMenu.cs +++ b/Source/Editor/GUI/ContextMenu/ContextMenu.cs @@ -193,8 +193,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuButton AddButton(string text) { - var item = new ContextMenuButton(this, text); - item.Parent = _panel; + var item = new ContextMenuButton(this, text) + { + Parent = _panel + }; SortButtons(); return item; } @@ -207,8 +209,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuButton AddButton(string text, string shortKeys) { - var item = new ContextMenuButton(this, text, shortKeys); - item.Parent = _panel; + var item = new ContextMenuButton(this, text, shortKeys) + { + Parent = _panel + }; SortButtons(); return item; } @@ -221,8 +225,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuButton AddButton(string text, Action clicked) { - var item = new ContextMenuButton(this, text); - item.Parent = _panel; + var item = new ContextMenuButton(this, text) + { + Parent = _panel + }; item.Clicked += clicked; SortButtons(); return item; @@ -236,8 +242,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuButton AddButton(string text, Action clicked) { - var item = new ContextMenuButton(this, text); - item.Parent = _panel; + var item = new ContextMenuButton(this, text) + { + Parent = _panel + }; item.ButtonClicked += clicked; SortButtons(); return item; @@ -252,8 +260,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuButton AddButton(string text, string shortKeys, Action clicked) { - var item = new ContextMenuButton(this, text, shortKeys); - item.Parent = _panel; + var item = new ContextMenuButton(this, text, shortKeys) + { + Parent = _panel + }; item.Clicked += clicked; SortButtons(); return item; @@ -285,8 +295,10 @@ namespace FlaxEditor.GUI.ContextMenu var item = GetChildMenu(text); if (item == null) { - item = new ContextMenuChildMenu(this, text); - item.Parent = _panel; + item = new ContextMenuChildMenu(this, text) + { + Parent = _panel + }; } return item; @@ -299,8 +311,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuChildMenu AddChildMenu(string text) { - var item = new ContextMenuChildMenu(this, text); - item.Parent = _panel; + var item = new ContextMenuChildMenu(this, text) + { + Parent = _panel + }; return item; } @@ -310,8 +324,10 @@ namespace FlaxEditor.GUI.ContextMenu /// Created context menu item control. public ContextMenuSeparator AddSeparator() { - var item = new ContextMenuSeparator(this); - item.Parent = _panel; + var item = new ContextMenuSeparator(this) + { + Parent = _panel + }; return item; } diff --git a/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs b/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs index 9eb63ee48..bd16f1469 100644 --- a/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs +++ b/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs @@ -113,53 +113,71 @@ namespace FlaxEditor.GUI.Dialogs _onClosed = pickerClosed; // Selector - _cSelector = new ColorSelectorWithSliders(180, 18); - _cSelector.Location = new Vector2(PickerMargin, PickerMargin); + _cSelector = new ColorSelectorWithSliders(180, 18) + { + Location = new Vector2(PickerMargin, PickerMargin), + Parent = this + }; _cSelector.ColorChanged += x => SelectedColor = x; - _cSelector.Parent = this; // Red - _cRed = new FloatValueBox(0, _cSelector.Right + PickerMargin + RGBAMargin + ChannelTextWidth, PickerMargin, 100, 0, float.MaxValue, 0.001f); + _cRed = new FloatValueBox(0, _cSelector.Right + PickerMargin + RGBAMargin + ChannelTextWidth, PickerMargin, 100, 0, float.MaxValue, 0.001f) + { + Parent = this + }; _cRed.ValueChanged += OnRGBAChanged; - _cRed.Parent = this; // Green - _cGreen = new FloatValueBox(0, _cRed.X, _cRed.Bottom + ChannelsMargin, _cRed.Width, 0, float.MaxValue, 0.001f); + _cGreen = new FloatValueBox(0, _cRed.X, _cRed.Bottom + ChannelsMargin, _cRed.Width, 0, float.MaxValue, 0.001f) + { + Parent = this + }; _cGreen.ValueChanged += OnRGBAChanged; - _cGreen.Parent = this; // Blue - _cBlue = new FloatValueBox(0, _cRed.X, _cGreen.Bottom + ChannelsMargin, _cRed.Width, 0, float.MaxValue, 0.001f); + _cBlue = new FloatValueBox(0, _cRed.X, _cGreen.Bottom + ChannelsMargin, _cRed.Width, 0, float.MaxValue, 0.001f) + { + Parent = this + }; _cBlue.ValueChanged += OnRGBAChanged; - _cBlue.Parent = this; // Alpha - _cAlpha = new FloatValueBox(0, _cRed.X, _cBlue.Bottom + ChannelsMargin, _cRed.Width, 0, float.MaxValue, 0.001f); + _cAlpha = new FloatValueBox(0, _cRed.X, _cBlue.Bottom + ChannelsMargin, _cRed.Width, 0, float.MaxValue, 0.001f) + { + Parent = this + }; _cAlpha.ValueChanged += OnRGBAChanged; - _cAlpha.Parent = this; // Hue - _cHue = new FloatValueBox(0, PickerMargin + HSVMargin + ChannelTextWidth, _cSelector.Bottom + PickerMargin, 100, 0, 360); + _cHue = new FloatValueBox(0, PickerMargin + HSVMargin + ChannelTextWidth, _cSelector.Bottom + PickerMargin, 100, 0, 360) + { + Parent = this + }; _cHue.ValueChanged += OnHSVChanged; - _cHue.Parent = this; // Saturation - _cSaturation = new FloatValueBox(0, _cHue.X, _cHue.Bottom + ChannelsMargin, _cHue.Width, 0, 100.0f, 0.1f); + _cSaturation = new FloatValueBox(0, _cHue.X, _cHue.Bottom + ChannelsMargin, _cHue.Width, 0, 100.0f, 0.1f) + { + Parent = this + }; _cSaturation.ValueChanged += OnHSVChanged; - _cSaturation.Parent = this; // Value - _cValue = new FloatValueBox(0, _cHue.X, _cSaturation.Bottom + ChannelsMargin, _cHue.Width, 0, float.MaxValue, 0.1f); + _cValue = new FloatValueBox(0, _cHue.X, _cSaturation.Bottom + ChannelsMargin, _cHue.Width, 0, float.MaxValue, 0.1f) + { + Parent = this + }; _cValue.ValueChanged += OnHSVChanged; - _cValue.Parent = this; // Set valid dialog size based on UI content _dialogSize = Size = new Vector2(_cRed.Right + PickerMargin, 300); // Hex const float hexTextBoxWidth = 80; - _cHex = new TextBox(false, Width - hexTextBoxWidth - PickerMargin, _cSelector.Bottom + PickerMargin, hexTextBoxWidth); - _cHex.Parent = this; + _cHex = new TextBox(false, Width - hexTextBoxWidth - PickerMargin, _cSelector.Bottom + PickerMargin, hexTextBoxWidth) + { + Parent = this + }; _cHex.EditEnd += OnHexChanged; // Cancel @@ -233,8 +251,7 @@ namespace FlaxEditor.GUI.Dialogs if (_disableEvents) return; - Color color; - if (Color.TryParseHex(_cHex.Text, out color)) + if (Color.TryParseHex(_cHex.Text, out Color color)) SelectedColor = color; } diff --git a/Source/Editor/GUI/Docking/DockPanel.cs b/Source/Editor/GUI/Docking/DockPanel.cs index f6e10e653..2865515da 100644 --- a/Source/Editor/GUI/Docking/DockPanel.cs +++ b/Source/Editor/GUI/Docking/DockPanel.cs @@ -597,8 +597,10 @@ namespace FlaxEditor.GUI.Docking if (_tabsProxy == null) { // Create proxy and make set simple full dock - _tabsProxy = new DockPanelProxy(this); - _tabsProxy.Parent = this; + _tabsProxy = new DockPanelProxy(this) + { + Parent = this + }; _tabsProxy.UnlockChildrenRecursive(); } } diff --git a/Source/Editor/GUI/Docking/DockPanelProxy.cs b/Source/Editor/GUI/Docking/DockPanelProxy.cs index 748ae726c..ec8faead4 100644 --- a/Source/Editor/GUI/Docking/DockPanelProxy.cs +++ b/Source/Editor/GUI/Docking/DockPanelProxy.cs @@ -402,8 +402,7 @@ namespace FlaxEditor.GUI.Docking else if (MouseDownWindow != null && _panel.TabsCount > 1) { // Check if mouse left current tab rect - Rectangle currWinRect; - GetTabRect(MouseDownWindow, out currWinRect); + GetTabRect(MouseDownWindow, out Rectangle currWinRect); if (!currWinRect.Contains(location)) { int index = _panel.GetTabIndex(MouseDownWindow); @@ -496,8 +495,10 @@ namespace FlaxEditor.GUI.Docking private void ShowContextMenu(DockWindow tab, ref Vector2 location) { - var menu = new ContextMenu.ContextMenu(); - menu.Tag = tab; + var menu = new ContextMenu.ContextMenu + { + Tag = tab + }; tab.OnShowContextMenu(menu); menu.AddButton("Close", OnTabMenuCloseClicked); menu.AddButton("Close All", OnTabMenuCloseAllClicked); diff --git a/Source/Editor/GUI/Docking/DockWindow.cs b/Source/Editor/GUI/Docking/DockWindow.cs index 56c78efed..0c7f70ffc 100644 --- a/Source/Editor/GUI/Docking/DockWindow.cs +++ b/Source/Editor/GUI/Docking/DockWindow.cs @@ -134,7 +134,7 @@ namespace FlaxEditor.GUI.Docking }); // Link to the master panel - _masterPanel?.linkWindow(this); + _masterPanel?.LinkWindow(this); } /// @@ -409,7 +409,7 @@ namespace FlaxEditor.GUI.Docking Undock(); // Unlink from the master panel - _masterPanel?.unlinkWindow(this); + _masterPanel?.UnlinkWindow(this); base.OnDestroy(); } diff --git a/Source/Editor/GUI/Docking/MasterDockPanel.cs b/Source/Editor/GUI/Docking/MasterDockPanel.cs index a560de195..0293ec0cc 100644 --- a/Source/Editor/GUI/Docking/MasterDockPanel.cs +++ b/Source/Editor/GUI/Docking/MasterDockPanel.cs @@ -97,13 +97,13 @@ namespace FlaxEditor.GUI.Docking return base.HitTest(ref position); } - internal void linkWindow(DockWindow window) + internal void LinkWindow(DockWindow window) { // Add to the windows list Windows.Add(window); } - internal void unlinkWindow(DockWindow window) + internal void UnlinkWindow(DockWindow window) { // Call event to the window window.OnUnlinkInternal(); diff --git a/Source/Editor/GUI/Drag/DragActors.cs b/Source/Editor/GUI/Drag/DragActors.cs index 1948c91e9..437c7d3d0 100644 --- a/Source/Editor/GUI/Drag/DragActors.cs +++ b/Source/Editor/GUI/Drag/DragActors.cs @@ -112,8 +112,7 @@ namespace FlaxEditor.GUI.Drag for (int i = 0; i < ids.Length; i++) { // Find element - Guid id; - if (Guid.TryParse(ids[i], out id)) + if (Guid.TryParse(ids[i], out Guid id)) { var obj = Editor.Instance.Scene.GetActorNode(id); diff --git a/Source/Editor/GUI/Drag/DragScripts.cs b/Source/Editor/GUI/Drag/DragScripts.cs index 38899abbf..d1351f321 100644 --- a/Source/Editor/GUI/Drag/DragScripts.cs +++ b/Source/Editor/GUI/Drag/DragScripts.cs @@ -98,8 +98,7 @@ namespace FlaxEditor.GUI.Drag for (int i = 0; i < ids.Length; i++) { // Find element - Guid id; - if (Guid.TryParse(ids[i], out id)) + if (Guid.TryParse(ids[i], out Guid id)) { var obj = FlaxEngine.Object.Find