private void trackScene(Scene scene, LoadSceneMode mode) { Debug.Log("Scene changed"); if (mode.Equals(LoadSceneMode.Single)) { currentScene = scene; player = GameObject.FindGameObjectWithTag("Player"); } }
public void OnSceneLoaded(Scene newScene, LoadSceneMode loadMode) { Debug.Log("Story Controller noted scene " + newScene.name + " is loading"); if (newScene.name == TITLE_LEVEL && StoryStage == STAGE_TITLE) { SetupTitleScreenPostLoad(); } else if (newScene.name == LOADING_LEVEL) { //This is our chance to enable everything to be ready once the next level is loaded musicManager.IsEnabled = true; player.lockedControls = false; //Load the scene needed for this part of the story: if (StoryStage == STAGE_GET_ARROW) { //levelLoader.LoadNextLevel("House"); StartCoroutine(LoadLevelNextFrame("House")); } //Here, the palyer can be in their house, the village, or the forest //TODO Maybe player position? else if (StoryStage == STAGE_HAS_ARROW) { if (LastLevel != "") { //levelLoader.LoadNextLevel(LastLevel); StartCoroutine(LoadLevelNextFrame(LastLevel)); } else { //levelLoader.LoadNextLevel("House"); StartCoroutine(LoadLevelNextFrame("House")); } } } //Can't save in a combat scene, also don't save the title screen if (!newScene.name.Contains("Combat") && loadMode.Equals(LoadSceneMode.Single)) { LastLevel = newScene.name; PlayerPrefs.SetString(LAST_LEVEL_KEY, LastLevel); PlayerPrefs.Save(); } }
private static IEnumerator LoadSceneCO(IConvertible _sceneName, float _minSeconds, Button _buttonToDisable, LoadSceneMode _sceneMode, Image _imageToFill, Text _textToShow) { if (_buttonToDisable != null) { _buttonToDisable.interactable = false; } AsyncOperation async = SceneManager.LoadSceneAsync(_sceneName.ToString(CultureInfo.InvariantCulture), _sceneMode); async.allowSceneActivation = false; if (!Mathf.Approximately(_minSeconds, 0.0f)) { Action <float> FillImage = _value => { }; Action <float> UpdateText = _value => { }; if (_imageToFill != null) { FillImage = _value => { _imageToFill.fillAmount = _value; }; } if (_textToShow != null) { UpdateText = _value => { _textToShow.text = CustomLibrary.Utils.BuildString((int)(_value * 100), "%"); }; } float step = 0; float temp_value = 0; float randomWait = _minSeconds; float firstStep = UnityEngine.Random.Range(.7f, .8f); while (step < 1.0f) { temp_value = Mathf.Lerp(0, firstStep, step); step += Time.deltaTime / randomWait; FillImage(temp_value); UpdateText(temp_value); yield return(null); } step = 0; while (step < 1) { step += Time.deltaTime / randomWait; temp_value = Mathf.Lerp(firstStep, 1, step); FillImage(temp_value); UpdateText(temp_value); yield return(null); } } async.allowSceneActivation = true; yield return(new WaitUntil(() => async.progress > .9f && async.isDone)); if (_sceneMode.Equals(LoadSceneMode.Single)) { yield break; } Scene oldScene = SceneManager.GetActiveScene(); SceneManager.SetActiveScene(SceneManager.GetSceneByName(_sceneName.ToString(CultureInfo.InvariantCulture))); SceneManager.UnloadSceneAsync(oldScene); }