From ea5ad663d9c45cbc26942f324583c663015637a6 Mon Sep 17 00:00:00 2001 From: breadnone <64100867+breadnone@users.noreply.github.com> Date: Tue, 13 Jul 2021 11:16:09 +0700 Subject: [PATCH] Qol loadscene --- Assets/Fungus/Scripts/Components/SceneLoader.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Assets/Fungus/Scripts/Components/SceneLoader.cs b/Assets/Fungus/Scripts/Components/SceneLoader.cs index cc3818f5e..b99b2fdff 100644 --- a/Assets/Fungus/Scripts/Components/SceneLoader.cs +++ b/Assets/Fungus/Scripts/Components/SceneLoader.cs @@ -89,6 +89,7 @@ protected virtual void OnGUI() displayedImage = true; } } + protected static List sceneStrings = new List(); #region Public members @@ -99,7 +100,21 @@ protected virtual void OnGUI() /// Loading image to display while loading the new scene. public static void LoadScene(string _sceneToLoad, Texture2D _loadingTexture) { - // Unity does not provide a way to check if the named scene actually exists in the project. + if(_sceneToLoad != string.Empty) + { + for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++) + { + string scenePath = SceneUtility.GetScenePathByBuildIndex(i); + int lastSlash = scenePath.LastIndexOf("/"); + sceneStrings.Add(scenePath.Substring(lastSlash + 1, scenePath.LastIndexOf(".") - lastSlash - 1)); + } + if(!sceneStrings.Contains(_sceneToLoad)) + { + Debug.LogWarning("The scene does not exist in build settings"); + return; + } + } + GameObject go = new GameObject("SceneLoader"); DontDestroyOnLoad(go);