Merge branch 'Double-Click-Scene-Node-Actions' of https://github.com/davevanegdom/FlaxEngine into davevanegdom-Double-Click-Scene-Node-Actions

# Conflicts:
#	Source/Editor/Modules/PrefabsModule.cs
#	Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs
This commit is contained in:
Wojtek Figat
2025-02-23 21:18:38 +01:00
4 changed files with 75 additions and 0 deletions

View File

@@ -105,6 +105,30 @@ namespace FlaxEditor.Modules
Editor.Windows.ContentWin.NewItem(proxy, actor, contentItem => OnPrefabCreated(contentItem, actor, prefabWindow), actor.Name, rename);
}
/// <summary>
/// Opens a prefab editor window.
/// </summary>
///
/// <returns>Whether the prefab was successfully opened in a Prefab Editor.</returns>
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)

View File

@@ -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
}
}

View File

@@ -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);
}

View File

@@ -382,6 +382,29 @@ namespace FlaxEditor.Windows
return false;
}
/// <inheritdoc />
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);
}
/// <inheritdoc />
public override void OnLostFocus()
@@ -570,4 +593,28 @@ namespace FlaxEditor.Windows
base.OnDestroy();
}
}
/// <summary>
/// Action to perform when a Scene Node receive a double mouse click (Left)
/// </summary>
[Serializable]
public enum SceneNodeDoubleClick
{
/// <summary>
/// No action is performed
/// </summary>
None,
/// <summary>
/// Rename the Scene Node
/// </summary>
RenameActor,
/// <summary>
/// Focus the Scene Node object in the Scene View
/// </summary>
FocusActor,
/// <summary>
/// If possible, open the scene node in an associated Editor (e.g. Prefab Editor)
/// </summary>
OpenPrefab
}
}