diff --git a/Source/Editor/Modules/SceneModule.cs b/Source/Editor/Modules/SceneModule.cs index a144d6f4c..850e4df3d 100644 --- a/Source/Editor/Modules/SceneModule.cs +++ b/Source/Editor/Modules/SceneModule.cs @@ -41,7 +41,7 @@ namespace FlaxEditor.Modules public override Undo Undo => Editor.Instance.Undo; /// - public override List Selection => _editor.SceneEditing.Selection; + public override ISceneEditingContext SceneContext => _editor.Windows.EditWin; } /// diff --git a/Source/Editor/SceneGraph/ISceneEditingContext.cs b/Source/Editor/SceneGraph/ISceneEditingContext.cs new file mode 100644 index 000000000..63c2cc9c2 --- /dev/null +++ b/Source/Editor/SceneGraph/ISceneEditingContext.cs @@ -0,0 +1,47 @@ +// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. + +using System.Collections.Generic; +using FlaxEditor.SceneGraph; +using FlaxEditor.Viewport; + +namespace FlaxEditor +{ + /// + /// Shared interface for scene editing utilities. + /// + public interface ISceneEditingContext + { + /// + /// Gets the main or last editor viewport used for scene editing within this context. + /// + EditorViewport Viewport { get; } + + /// + /// Gets the list of selected scene graph nodes in the editor context. + /// + List Selection { get; } + + /// + /// Selects the specified node. + /// + /// The node. + /// if set to true will use additive mode, otherwise will clear previous selection. + void Select(SceneGraphNode node, bool additive = false); + + /// + /// Deselects node. + /// + /// The node to deselect. + void Deselect(SceneGraphNode node); + + /// + /// Opends popup for renaming selected objects. + /// + void RenameSelection(); + + /// + /// Focuses selected objects. + /// + void FocusSelection(); + } +} diff --git a/Source/Editor/SceneGraph/RootNode.cs b/Source/Editor/SceneGraph/RootNode.cs index 68044cc1a..e387520da 100644 --- a/Source/Editor/SceneGraph/RootNode.cs +++ b/Source/Editor/SceneGraph/RootNode.cs @@ -168,7 +168,14 @@ namespace FlaxEditor.SceneGraph /// /// Gets the list of selected scene graph nodes in the editor context. + /// [Deprecated in v1.10] /// - public abstract List Selection { get; } + [Obsolete("Use SceneContext.Selection instead.")] + public List Selection => SceneContext.Selection; + + /// + /// Gets the list of selected scene graph nodes in the editor context. + /// + public abstract ISceneEditingContext SceneContext { get; } } } diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index c9600b089..22aa2015e 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -1545,11 +1545,11 @@ namespace FlaxEditor.Utilities return path; } - internal static ISceneContextWindow GetSceneContext(this Control c) + internal static ISceneEditingContext GetSceneContext(this Control c) { - while (c != null && !(c is ISceneContextWindow)) + while (c != null && !(c is ISceneEditingContext)) c = c.Parent; - return c as ISceneContextWindow; + return c as ISceneEditingContext; } } } diff --git a/Source/Editor/Viewport/PrefabWindowViewport.cs b/Source/Editor/Viewport/PrefabWindowViewport.cs index 256b41290..f5ef95bce 100644 --- a/Source/Editor/Viewport/PrefabWindowViewport.cs +++ b/Source/Editor/Viewport/PrefabWindowViewport.cs @@ -10,7 +10,6 @@ using FlaxEditor.SceneGraph; using FlaxEditor.Scripting; using FlaxEditor.Viewport.Cameras; using FlaxEditor.Viewport.Previews; -using FlaxEditor.Viewport.Widgets; using FlaxEditor.Windows.Assets; using FlaxEngine; using FlaxEngine.GUI; diff --git a/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs b/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs index 081573b40..da85d91ff 100644 --- a/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs +++ b/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs @@ -41,7 +41,7 @@ namespace FlaxEditor.Windows.Assets public override Undo Undo => _window.Undo; /// - public override List Selection => _window.Selection; + public override ISceneEditingContext SceneContext => _window; } /// diff --git a/Source/Editor/Windows/Assets/PrefabWindow.Selection.cs b/Source/Editor/Windows/Assets/PrefabWindow.Selection.cs index 85dfc1595..48c0c5685 100644 --- a/Source/Editor/Windows/Assets/PrefabWindow.Selection.cs +++ b/Source/Editor/Windows/Assets/PrefabWindow.Selection.cs @@ -12,10 +12,7 @@ namespace FlaxEditor.Windows.Assets { public sealed partial class PrefabWindow { - /// - /// The current selection (readonly). - /// - public readonly List Selection = new List(); + private readonly List _selection = new List(); /// /// Occurs when selection gets changed. diff --git a/Source/Editor/Windows/Assets/PrefabWindow.cs b/Source/Editor/Windows/Assets/PrefabWindow.cs index 533735c93..03d666478 100644 --- a/Source/Editor/Windows/Assets/PrefabWindow.cs +++ b/Source/Editor/Windows/Assets/PrefabWindow.cs @@ -1,6 +1,7 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. using System; +using System.Collections.Generic; using System.Xml; using FlaxEditor.Content; using FlaxEditor.CustomEditors; @@ -19,7 +20,7 @@ namespace FlaxEditor.Windows.Assets /// /// /// - public sealed partial class PrefabWindow : AssetEditorWindowBase, IPresenterOwner, ISceneContextWindow + public sealed partial class PrefabWindow : AssetEditorWindowBase, IPresenterOwner, ISceneEditingContext { private readonly SplitPanel _split1; private readonly SplitPanel _split2; @@ -54,6 +55,9 @@ namespace FlaxEditor.Windows.Assets /// public PrefabWindowViewport Viewport => _viewport; + /// + public List Selection => _selection; + /// /// Gets the prefab objects properties editor. /// @@ -557,5 +561,8 @@ namespace FlaxEditor.Windows.Assets /// public EditorViewport PresenterViewport => _viewport; + + /// + EditorViewport ISceneEditingContext.Viewport => Viewport; } } diff --git a/Source/Editor/Windows/EditGameWindow.cs b/Source/Editor/Windows/EditGameWindow.cs index 6fb3c1a08..3ff213652 100644 --- a/Source/Editor/Windows/EditGameWindow.cs +++ b/Source/Editor/Windows/EditGameWindow.cs @@ -130,7 +130,7 @@ namespace FlaxEditor.Windows /// /// The viewport control. /// - public readonly MainEditorGizmoViewport Viewport; + public new readonly MainEditorGizmoViewport Viewport; /// /// Initializes a new instance of the class. diff --git a/Source/Editor/Windows/SceneEditorWindow.cs b/Source/Editor/Windows/SceneEditorWindow.cs index 62922ebed..4a20ab7af 100644 --- a/Source/Editor/Windows/SceneEditorWindow.cs +++ b/Source/Editor/Windows/SceneEditorWindow.cs @@ -1,32 +1,18 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. +using System.Collections.Generic; using FlaxEditor.SceneGraph; +using FlaxEditor.Viewport; using FlaxEngine; using FlaxEngine.GUI; namespace FlaxEditor.Windows { - /// - /// Shared interface for scene editing utilities. - /// - public interface ISceneContextWindow - { - /// - /// Opends popup for renaming selected objects. - /// - void RenameSelection(); - - /// - /// Focuses selected objects. - /// - void FocusSelection(); - } - /// /// Base class for editor windows dedicated to scene editing. /// /// - public abstract class SceneEditorWindow : EditorWindow, ISceneContextWindow + public abstract class SceneEditorWindow : EditorWindow, ISceneEditingContext { /// /// Initializes a new instance of the class. @@ -46,6 +32,24 @@ namespace FlaxEditor.Windows Editor.Windows.EditWin.Viewport.FocusSelection(); } + /// + public EditorViewport Viewport => Editor.Windows.EditWin.Viewport; + + /// + public List Selection => Editor.SceneEditing.Selection; + + /// + public void Select(SceneGraphNode node, bool additive = false) + { + Editor.SceneEditing.Select(node, additive); + } + + /// + public void Deselect(SceneGraphNode node) + { + Editor.SceneEditing.Deselect(node); + } + /// public void RenameSelection() {