using QFSW.QC; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.SceneManagement; namespace BNG { public class SceneLoader : MonoBehaviour { public List AllMapsLevelNames = new List(); public string ResultSceneName = "ResultScene"; public static SceneLoader Instance; public int TournamentSceneCount = 3; private List _randomMapsList = new List(); private void Awake() { if (Instance == null) { Instance = this; } else { Destroy(gameObject); } } private string _sceneName; private void Start() { InitStartValues(); } [ContextMenu("Debug test")] private void InitStartValues() { _randomMapsList.Clear(); _randomMapsList = new List(); _randomMapsList.AddRange(AllMapsLevelNames.OrderBy(x => Random.Range(0, 100)).Take(TournamentSceneCount)); _randomMapsList.Add(ResultSceneName); GlobalSettings.Instance.AllMaps = false; } public void ChangeLevel() { var firstPersonAfterJack = _randomMapsList.SkipWhile(p => p != SceneManager.GetActiveScene().name).ElementAt(1); LoadScene(firstPersonAfterJack); } public void LoadTournament() { LoadScene(_randomMapsList.First()); } public void LoadScene(string sceneName) { _sceneName = sceneName; StartCoroutine(LoadAsuncScene()); } public void LoadStartScene() { InitStartValues(); LoadScene("StartScene"); } private IEnumerator LoadAsuncScene() { var scene = SceneManager.LoadSceneAsync(_sceneName, LoadSceneMode.Single); scene.allowSceneActivation = false; while (!scene.isDone) { scene.allowSceneActivation = true; yield return null; } } private int _sceneIndex = 0; private void Update() { if (Input.GetKeyDown(KeyCode.R)) { SceneManager.LoadScene(0); } if (Input.GetKeyDown(KeyCode.Equals)) { _sceneIndex++; if (_sceneIndex >= SceneManager.sceneCountInBuildSettings) _sceneIndex = 0; SceneManager.LoadScene(_sceneIndex); } else if (Input.GetKeyDown(KeyCode.Minus)) { _sceneIndex--; if (_sceneIndex < 0) _sceneIndex = SceneManager.sceneCountInBuildSettings - 1; SceneManager.LoadScene(_sceneIndex); } } } }