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
|
|
|
|
{
|
|
|
|
|
|
|
|
void Awake() {
|
2023-04-26 13:27:08 -07:00
|
|
|
if (!GameObject.Find("StateController").GetComponent<StateController>().inDebugMode) {
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
}
|
2023-04-26 13:03:48 -07:00
|
|
|
// check to see if a debug canvas already exists
|
|
|
|
if (GameObject.FindGameObjectWithTag("DebugCanvas") != null) {
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
} else { // if it doesn't, then this is the only one
|
|
|
|
this.gameObject.tag = "DebugCanvas";
|
|
|
|
}
|
|
|
|
DontDestroyOnLoad(this.gameObject);
|
|
|
|
CreateDropdownOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateDropdownOptions() {
|
|
|
|
TMP_Dropdown sceneDropdown = GameObject.Find("SceneSwitcherDropdown").GetComponent<TMP_Dropdown>();
|
|
|
|
if (sceneDropdown.options.Count == 0) {
|
|
|
|
List<string> sceneNames = new List<string>();
|
|
|
|
for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++) {
|
|
|
|
string newName = System.IO.Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(i));
|
|
|
|
print(newName);
|
|
|
|
sceneNames.Add(newName);
|
|
|
|
}
|
|
|
|
sceneDropdown.AddOptions(sceneNames);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ChangeScene(int index) {
|
|
|
|
// print(index);
|
|
|
|
GameObject.FindGameObjectWithTag("SceneManager").GetComponent<SceneController>().LoadChosenScene(index);
|
|
|
|
}
|
|
|
|
}
|