diff --git a/Source/Editor/Modules/PrefabsModule.cs b/Source/Editor/Modules/PrefabsModule.cs index 3b3054987..680d710f4 100644 --- a/Source/Editor/Modules/PrefabsModule.cs +++ b/Source/Editor/Modules/PrefabsModule.cs @@ -105,6 +105,30 @@ namespace FlaxEditor.Modules Editor.Windows.ContentWin.NewItem(proxy, actor, contentItem => OnPrefabCreated(contentItem, actor, prefabWindow), actor.Name, rename); } + /// + /// Opens a prefab editor window. + /// + /// + /// Whether the prefab was successfully opened in a Prefab Editor. + public bool OpenPrefab(Guid prefabID = default) + { + if (prefabID == Guid.Empty) + { + var selection = Editor.SceneEditing.Selection.Where(x => x is ActorNode actorNode && actorNode.HasPrefabLink).ToList().BuildNodesParents(); + if (selection.Count == 0 || !((ActorNode)selection[0]).Actor.HasPrefabLink) + return false; + prefabID = ((ActorNode)selection[0]).Actor.PrefabID; + } + + var item = Editor.Instance.ContentDatabase.Find(prefabID); + if (item != null) + { + Editor.Instance.ContentEditing.Open(item); + return true; + } + return false; + } + private void OnPrefabCreated(ContentItem contentItem, Actor actor, Windows.Assets.PrefabWindow prefabWindow) { if (contentItem is PrefabItem prefabItem) diff --git a/Source/Editor/Options/InputOptions.cs b/Source/Editor/Options/InputOptions.cs index 76610f675..157890159 100644 --- a/Source/Editor/Options/InputOptions.cs +++ b/Source/Editor/Options/InputOptions.cs @@ -344,6 +344,9 @@ namespace FlaxEditor.Options [EditorDisplay("Interface"), EditorOrder(2020)] public InputBinding PreviousTab = new InputBinding(KeyboardKeys.Tab, KeyboardKeys.Control, KeyboardKeys.Shift); + [DefaultValue(Windows.SceneNodeDoubleClick.None)] + [EditorDisplay("Interface"), EditorOrder(2030)] + public Windows.SceneNodeDoubleClick DoubleClickSceneNode = Windows.SceneNodeDoubleClick.None; #endregion } } diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs index a107a72f5..a1f8209eb 100644 --- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs +++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs @@ -145,6 +145,7 @@ namespace FlaxEditor.Windows bool hasPrefabLink = canEditScene && isSingleActorSelected && (firstSelection != null ? firstSelection.HasPrefabLink : false); if (hasPrefabLink) { + contextMenu.AddButton("Open Prefab", () => Editor.Prefabs.OpenPrefab(actorNode.Actor.PrefabID)); contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab); contextMenu.AddButton("Break Prefab Link", Editor.Prefabs.BreakLinks); } diff --git a/Source/Editor/Windows/SceneTreeWindow.cs b/Source/Editor/Windows/SceneTreeWindow.cs index 42dc0ffbe..8a500d108 100644 --- a/Source/Editor/Windows/SceneTreeWindow.cs +++ b/Source/Editor/Windows/SceneTreeWindow.cs @@ -382,6 +382,29 @@ namespace FlaxEditor.Windows return false; } + + /// + public override bool OnMouseDoubleClick(Float2 location, MouseButton button) + { + if(button == MouseButton.Left) + { + switch (Editor.Options.Options.Input.DoubleClickSceneNode) + { + case SceneNodeDoubleClick.RenameActor: + Rename(); + return true; + case SceneNodeDoubleClick.FocusActor: + Editor.Windows.EditWin.Viewport.FocusSelection(); + return true; + case SceneNodeDoubleClick.OpenPrefab: + return Editor.Prefabs.OpenPrefab(); + case SceneNodeDoubleClick.None: + default: + return base.OnMouseDoubleClick(location, button); + } + } + return base.OnMouseDoubleClick(location, button); + } /// public override void OnLostFocus() @@ -570,4 +593,28 @@ namespace FlaxEditor.Windows base.OnDestroy(); } } + + /// + /// Action to perform when a Scene Node receive a double mouse click (Left) + /// + [Serializable] + public enum SceneNodeDoubleClick + { + /// + /// No action is performed + /// + None, + /// + /// Rename the Scene Node + /// + RenameActor, + /// + /// Focus the Scene Node object in the Scene View + /// + FocusActor, + /// + /// If possible, open the scene node in an associated Editor (e.g. Prefab Editor) + /// + OpenPrefab + } }