From 475453aa601d4f8ced173ae4a05c913e21ac1c0f Mon Sep 17 00:00:00 2001 From: nothingTVatYT Date: Tue, 28 Nov 2023 00:06:28 +0100 Subject: [PATCH 1/4] add load scene add. to context menus --- Source/Editor/Content/Proxy/SceneProxy.cs | 7 ++++++ .../Windows/SceneTreeWindow.ContextMenu.cs | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Source/Editor/Content/Proxy/SceneProxy.cs b/Source/Editor/Content/Proxy/SceneProxy.cs index 004c2aed7..a232c672b 100644 --- a/Source/Editor/Content/Proxy/SceneProxy.cs +++ b/Source/Editor/Content/Proxy/SceneProxy.cs @@ -1,6 +1,7 @@ // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; +using FlaxEditor.GUI.ContextMenu; using FlaxEditor.Windows; using FlaxEngine; @@ -68,5 +69,11 @@ namespace FlaxEditor.Content { return new SceneItem(path, id); } + + /// + public override void OnContentWindowContextMenu(ContextMenu menu, ContentItem item) + { + menu.AddButton("Open additionally", () => { Editor.Instance.Scene.OpenScene(((SceneItem)item).ID, true); }); + } } } diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs index a99c3ac7d..3e078bcb8 100644 --- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs +++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs @@ -1,6 +1,8 @@ // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; +using System.Collections.Generic; +using System.Linq; using FlaxEditor.GUI.ContextMenu; using FlaxEditor.SceneGraph; using FlaxEngine; @@ -148,6 +150,26 @@ namespace FlaxEditor.Windows // Spawning actors options + if (!hasSthSelected) + { + var allScenes = FlaxEngine.Content.GetAllAssetsByType(typeof(SceneAsset)); + var loadedSceneIds = Editor.Instance.Scene.Root.ChildNodes.Select(node => node.ID).ToList(); + var unloadedScenes = allScenes.Where(sceneId => !loadedSceneIds.Contains(sceneId)).ToList(); + if (unloadedScenes.Count > 0) + { + contextMenu.AddSeparator(); + var childCM = contextMenu.GetOrAddChildMenu("Open Scene additionally"); + foreach (var sceneGuid in unloadedScenes.Where(sceneGuid => !Level.FindScene(sceneGuid))) + { + if (FlaxEngine.Content.GetAssetInfo(sceneGuid, out var unloadedScene)) + { + var splitPath = unloadedScene.Path.Split('/'); + childCM.ContextMenu.AddButton(splitPath[^1], () => { Editor.Instance.Scene.OpenScene(sceneGuid, true); }); + } + } + } + } + contextMenu.AddSeparator(); // go through each actor and add it to the context menu if it has the ActorContextMenu attribute From a06a0798041e22ee6f48a9b5195f33be75982190 Mon Sep 17 00:00:00 2001 From: nothingTVatYT Date: Tue, 28 Nov 2023 00:37:29 +0100 Subject: [PATCH 2/4] change submenu name to the shorter and less complicated "Add Scene" --- Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs index 3e078bcb8..6261c0c07 100644 --- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs +++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs @@ -158,13 +158,16 @@ namespace FlaxEditor.Windows if (unloadedScenes.Count > 0) { contextMenu.AddSeparator(); - var childCM = contextMenu.GetOrAddChildMenu("Open Scene additionally"); + var childCM = contextMenu.GetOrAddChildMenu("Add Scene"); foreach (var sceneGuid in unloadedScenes.Where(sceneGuid => !Level.FindScene(sceneGuid))) { if (FlaxEngine.Content.GetAssetInfo(sceneGuid, out var unloadedScene)) { var splitPath = unloadedScene.Path.Split('/'); - childCM.ContextMenu.AddButton(splitPath[^1], () => { Editor.Instance.Scene.OpenScene(sceneGuid, true); }); + var sceneName = splitPath[^1]; + if (splitPath[^1].EndsWith(".scene")) + sceneName = sceneName[..^6]; + childCM.ContextMenu.AddButton(sceneName, () => { Editor.Instance.Scene.OpenScene(sceneGuid, true); }); } } } From 84f3d509252bac9d351376c3bb0e2d7e39092846 Mon Sep 17 00:00:00 2001 From: nothingTVatYT Date: Tue, 28 Nov 2023 00:43:55 +0100 Subject: [PATCH 3/4] moved a comment line back to the suitable place --- Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs index 6261c0c07..ea4714df8 100644 --- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs +++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs @@ -148,7 +148,7 @@ namespace FlaxEditor.Windows contextMenu.AddButton("Break Prefab Link", Editor.Prefabs.BreakLinks); } - // Spawning actors options + // Load additional scenes option if (!hasSthSelected) { @@ -173,6 +173,8 @@ namespace FlaxEditor.Windows } } + // Spawning actors options + contextMenu.AddSeparator(); // go through each actor and add it to the context menu if it has the ActorContextMenu attribute From a3f1dc269474eaee3de64334d9ddf6d0319fcf76 Mon Sep 17 00:00:00 2001 From: nothingTVatYT Date: Tue, 28 Nov 2023 00:50:44 +0100 Subject: [PATCH 4/4] removed unnecessary check --- Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs index ea4714df8..8b5318190 100644 --- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs +++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs @@ -159,7 +159,7 @@ namespace FlaxEditor.Windows { contextMenu.AddSeparator(); var childCM = contextMenu.GetOrAddChildMenu("Add Scene"); - foreach (var sceneGuid in unloadedScenes.Where(sceneGuid => !Level.FindScene(sceneGuid))) + foreach (var sceneGuid in unloadedScenes) { if (FlaxEngine.Content.GetAssetInfo(sceneGuid, out var unloadedScene)) {