Adding Convert feature to Actor context menu.

This commit is contained in:
Jean-Baptiste Perrier
2021-01-09 23:21:31 +01:00
parent 0e768694b5
commit d2888d0007
2 changed files with 46 additions and 1 deletions

View File

@@ -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;

View File

@@ -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);
}
/// <summary>
/// Focuses search box.
/// </summary>