46 lines
1.6 KiB
C#
Executable File
46 lines
1.6 KiB
C#
Executable File
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class DropDownScenePopulator : MonoBehaviour
|
|
{
|
|
public List<Dropdown.OptionData> optionDataList;
|
|
public Dropdown scenenavigator;
|
|
public string SelectedSceneName = "";
|
|
void Start()
|
|
{
|
|
if (scenenavigator)
|
|
{
|
|
optionDataList = new List<Dropdown.OptionData>();
|
|
for (int i = 0; i < SceneManager.sceneCountInBuildSettings; ++i)
|
|
{
|
|
string name = System.IO.Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(i));
|
|
optionDataList.Add(new Dropdown.OptionData(name));
|
|
}
|
|
scenenavigator.ClearOptions();
|
|
scenenavigator.AddOptions(optionDataList);
|
|
scenenavigator.onValueChanged.AddListener((t) => {
|
|
//SetSceneOptionData(optionDataList[scenenavigator.value]);
|
|
SelectedSceneName = optionDataList[scenenavigator.value].text;
|
|
Debug.LogError("Selected scene in navigator: " + optionDataList[scenenavigator.value].text);
|
|
});
|
|
}
|
|
}
|
|
|
|
public void SwitchScene()
|
|
{
|
|
Time.timeScale = 1;
|
|
Debug.Log(SelectedSceneName);
|
|
Debug.Log(string.Format("Setting current scene to {0}", SelectedSceneName));
|
|
SceneManager.LoadScene(SelectedSceneName);
|
|
}
|
|
|
|
public void ReloadScene()
|
|
{
|
|
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
|
}
|
|
}
|