You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Jeremy/Assets/Scripts/Editor/SceneSwitcherEditorWindow.cs

58 lines
1.6 KiB

using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
public class SceneSwitcherEditorWindow : EditorWindow
{
[MenuItem("Examples/My Editor Window")]
public static void ShowExample()
{
var editorWindow = GetWindow<SceneSwitcherEditorWindow>();
editorWindow.titleContent = new GUIContent("SceneSwitcherEditor");
}
public void CreateGUI()
{
// Each editor window contains a root VisualElement object
VisualElement root = rootVisualElement;
root.Clear();
// Create a ScrollView
ScrollView scrollView = new ScrollView();
root.Add(scrollView);
// reload button
Button reloadButton = new Button();
reloadButton.text = "Reload";
reloadButton.clicked += () => CreateGUI();
scrollView.Add(reloadButton);
// space
scrollView.Add(new Label(""));
// Get the SceneSwitcher component
if (SceneSwitcher.Instance == null)
{
Debug.LogError("SceneSwitcher component not found in the scene.");
return;
}
// Get the list of scenes
List<(string name, int index)> scenes = SceneSwitcher.Instance.GetScenes();
// Create a button for each scene
foreach (var scene in scenes)
{
Button button = new Button();
button.text = scene.name;
int sceneIndex = scene.index; // Capture the index in a local variable
button.clicked += () => SceneSwitcher.Instance.SwitchScene(sceneIndex);
scrollView.Add(button);
}
}
}