Last active
January 18, 2023 08:07
-
-
Save klaszlo8207/79d269a7d956aacb6e53c2cb556143a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine.SceneManagement; | |
namespace _MyScripts.Utils | |
{ | |
public static class SceneUtils | |
{ | |
private static string NameFromIndex(int buildIndex) | |
{ | |
var path = SceneUtility.GetScenePathByBuildIndex(buildIndex); | |
var slash = path.LastIndexOf('/'); | |
var name = path.Substring(slash + 1); | |
var dot = name.LastIndexOf('.'); | |
return name.Substring(0, dot); | |
} | |
public static int SceneIndexFromName(string sceneName) | |
{ | |
for (var i = 0; i < SceneManager.sceneCountInBuildSettings; i++) | |
{ | |
var testedScreen = NameFromIndex(i); | |
if (testedScreen == sceneName) | |
return i; | |
} | |
return -1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment