From d2888d00078948cd8d8cb15e100eefca4af908fe Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sat, 9 Jan 2021 23:21:31 +0100 Subject: [PATCH] Adding Convert feature to Actor context menu. --- .../Windows/SceneTreeWindow.ContextMenu.cs | 22 ++++++++++++++++ Source/Editor/Windows/SceneTreeWindow.cs | 25 ++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs index b6756b438..87f13b13f 100644 --- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs +++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs @@ -55,6 +55,28 @@ namespace FlaxEditor.Windows b = contextMenu.AddButton("Duplicate", Editor.SceneEditing.Duplicate); b.Enabled = hasSthSelected; + var convertMenu = contextMenu.AddChildMenu("Convert"); + var convertActorCm = convertMenu.ContextMenu; + for (int i = 0; i < SpawnActorsGroups.Length; i++) + { + var group = SpawnActorsGroups[i]; + + if (group.Types.Length == 1) + { + var type = group.Types[0].Value; + convertActorCm.AddButton(group.Types[0].Key, () => Convert(type)); + } + else + { + var groupCm = convertActorCm.AddChildMenu(group.Name).ContextMenu; + for (int j = 0; j < group.Types.Length; j++) + { + var type = group.Types[j].Value; + groupCm.AddButton(group.Types[j].Key, () => Convert(type)); + } + } + } + b = contextMenu.AddButton("Delete", Editor.SceneEditing.Delete); b.Enabled = hasSthSelected; diff --git a/Source/Editor/Windows/SceneTreeWindow.cs b/Source/Editor/Windows/SceneTreeWindow.cs index 3db4df799..997f764d2 100644 --- a/Source/Editor/Windows/SceneTreeWindow.cs +++ b/Source/Editor/Windows/SceneTreeWindow.cs @@ -122,7 +122,30 @@ namespace FlaxEditor.Windows // Spawn it Editor.SceneEditing.Spawn(actor, parentActor); } - + + private void Convert(Type to) + { + if (!Editor.SceneEditing.HasSthSelected || !(Editor.SceneEditing.Selection[0] is ActorNode)) + return; + Actor old = ((ActorNode)Editor.SceneEditing.Selection[0]).Actor; + Actor actor = (Actor)FlaxEngine.Object.New(to); + actor.Transform = old.Transform; + if (old.Parent != null) + actor.Parent = old.Parent; + actor.StaticFlags = old.StaticFlags; + actor.HideFlags = old.HideFlags; + actor.Layer = old.Layer; + actor.Tag = old.Tag; + actor.Name = old.Name; + actor.IsActive = old.IsActive; + for (var i = old.Children.Length - 1; i >= 0 ; i--) + { + old.Children[i].Parent = actor; + } + Editor.SceneEditing.Delete(); + Editor.SceneEditing.Spawn(actor, actor.Parent); + } + /// /// Focuses search box. ///