private TreeViewItem LoadScene(Scene scene, SearchingScope search) { var graph = m_SceneManager.GetGraphForScene(scene); var item = new SceneItem(m_Session, graph); foreach (var node in graph.Roots) { BuildFromNode(node, item, search); } m_CachedSceneItems[scene.SceneGuid] = item; return(item); }
public void ShowSceneContextMenu(SceneItem item) { if (item.Scene == Scene.Null) { return; } var project = Application.AuthoringProject; var scenes = project.GetScenes(); var menu = new GenericMenu(); if (m_SceneManager.GetActiveScene() == item.Scene) { menu.AddDisabledItem(new GUIContent("Set as Active Scene"), true); } else { menu.AddItem(new GUIContent("Set as Active Scene"), false, () => { m_SceneManager.SetActiveScene(item.Scene); }); } menu.AddItem(new GUIContent("Unload Scene"), false, () => { m_SceneManager.UnloadSceneWithDialog(item.Scene); }); menu.AddItem(new GUIContent("Unload Other Scenes"), false, () => { using (var scenesToUnload = ListPool <Scene> .GetDisposable()) { for (var i = 0; i < m_SceneManager.LoadedSceneCount; ++i) { var scene = m_SceneManager.GetLoadedSceneAtIndex(i); if (scene != item.Scene) { scenesToUnload.List.Add(scene); } } foreach (var scene in scenesToUnload.List) { m_SceneManager.UnloadSceneWithDialog(scene); } } }); menu.AddSeparator(""); if (m_SceneManager.GetLoadedSceneAtIndex(0) == item.Scene) { menu.AddDisabledItem(new GUIContent("Move Up")); } else { menu.AddItem(new GUIContent("Move Up"), false, () => { m_SceneManager.MoveSceneUp(item.Scene); }); } if (m_SceneManager.GetLoadedSceneAtIndex(m_SceneManager.LoadedSceneCount - 1) == item.Scene) { menu.AddDisabledItem(new GUIContent("Move Down")); } else { menu.AddItem(new GUIContent("Move Down"), false, () => { m_SceneManager.MoveSceneDown(item.Scene); }); } menu.AddSeparator(""); var sceneReference = new SceneReference { SceneGuid = item.Scene.SceneGuid.Guid }; if (scenes.Contains(sceneReference)) { var startupScenes = project.GetStartupScenes(); menu.AddItem(new GUIContent($"Remove Scene from {project.Name}"), false, () => { project.RemoveScene(sceneReference); }); if (startupScenes.Contains(sceneReference)) { menu.AddItem(new GUIContent($"Remove Scene from {project.Name} Startup Scenes"), false, () => { project.RemoveStartupScene(sceneReference); }); } else { menu.AddItem(new GUIContent($"Add Scene to {project.Name} Startup Scenes"), false, () => { project.AddStartupScene(sceneReference); }); } } else { menu.AddItem(new GUIContent($"Add Scene to {project.Name}"), false, () => { project.AddScene(sceneReference); }); menu.AddDisabledItem(new GUIContent($"Add Scene to {project.Name} Startup Scenes")); } menu.ShowAsContext(); }
private void DrawItem(UnityEngine.Rect rect, SceneItem item, RowGUIArgs args) { if (null == item) { return; } // Draw scene separators and background var indent = GetContentIndent(item); if (!args.selected) { var headerRect = rect; headerRect.width += 1; var topLine = headerRect; topLine.height = 1; HierarchyGui.BackgroundColor(topLine, HierarchyColors.Hierarchy.SceneSeparator); headerRect.y += 2; headerRect.height -= 2; HierarchyGui.BackgroundColor(headerRect, HierarchyColors.Hierarchy.SceneItem); if (rect.Contains(Event.current.mousePosition)) { HierarchyGui.BackgroundColor(headerRect, HierarchyColors.Hierarchy.Hover); if (Event.current.type == EventType.Layout) { m_CurrentHoveredRect = rect; } } var bottomLine = headerRect; bottomLine.y += bottomLine.height - 2; bottomLine.height = 1; HierarchyGui.BackgroundColor(bottomLine, HierarchyColors.Hierarchy.SceneSeparator); } // Draw scene icon rect.y += 2; rect.x = indent; rect.width -= indent; var iconRect = rect; iconRect.width = 20; var image = ActiveScene == item.Scene ? Icons.ActiveScene : Icons.Scene; EditorGUI.LabelField(iconRect, new UnityEngine.GUIContent { image = image }); // Draw scene label rect.x += 20; rect.width -= 40; var style = ActiveScene == item.Scene ? EditorStyles.boldLabel : UnityEngine.GUI.skin.label; var label = item.displayName; var project = Application.AuthoringProject; if (!project.GetScenes().Contains(new SceneReference { SceneGuid = item.Scene.SceneGuid.Guid })) { label += $" (Not in {project.Name})"; } EditorGUI.LabelField(rect, label, style); // Draw scene context menu button rect.x += rect.width; rect.width = 16; if (UnityEngine.GUI.Button(rect, Icons.Settings, GUI.skin.label)) { ShowSceneContextMenu(item); } }