2023-04-26 13:03:48 -07:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
using TMPro;
|
|
|
|
|
|
|
|
public class DebugSceneSwitcher : MonoBehaviour
|
|
|
|
{
|
2023-05-05 13:20:14 -07:00
|
|
|
public static DebugSceneSwitcher Instance = null;
|
|
|
|
|
2023-05-04 19:54:59 -07:00
|
|
|
public bool showDropdown;
|
|
|
|
|
2023-05-04 02:19:51 -07:00
|
|
|
void Awake()
|
|
|
|
{
|
2023-05-05 13:20:14 -07:00
|
|
|
if (Instance == null) {
|
|
|
|
Instance = this;
|
|
|
|
} else {
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
return;
|
|
|
|
}
|
2023-05-04 02:19:51 -07:00
|
|
|
// Keep the object around when we switch scenes
|
2023-04-26 13:03:48 -07:00
|
|
|
DontDestroyOnLoad(this.gameObject);
|
|
|
|
CreateDropdownOptions();
|
|
|
|
}
|
|
|
|
|
2023-05-04 02:19:51 -07:00
|
|
|
void CreateDropdownOptions()
|
|
|
|
{
|
2023-04-26 13:03:48 -07:00
|
|
|
TMP_Dropdown sceneDropdown = GameObject.Find("SceneSwitcherDropdown").GetComponent<TMP_Dropdown>();
|
2023-05-04 19:54:59 -07:00
|
|
|
if (showDropdown) {
|
|
|
|
if (sceneDropdown.options.Count == 0)
|
2023-05-04 02:19:51 -07:00
|
|
|
{
|
2023-05-04 19:54:59 -07:00
|
|
|
List<string> sceneNames = new List<string>();
|
|
|
|
for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++)
|
|
|
|
{
|
|
|
|
string newName = System.IO.Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(i));
|
|
|
|
sceneNames.Add(newName);
|
|
|
|
}
|
|
|
|
sceneDropdown.AddOptions(sceneNames);
|
2023-04-26 13:03:48 -07:00
|
|
|
}
|
2023-05-04 19:54:59 -07:00
|
|
|
} else {
|
|
|
|
sceneDropdown.gameObject.SetActive(false);
|
2023-04-26 13:03:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-04 02:19:51 -07:00
|
|
|
public void ChangeScene(int index)
|
|
|
|
{
|
|
|
|
SceneController.Instance.LoadChosenScene(index);
|
2023-05-04 11:38:06 -07:00
|
|
|
this.gameObject.SetActive(false);
|
2023-04-26 13:03:48 -07:00
|
|
|
}
|
2023-05-04 19:54:59 -07:00
|
|
|
|
|
|
|
public void ChangeSceneByName(string name) {
|
|
|
|
SceneController.Instance.LoadSceneByName(name);
|
|
|
|
this.gameObject.SetActive(false);
|
|
|
|
}
|
2023-04-26 13:03:48 -07:00
|
|
|
}
|