From 1ae898918c31a65e9761f2d154b1afa159c300a8 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 1 Feb 2021 16:21:05 +0100 Subject: [PATCH] Add auto-select for spawned actors in the level --- Source/Editor/Modules/SceneEditingModule.cs | 13 +++++++++++-- Source/Editor/Tools/Foliage/FoliageTab.cs | 5 +---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Source/Editor/Modules/SceneEditingModule.cs b/Source/Editor/Modules/SceneEditingModule.cs index 96aefe804..8c0914d58 100644 --- a/Source/Editor/Modules/SceneEditingModule.cs +++ b/Source/Editor/Modules/SceneEditingModule.cs @@ -200,7 +200,8 @@ namespace FlaxEditor.Modules /// /// The actor. /// The parent actor. Set null as default. - public void Spawn(Actor actor, Actor parent = null) + /// True if automatically select the spawned actor, otherwise false. + public void Spawn(Actor actor, Actor parent = null, bool autoSelect = true) { bool isPlayMode = Editor.StateMachine.IsPlayMode; @@ -225,7 +226,15 @@ namespace FlaxEditor.Modules actorNode.PostSpawn(); // Create undo action - var action = new DeleteActorsAction(new List(1) { actorNode }, true); + IUndoAction action = new DeleteActorsAction(new List(1) { actorNode }, true); + if (autoSelect) + { + var before = Selection.ToArray(); + Selection.Clear(); + Selection.Add(actorNode); + OnSelectionChanged(); + action = new MultiUndoAction(action, new SelectionChangeAction(before, Selection.ToArray(), OnSelectionUndo)); + } Undo.AddAction(action); // Mark scene as dirty diff --git a/Source/Editor/Tools/Foliage/FoliageTab.cs b/Source/Editor/Tools/Foliage/FoliageTab.cs index fe4120035..faf71bf1f 100644 --- a/Source/Editor/Tools/Foliage/FoliageTab.cs +++ b/Source/Editor/Tools/Foliage/FoliageTab.cs @@ -183,11 +183,8 @@ namespace FlaxEditor.Tools.Foliage actor.StaticFlags = StaticFlags.FullyStatic; actor.Name = "Foliage"; - // Spawn + // Spawn and select Editor.SceneEditing.Spawn(actor); - - // Select - Editor.SceneEditing.Select(actor); } private void OnSelectionChanged()