Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qol, Check If a Scene is Available in Build Settings #1015

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Assets/Fungus/Scripts/Components/SceneLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected virtual void OnGUI()
displayedImage = true;
}
}
protected static List<string> sceneStrings = new List<string>();

#region Public members

Expand All @@ -99,7 +100,21 @@ protected virtual void OnGUI()
/// <param name="_loadingTexture">Loading image to display while loading the new scene.</param>
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);

Expand Down