diff --git a/Source/Editor/Gizmo/TransformGizmo.cs b/Source/Editor/Gizmo/TransformGizmo.cs index afda8484e..08dbaaf3e 100644 --- a/Source/Editor/Gizmo/TransformGizmo.cs +++ b/Source/Editor/Gizmo/TransformGizmo.cs @@ -50,6 +50,44 @@ namespace FlaxEditor.Gizmo { } + /// + /// Helper function, recursivily finds the Prefab Root of node or null + /// + /// The node from which to start + /// + public ActorNode GetPrefabRootInParent(ActorNode node) + { + if (!node.HasPrefabLink) + return null; + if (node.Actor.IsPrefabRoot) + return node; + else if (node.ParentNode is ActorNode parAct) + return GetPrefabRootInParent(parAct); + else + return null; + } + + /// + /// Recursively walks up from the node up to ceiling node(inclusive) or selection(exclusive) + /// + /// The node from which to start + /// The ceiling(inclusive) + /// + public ActorNode RecursiveWalkUpAndFindSomethingBeforeSelectedOrSupplied(ActorNode node, ActorNode ceiling) + { + if (node == ceiling) + return node; + if (node.ParentNode is ActorNode parAct) + { + if (Editor.Instance.SceneEditing.Selection.Contains(node.ParentNode)) + return node; + else + return RecursiveWalkUpAndFindSomethingBeforeSelectedOrSupplied(parAct, ceiling); + } + else + return null; + } + /// public override void Pick() { @@ -100,6 +138,16 @@ namespace FlaxEditor.Gizmo } } + //select prefab root and then go down until you find the actual item in which case select the prefab root again + if(hit is ActorNode act) + { + ActorNode prefabRoot = GetPrefabRootInParent(act); + if (prefabRoot != null && act != prefabRoot) + { + hit = RecursiveWalkUpAndFindSomethingBeforeSelectedOrSupplied(act, prefabRoot); + } + } + bool addRemove = Owner.IsControlDown; bool isSelected = sceneEditing.Selection.Contains(hit);