Added "Create parent for selected actors" context menu button

This commit is contained in:
whocares77
2023-12-19 11:02:18 +03:00
parent 72f45afa45
commit 4e2f0cd22c
4 changed files with 45 additions and 0 deletions

View File

@@ -534,6 +534,38 @@ namespace FlaxEditor.Modules
Delete();
}
/// <summary>
/// Create parent for selected actors.
/// </summary>
public void CreateParentForSelectedActors()
{
Actor actor = new EmptyActor();
Editor.SceneEditing.Spawn(actor, null, false);
List<SceneGraphNode> selection = Editor.SceneEditing.Selection;
for (int i = 0; i < selection.Count; i++)
{
if (selection[i] is ActorNode node)
{
if (node.ParentNode != node.ParentScene) // if parent node is not Scene
{
if (selection.Contains(node.ParentNode))
{
return; // if parent and child nodes selected together, don't touch child nodes
}
else
{ // put created node as child of the Parent Node of node
int parentOrder = node.Actor.OrderInParent;
actor.Parent = node.Actor.Parent;
actor.OrderInParent = parentOrder;
}
}
node.Actor.Parent = actor;
}
}
Editor.SceneEditing.Select(actor);
Editor.Scene.GetActorNode(actor).TreeNode.StartRenaming(Editor.Windows.SceneWin, Editor.Windows.SceneWin.SceneTreePanel);
}
/// <summary>
/// Duplicates the selected objects. Supports undo/redo.
/// </summary>