Add set order in parent for spawning actor with a parent in editor.

This commit is contained in:
Chandler Cox
2025-04-07 21:10:36 -05:00
parent 4a10905464
commit 2452face38
5 changed files with 22 additions and 16 deletions

View File

@@ -310,8 +310,9 @@ namespace FlaxEditor.Modules
/// </summary>
/// <param name="actor">The actor.</param>
/// <param name="parent">The parent actor. Set null as default.</param>
/// <param name="orderInParent">The order under the parent to put the spawned actor.</param>
/// <param name="autoSelect">True if automatically select the spawned actor, otherwise false.</param>
public void Spawn(Actor actor, Actor parent = null, bool autoSelect = true)
public void Spawn(Actor actor, Actor parent = null, int orderInParent = -1, bool autoSelect = true)
{
bool isPlayMode = Editor.StateMachine.IsPlayMode;
@@ -323,6 +324,10 @@ namespace FlaxEditor.Modules
// Add it
Level.SpawnActor(actor, parent);
// Set order if given
if (orderInParent != -1)
actor.OrderInParent = orderInParent;
// Peek spawned node
var actorNode = Editor.Instance.Scene.GetActorNode(actor);
if (actorNode == null)
@@ -568,7 +573,7 @@ namespace FlaxEditor.Modules
{
Position = center,
};
Editor.SceneEditing.Spawn(parent, null, false);
Editor.SceneEditing.Spawn(parent, null, -1, false);
using (new UndoMultiBlock(Undo, actors, "Reparent actors"))
{
for (int i = 0; i < selection.Count; i++)

View File

@@ -32,9 +32,9 @@ namespace FlaxEditor.Modules
}
/// <inheritdoc />
public override void Spawn(Actor actor, Actor parent)
public override void Spawn(Actor actor, Actor parent, int orderInParent = -1)
{
_editor.SceneEditing.Spawn(actor, parent);
_editor.SceneEditing.Spawn(actor, parent, orderInParent);
}
/// <inheritdoc />

View File

@@ -690,9 +690,8 @@ namespace FlaxEditor.SceneGraph.GUI
if (_dragAssets.Objects[i] is not PrefabItem)
actor.Transform = Transform.Identity;
var previousTrans = actor.Transform;
ActorNode.Root.Spawn(actor, spawnParent);
ActorNode.Root.Spawn(actor, spawnParent, newOrder);
actor.LocalTransform = previousTrans;
actor.OrderInParent = newOrder;
}
result = DragDropEffect.Move;
}
@@ -710,8 +709,7 @@ namespace FlaxEditor.SceneGraph.GUI
}
actor.StaticFlags = newParent.StaticFlags;
actor.Name = item.Name;
ActorNode.Root.Spawn(actor, newParent);
actor.OrderInParent = newOrder;
ActorNode.Root.Spawn(actor, newParent, newOrder);
}
result = DragDropEffect.Move;
}
@@ -733,8 +731,7 @@ namespace FlaxEditor.SceneGraph.GUI
StaticFlags = newParent.StaticFlags,
Name = item.Name,
};
ActorNode.Root.Spawn(uiControl, newParent);
uiControl.OrderInParent = newOrder;
ActorNode.Root.Spawn(uiControl, newParent, newOrder);
}
result = DragDropEffect.Move;
}
@@ -761,8 +758,7 @@ namespace FlaxEditor.SceneGraph.GUI
actor.StaticFlags = spawnParent.StaticFlags;
actor.Name = actorType.Name;
actor.Transform = spawnParent.Transform;
ActorNode.Root.Spawn(actor, spawnParent);
actor.OrderInParent = newOrder;
ActorNode.Root.Spawn(actor, spawnParent, newOrder);
}
else if (scriptType != ScriptType.Null)
{

View File

@@ -159,7 +159,7 @@ namespace FlaxEditor.SceneGraph
/// </summary>
/// <param name="actor">The actor.</param>
/// <param name="parent">The parent.</param>
public abstract void Spawn(Actor actor, Actor parent);
public abstract void Spawn(Actor actor, Actor parent, int orderInParent = -1);
/// <summary>
/// Gets the undo.

View File

@@ -32,9 +32,9 @@ namespace FlaxEditor.Windows.Assets
}
/// <inheritdoc />
public override void Spawn(Actor actor, Actor parent)
public override void Spawn(Actor actor, Actor parent, int orderInParent)
{
_window.Spawn(actor, parent);
_window.Spawn(actor, parent, orderInParent);
}
/// <inheritdoc />
@@ -486,7 +486,8 @@ namespace FlaxEditor.Windows.Assets
/// </summary>
/// <param name="actor">The actor.</param>
/// <param name="parent">The parent.</param>
public void Spawn(Actor actor, Actor parent)
/// <param name="orderInParent">The order of the actor under the parent.</param>
public void Spawn(Actor actor, Actor parent, int orderInParent = -1)
{
if (actor == null)
throw new ArgumentNullException(nameof(actor));
@@ -494,6 +495,10 @@ namespace FlaxEditor.Windows.Assets
// Link it
actor.Parent = parent ?? throw new ArgumentNullException(nameof(parent));
// Set order in parent
if (orderInParent != -1)
actor.OrderInParent = orderInParent;
// Peek spawned node
var actorNode = SceneGraphFactory.FindNode(actor.ID) as ActorNode ?? SceneGraphFactory.BuildActorNode(actor);
if (actorNode == null)