unity-editor-tools/editor/SceneSelectorWindow.cs
2025-03-17 01:02:24 +01:00

61 lines
1.6 KiB
C#

using UnityEditor;
using UnityEngine;
using System.IO;
using System.Linq;
namespace editor
{
public class SceneSelectorWindow : EditorWindow
{
private string[] _scenePaths;
private Vector2 _scrollPos;
[MenuItem("Tools/Scene Selector")]
public static void ShowWindow()
{
GetWindow<SceneSelectorWindow>("Scene Selector");
}
private void OnEnable()
{
RefreshSceneList();
}
private void OnGUI()
{
GUILayout.Label("Scene Selector", EditorStyles.boldLabel);
GUILayout.Space(10);
if (GUILayout.Button("Refresh"))
{
RefreshSceneList();
}
GUILayout.Space(20);
_scrollPos = GUILayout.BeginScrollView(_scrollPos);
foreach (var scenePath in _scenePaths)
{
if (GUILayout.Button(Path.GetFileNameWithoutExtension(scenePath)))
{
OpenScene(scenePath);
}
}
GUILayout.EndScrollView();
}
private void RefreshSceneList()
{
_scenePaths = AssetDatabase.FindAssets("t:Scene", new[] { "Assets/Scenes" })
.Select(AssetDatabase.GUIDToAssetPath)
.ToArray();
}
private void OpenScene(string scenePath)
{
if (UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
{
UnityEditor.SceneManagement.EditorSceneManager.OpenScene(scenePath);
}
}
}
}