diff --git a/Source/Editor/Modules/SceneEditingModule.cs b/Source/Editor/Modules/SceneEditingModule.cs index 68d327574..49689d3a7 100644 --- a/Source/Editor/Modules/SceneEditingModule.cs +++ b/Source/Editor/Modules/SceneEditingModule.cs @@ -216,35 +216,6 @@ namespace FlaxEditor.Modules } } - private void OnDirty(List objects) - { - var options = Editor.Options.Options; - var isPlayMode = Editor.StateMachine.IsPlayMode; - - // Auto CSG mesh rebuild - if (!isPlayMode && options.General.AutoRebuildCSG) - { - foreach (var obj in objects) - { - if (obj is ActorNode node && node.Actor is BoxBrush) - node.Actor.Scene.BuildCSG(options.General.AutoRebuildCSGTimeoutMs); - } - } - - // Auto NavMesh rebuild - if (!isPlayMode && options.General.AutoRebuildNavMesh) - { - foreach (var obj in objects) - { - if (obj is ActorNode node && node.Actor && node.Actor.Scene && node.AffectsNavigationWithChildren) - { - var bounds = node.Actor.BoxWithChildren; - Navigation.BuildNavMesh(node.Actor.Scene, bounds, options.General.AutoRebuildNavMeshTimeoutMs); - } - } - } - } - private static bool SelectActorsUsingAsset(Guid assetId, ref Guid id, Dictionary scannedAssets) { // Check for asset match or try to use cache @@ -478,8 +449,6 @@ namespace FlaxEditor.Modules SelectionDeleteEnd?.Invoke(); - OnDirty(objects); - if (isSceneTreeFocus) Editor.Windows.SceneWin.Focus(); } diff --git a/Source/Editor/SceneGraph/Actors/NavMeshBoundsVolumeNode.cs b/Source/Editor/SceneGraph/Actors/NavMeshBoundsVolumeNode.cs index 66ed32be4..a4780643d 100644 --- a/Source/Editor/SceneGraph/Actors/NavMeshBoundsVolumeNode.cs +++ b/Source/Editor/SceneGraph/Actors/NavMeshBoundsVolumeNode.cs @@ -11,6 +11,9 @@ namespace FlaxEditor.SceneGraph.Actors [HideInEditor] public sealed class NavMeshBoundsVolumeNode : BoxVolumeNode { + /// + public override bool AffectsNavigation => true; + /// public NavMeshBoundsVolumeNode(Actor actor) : base(actor) diff --git a/Source/Editor/Undo/Actions/DeleteActorsAction.cs b/Source/Editor/Undo/Actions/DeleteActorsAction.cs index 3dc7b77cf..5f7b0b727 100644 --- a/Source/Editor/Undo/Actions/DeleteActorsAction.cs +++ b/Source/Editor/Undo/Actions/DeleteActorsAction.cs @@ -33,9 +33,12 @@ namespace FlaxEditor.Actions [Serialize] private bool _isInverted; - /// - /// The node parents. - /// + [Serialize] + private bool _affectsCSG; + + [Serialize] + private bool _affectsNavigation; + [Serialize] protected List _nodeParents; @@ -74,6 +77,7 @@ namespace FlaxEditor.Actions // Collect parent nodes to delete _nodeParents = new List(nodes.Count); deleteNodes.BuildNodesParents(_nodeParents); + OnDirtyInit(); _nodeParentsIDs = new Guid[_nodeParents.Count]; for (int i = 0; i < _nodeParentsIDs.Length; i++) _nodeParentsIDs[i] = _nodeParents[i].ID; @@ -128,10 +132,10 @@ namespace FlaxEditor.Actions protected virtual void Delete() { // Remove objects + OnDirty(); for (int i = 0; i < _nodeParents.Count; i++) { var node = _nodeParents[i]; - Editor.Instance.Scene.MarkSceneEdited(node.ParentScene); node.Delete(); } _nodeParents.Clear(); @@ -209,11 +213,64 @@ namespace FlaxEditor.Actions } } nodes.BuildNodesParents(_nodeParents); + OnDirty(); + } - // Mark scenes as modified + private void OnDirtyInit() + { for (int i = 0; i < _nodeParents.Count; i++) { - Editor.Instance.Scene.MarkSceneEdited(_nodeParents[i].ParentScene); + if (_nodeParents[i] is ActorNode node && node.Actor is BoxBrush) + { + _affectsCSG = true; + break; + } + } + + for (int i = 0; i < _nodeParents.Count; i++) + { + if (_nodeParents[i] is ActorNode actorNode && actorNode.AffectsNavigationWithChildren) + { + _affectsNavigation = true; + break; + } + } + } + + private void OnDirty() + { + // Mark scene as modified + foreach (var obj in _nodeParents) + { + Editor.Instance.Scene.MarkSceneEdited(obj.ParentScene); + } + + var editor = Editor.Instance; + if (editor.StateMachine.IsPlayMode) + return; + var options = editor.Options.Options; + + // Auto CSG mesh rebuild + if (_affectsCSG && options.General.AutoRebuildCSG) + { + for (var i = 0; i < _nodeParents.Count; i++) + { + if (_nodeParents[i] is ActorNode node && node.Actor is BoxBrush) + node.Actor.Scene.BuildCSG(options.General.AutoRebuildCSGTimeoutMs); + } + } + + // Auto NavMesh rebuild + if (_affectsNavigation && options.General.AutoRebuildNavMesh) + { + for (var i = 0; i < _nodeParents.Count; i++) + { + if (_nodeParents[i] is ActorNode node && node.Actor && node.Actor.Scene && node.AffectsNavigationWithChildren) + { + var bounds = node.Actor.BoxWithChildren; + Navigation.BuildNavMesh(node.Actor.Scene, bounds, options.General.AutoRebuildNavMeshTimeoutMs); + } + } } } }