Small optimization

This commit is contained in:
davevanegdom
2023-09-23 03:24:19 +02:00
parent 23f4a82bbc
commit 1b84f57a5b
2 changed files with 10 additions and 7 deletions

View File

@@ -113,15 +113,18 @@ namespace FlaxEditor.Modules
/// Open a prefab in a Prefab Editor
/// </summary>
/// <returns>Whether the prefab was successfully opened in a Prefab Editor</returns>
public bool OpenPrefab()
public bool OpenPrefab(Guid prefabID = default)
{
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;
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;
var prefabId = ((ActorNode)selection[0]).Actor.PrefabID;
var item = Editor.Instance.ContentDatabase.Find(prefabId);
prefabID = ((ActorNode)selection[0]).Actor.PrefabID;
}
var item = Editor.Instance.ContentDatabase.Find(prefabID);
if(item != null)
{
Editor.Instance.ContentEditing.Open(item);

View File

@@ -141,7 +141,7 @@ namespace FlaxEditor.Windows
bool hasPrefabLink = canEditScene && isSingleActorSelected && actorNode.HasPrefabLink;
if (hasPrefabLink)
{
contextMenu.AddButton("Open Prefab", () => Editor.Prefabs.OpenPrefab());
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);
}