Quick scene browser tab

This commit is contained in:
Michal Pikulski
2025-09-11 15:29:28 +02:00
parent fd220de298
commit c5b8561b73
3 changed files with 126 additions and 3 deletions

View File

@@ -0,0 +1,123 @@
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public class SceneBrowserWindow : EditorWindow
{
private class SceneInfo
{
public string path;
public string name;
public string folder;
public bool inBuildSettings;
}
private Vector2 _scroll;
private List<SceneInfo> _scenes = new List<SceneInfo>();
private Dictionary<string, List<SceneInfo>> _scenesByFolder = new Dictionary<string, List<SceneInfo>>();
[MenuItem("Tools/Scene Browser")]
public static void ShowWindow()
{
var window = GetWindow<SceneBrowserWindow>(false, "Scene Browser", true);
window.RefreshScenes();
}
private void OnFocus()
{
RefreshScenes();
}
private void RefreshScenes()
{
_scenes.Clear();
_scenesByFolder.Clear();
string[] guids = AssetDatabase.FindAssets("t:Scene", new[] { "Assets/Scenes" });
var buildScenes = EditorBuildSettings.scenes.Select(s => s.path).ToHashSet();
foreach (var guid in guids)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
string name = Path.GetFileNameWithoutExtension(path);
string folder = Path.GetDirectoryName(path).Replace("\\", "/");
if (folder == "Assets/Scenes") folder = "";
var info = new SceneInfo
{
path = path,
name = name,
folder = folder,
inBuildSettings = buildScenes.Contains(path)
};
_scenes.Add(info);
if (!_scenesByFolder.ContainsKey(folder))
_scenesByFolder[folder] = new List<SceneInfo>();
_scenesByFolder[folder].Add(info);
}
}
private void OnGUI()
{
if (GUILayout.Button("Refresh"))
RefreshScenes();
_scroll = EditorGUILayout.BeginScrollView(_scroll);
// Top-level scenes
if (_scenesByFolder.ContainsKey(""))
{
foreach (var scene in _scenesByFolder[""])
DrawSceneRow(scene);
EditorGUILayout.Space();
}
// Subfolders
foreach (var kvp in _scenesByFolder)
{
if (string.IsNullOrEmpty(kvp.Key)) continue;
EditorGUILayout.LabelField(kvp.Key, EditorStyles.boldLabel);
foreach (var scene in kvp.Value)
DrawSceneRow(scene);
EditorGUILayout.Space();
}
EditorGUILayout.EndScrollView();
}
private void DrawSceneRow(SceneInfo scene)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(scene.name, GUILayout.Width(180));
if (GUILayout.Button("Open", GUILayout.Width(50)))
{
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
EditorSceneManager.OpenScene(scene.path);
}
if (GUILayout.Button("Locate", GUILayout.Width(50)))
{
var obj = AssetDatabase.LoadAssetAtPath<SceneAsset>(scene.path);
EditorGUIUtility.PingObject(obj);
}
bool inBuild = scene.inBuildSettings;
bool newInBuild = GUILayout.Toggle(inBuild, "In Build", GUILayout.Width(70));
if (newInBuild != inBuild)
{
ToggleSceneInBuildSettings(scene.path, newInBuild);
scene.inBuildSettings = newInBuild;
}
EditorGUILayout.EndHorizontal();
}
private void ToggleSceneInBuildSettings(string path, bool add)
{
var scenes = EditorBuildSettings.scenes.ToList();
if (add)
{
if (!scenes.Any(s => s.path == path))
scenes.Add(new EditorBuildSettingsScene(path, true));
}
else
{
scenes = scenes.Where(s => s.path != path).ToList();
}
EditorBuildSettings.scenes = scenes.ToArray();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bda5b0c96582450e94a8b332f86c726d
timeCreated: 1757596929

View File

@@ -58,10 +58,7 @@ public class FollowerController: MonoBehaviour
/// </summary>
public event FollowerPickupHandler OnPickupReturned;
private Coroutine _pickupCoroutine;
private bool _lastInteractionSuccess = true;
void Awake()
{
_aiPath = GetComponent<AIPath>();