using Assets.WasapiAudio.Scripts.Unity; using System.Collections.Generic; using System.Collections; using UnityEditor; using UnityEngine.SceneManagement; using UnityEngine.UI; using UnityEngine.VFX; using UnityEngine; public class Loader : MonoBehaviour { public Text currentVis; public Canvas vfxMenu; private static bool menuVisible; private Scene scene; private KeyCode NextButton = KeyCode.Space; private KeyCode PrevButton = KeyCode.Backspace; private KeyCode MenuButton = KeyCode.Escape; public float mouseHideTimeSeconds = 3f; public float mouseHideThreshold = 3f; float mouseLastMoveTime; Vector3 mouseLastMovePos; void Awake() { ToggleMenu(menuVisible); } void Start() { scene = SceneManager.GetActiveScene(); currentVis.text = scene.name; // Debug.Log("Active Scene name is: " + scene.name + "\nActive Scene index: " + scene.buildIndex); // cursor visibility mouseLastMoveTime = Time.timeSinceLevelLoad; mouseLastMovePos = Input.mousePosition; } void Update() { if (Input.GetKeyDown(NextButton)) { NextScene(); } if (Input.GetKeyDown(PrevButton)) { PrevScene(); } if (Input.GetKeyDown(MenuButton)) { ToggleMenu(!menuVisible); } CheckMouseVisibility(); } void VfxMenuVisible(bool v) { if (vfxMenu) vfxMenu.enabled = v; } void ToggleMenu(bool visible) { if (visible) { gameObject.GetComponent().enabled = true; VfxMenuVisible(true); } else { gameObject.GetComponent().enabled = false; VfxMenuVisible(false); } menuVisible = visible; } void CheckMouseVisibility() { if (menuVisible) { Vector2 dx = Input.mousePosition - mouseLastMovePos; bool move = (dx.sqrMagnitude > (mouseHideThreshold * mouseHideThreshold)); mouseLastMovePos = Input.mousePosition; if (move) mouseLastMoveTime = Time.timeSinceLevelLoad; Cursor.visible = (Time.timeSinceLevelLoad - mouseLastMoveTime) < mouseHideTimeSeconds; } else { Cursor.visible = false; } } public void NextScene() { int current = scene.buildIndex; int next = (current + 1) % (SceneManager.sceneCountInBuildSettings); // welcome is at 0. skip it if (next == 0) next = 1; if (next != current) LoadScene(next); } public void PrevScene() { int current = scene.buildIndex; int prev = (current - 1); // check for welcome if (prev <= 0) prev = SceneManager.sceneCountInBuildSettings - 1; if (prev != current) LoadScene(prev); } public void LoadScene(int i) { SceneManager.LoadScene(i); } public void Quit() { // if (EditorApplication) EditorApplication.isPlaying = false; Application.Quit(); } // IEnumerator LoadScene(int i) { // AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(i); // // Wait until the asynchronous scene fully loads // while (!asyncLoad.isDone) // { // yield return null; // } // } }