private void OnActorParentChanged(Actor actor, Actor prevParent) { ActorNode node = null; var parentNode = GetActorNode(actor.Parent); // Try use previous parent actor to find actor node var prevParentNode = GetActorNode(prevParent); if (prevParentNode != null) { // If should be one of the children node = prevParentNode.FindChildActor(actor); // Search whole tree if node was not found if (node == null) { node = GetActorNode(actor); } } else if (parentNode != null) { // Create new node for that actor (user may unlink it from the scene before and now link it) node = SceneGraphFactory.BuildActorNode(actor); } if (node == null) { return; } // Get the new parent node (may be missing) if (parentNode != null) { // Change parent node.TreeNode.UnlockChildrenRecursive(); node.ParentNode = parentNode; } else { // Check if actor is selected in editor if (Editor.SceneEditing.Selection.Contains(node)) { Editor.SceneEditing.Deselect(); } // Remove node (user may unlink actor from the scene but not destroy the actor) node.Dispose(); } }
private void OnActorDeleted(ActorNode node) { for (int i = 0; i < node.ChildNodes.Count; i++) { if (node.ChildNodes[i] is ActorNode child) { i--; OnActorDeleted(child); } } ActorRemoved?.Invoke(node); // Cleanup part of the graph node.Dispose(); }
private void OnActorParentChanged(Actor actor, Actor prevParent) { ActorNode node = null; // Try use previous parent actor to find actor node var prevParentNode = GetActorNode(prevParent); if (prevParentNode != null) { // If should be one of the children node = prevParentNode.FindChildActor(actor); // Search whole tree if node was not found if (node == null) { node = GetActorNode(actor); } } else { // Create new node for that actor (user may unlink it from the scene before and now link it) node = SceneGraphFactory.BuildActorNode(actor); } if (node == null) { return; } // Get the new parent node (may be missing) var parentNode = GetActorNode(actor.Parent); if (parentNode != null) { // Change parent node.ParentNode = parentNode; } else { // Remove node (user may unlink actor from the scene but not destroy the actor) node.Dispose(); } }