diff --git a/Source/Editor/CustomEditors/Dedicated/RagdollEditor.cs b/Source/Editor/CustomEditors/Dedicated/RagdollEditor.cs index 175312b6a..17387a202 100644 --- a/Source/Editor/CustomEditors/Dedicated/RagdollEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/RagdollEditor.cs @@ -160,7 +160,7 @@ namespace FlaxEditor.CustomEditors.Dedicated var actions = new List(); foreach (var body in bodies) { - var action = new Actions.DeleteActorsAction(new List { SceneGraphFactory.FindNode(body.ID) }); + var action = new Actions.DeleteActorsAction(body); action.Do(); actions.Add(action); } @@ -185,7 +185,7 @@ namespace FlaxEditor.CustomEditors.Dedicated var body = bodies.FirstOrDefault(x => x.Name == name); if (body != null) { - var action = new Actions.DeleteActorsAction(new List { SceneGraphFactory.FindNode(body.ID) }); + var action = new Actions.DeleteActorsAction(body); action.Do(); Presenter.Undo?.AddAction(action); } @@ -224,7 +224,7 @@ namespace FlaxEditor.CustomEditors.Dedicated else { // Remove joint that will no longer be valid - var action = new Actions.DeleteActorsAction(new List { SceneGraphFactory.FindNode(joint.ID) }); + var action = new Actions.DeleteActorsAction(joint); action.Do(); Presenter.Undo?.AddAction(action); } @@ -233,7 +233,7 @@ namespace FlaxEditor.CustomEditors.Dedicated // Remove body { - var action = new Actions.DeleteActorsAction(new List { SceneGraphFactory.FindNode(body.ID) }); + var action = new Actions.DeleteActorsAction(body); action.Do(); Presenter.Undo?.AddAction(action); } diff --git a/Source/Editor/Modules/SceneEditingModule.cs b/Source/Editor/Modules/SceneEditingModule.cs index faeca2520..df9009cc8 100644 --- a/Source/Editor/Modules/SceneEditingModule.cs +++ b/Source/Editor/Modules/SceneEditingModule.cs @@ -333,7 +333,7 @@ namespace FlaxEditor.Modules actorNode.PostSpawn(); // Create undo action - IUndoAction action = new DeleteActorsAction(new List(1) { actorNode }, true); + IUndoAction action = new DeleteActorsAction(actorNode, true); if (autoSelect) { var before = Selection.ToArray(); diff --git a/Source/Editor/Undo/Actions/DeleteActorsAction.cs b/Source/Editor/Undo/Actions/DeleteActorsAction.cs index 57352a12d..6b8ebee56 100644 --- a/Source/Editor/Undo/Actions/DeleteActorsAction.cs +++ b/Source/Editor/Undo/Actions/DeleteActorsAction.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using FlaxEditor.SceneGraph; -using FlaxEditor.Scripting; using FlaxEngine; using FlaxEngine.Utilities; @@ -25,6 +24,9 @@ namespace FlaxEditor.Actions [Serialize] private Guid[] _nodeParentsIDs; + [Serialize] + private int[] _nodeParentsOrders; + [Serialize] private Guid[] _prefabIds; @@ -43,12 +45,35 @@ namespace FlaxEditor.Actions [Serialize] protected List _nodeParents; + /// + /// Initializes a new instance of the class. + /// + /// The actor. + /// If set to true action will be inverted - instead of delete it will create actors. + /// If set to true action will be preserve actors order when performing undo. + internal DeleteActorsAction(Actor actor, bool isInverted = false, bool preserveOrder = true) + : this(new List(1) { SceneGraphFactory.FindNode(actor.ID) }, isInverted, preserveOrder) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The object. + /// If set to true action will be inverted - instead of delete it will create actors. + /// If set to true action will be preserve actors order when performing undo. + internal DeleteActorsAction(SceneGraphNode node, bool isInverted = false, bool preserveOrder = true) + : this(new List(1) { node }, isInverted, preserveOrder) + { + } + /// /// Initializes a new instance of the class. /// /// The objects. - /// If set to true action will be inverted - instead of delete it will be create actors. - internal DeleteActorsAction(List nodes, bool isInverted = false) + /// If set to true action will be inverted - instead of delete it will create actors. + /// If set to true action will be preserve actors order when performing undo. + internal DeleteActorsAction(List nodes, bool isInverted = false, bool preserveOrder = true) { _isInverted = isInverted; @@ -82,6 +107,12 @@ namespace FlaxEditor.Actions _nodeParentsIDs = new Guid[_nodeParents.Count]; for (int i = 0; i < _nodeParentsIDs.Length; i++) _nodeParentsIDs[i] = _nodeParents[i].ID; + if (preserveOrder) + { + _nodeParentsOrders = new int[_nodeParents.Count]; + for (int i = 0; i < _nodeParentsOrders.Length; i++) + _nodeParentsOrders[i] = _nodeParents[i].OrderInParent; + } // Serialize actors _actorsData = Actor.ToBytes(actors.ToArray()); @@ -122,6 +153,7 @@ namespace FlaxEditor.Actions { _actorsData = null; _nodeParentsIDs = null; + _nodeParentsOrders = null; _prefabIds = null; _prefabObjectIds = null; _nodeParents.Clear(); @@ -211,6 +243,8 @@ namespace FlaxEditor.Actions if (foundNode is ActorNode node) { nodes.Add(node); + if (_nodeParentsOrders != null) + node.Actor.OrderInParent = _nodeParentsOrders[i]; } } nodes.BuildNodesParents(_nodeParents); diff --git a/Source/Editor/Undo/Actions/PasteActorsAction.cs b/Source/Editor/Undo/Actions/PasteActorsAction.cs index 68b2b755e..87a21ec2d 100644 --- a/Source/Editor/Undo/Actions/PasteActorsAction.cs +++ b/Source/Editor/Undo/Actions/PasteActorsAction.cs @@ -165,7 +165,7 @@ namespace FlaxEditor.Actions var child = children[j]; if (child != actor && child.Name == name) { - string newName = Utilities.Utils.IncrementNameNumber(name, x => IsNameValid(x)); + string newName = Utilities.Utils.IncrementNameNumber(name, IsNameValid); foundNamesResults[newName] = true; actor.Name = newName; // Multiple actors may have the same name, continue diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index 0e187ac7b..2615f09fa 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -1764,14 +1764,6 @@ bool Actor::FromBytes(const Span& data, Array& output, ISerializeM } Scripting::ObjectsLookupIdMapping.Set(nullptr); - // Link objects - //for (int32 i = 0; i < objectsCount; i++) - { - //SceneObject* obj = sceneObjects->At(i); - // TODO: post load or post spawn? - //obj->PostLoad(); - } - // Update objects order //for (int32 i = 0; i < objectsCount; i++) {