added scene switcher debug menu
can be accessed at any time with the
This commit is contained in:
		
							
								
								
									
										38
									
								
								Assets/Scripts/DebugSceneSwitcher.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								Assets/Scripts/DebugSceneSwitcher.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using UnityEngine;
 | 
			
		||||
using UnityEngine.SceneManagement;
 | 
			
		||||
using TMPro;
 | 
			
		||||
 | 
			
		||||
public class DebugSceneSwitcher : MonoBehaviour
 | 
			
		||||
{
 | 
			
		||||
    
 | 
			
		||||
    void Awake() {
 | 
			
		||||
        // 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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								Assets/Scripts/DebugSceneSwitcher.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/DebugSceneSwitcher.cs.meta
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 7a63068c7963048a1a15b44127dfb92f
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -38,4 +38,8 @@ public class SceneController : MonoBehaviour
 | 
			
		||||
        SceneManager.LoadScene(0); // main menu scene should be 0
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void LoadChosenScene(int index) {
 | 
			
		||||
        SceneManager.LoadScene(index);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,8 @@ public class StateController : MonoBehaviour {
 | 
			
		||||
    public bool isPaused = false;
 | 
			
		||||
    public GameObject pauseMenuCanvas;
 | 
			
		||||
 | 
			
		||||
    GameObject debugCanvas;
 | 
			
		||||
 | 
			
		||||
    void Awake() {
 | 
			
		||||
        // check to see if a state controller already exists
 | 
			
		||||
        if (GameObject.FindGameObjectWithTag("StateController") != null) {
 | 
			
		||||
@@ -24,6 +26,9 @@ public class StateController : MonoBehaviour {
 | 
			
		||||
        }
 | 
			
		||||
        DontDestroyOnLoad(this.gameObject);
 | 
			
		||||
        SceneManager.sceneLoaded += OnSceneLoaded;
 | 
			
		||||
 | 
			
		||||
        debugCanvas = GameObject.Find("DebugCanvas");
 | 
			
		||||
        debugCanvas.SetActive(false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void OnSceneLoaded(Scene scene, LoadSceneMode mode) { 
 | 
			
		||||
@@ -44,18 +49,23 @@ public class StateController : MonoBehaviour {
 | 
			
		||||
        if (isPaused) {
 | 
			
		||||
            Unpause();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void OnToggleDebugMenu() {
 | 
			
		||||
        debugCanvas.SetActive(!debugCanvas.activeSelf);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void OnPause() {
 | 
			
		||||
        if (!isPaused) {
 | 
			
		||||
            Time.timeScale = 0;
 | 
			
		||||
            TogglePauseMenu(true);
 | 
			
		||||
        } else {
 | 
			
		||||
            Time.timeScale = 1;
 | 
			
		||||
            TogglePauseMenu(false);
 | 
			
		||||
        if (pauseMenuCanvas != null) {
 | 
			
		||||
            if (!isPaused) {
 | 
			
		||||
                Time.timeScale = 0;
 | 
			
		||||
                TogglePauseMenu(true);
 | 
			
		||||
            } else {
 | 
			
		||||
                Time.timeScale = 1;
 | 
			
		||||
                TogglePauseMenu(false);
 | 
			
		||||
            }
 | 
			
		||||
            isPaused = !isPaused;
 | 
			
		||||
        }
 | 
			
		||||
        isPaused = !isPaused;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void Unpause() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user