获取到单前场景的名字的代码
Scene scene = SceneManager.GetActiveScene();
Debug.Log(scene.name);
获取到Build Settings里Scenes In Build里所有场景的名字。注:如果当前场景没有放到Build Settings里Scenes In Build里,会额外增加一个场景的名字,放在数组的最后一位scene_names
为所有场景的名字,scene_paths
所有场景的路径
在这里插入代码片
void GetAllSceneName()
{
int count = SceneManager.sceneCountInBuildSettings;
Debug.Log("Scene Count = " + count);
string[] scene_names = new string[count];
string[] scene_paths = new string[count];
for (int i = 0; i < count; i++)
{
scene_names[i] = SceneUtility.GetScenePathByBuildIndex(i);
//从Assets路径下到此场景的路径
Debug.Log("Assets路径开始到场景的路径为:" + scene_names[i]);
scene_paths[i] = SceneUtility.GetScenePathByBuildIndex(i);
//路径
Debug.Log("路径为:" + scene_paths[i]);
string[] strs = scene_names[i].Split('/');
string str = strs[strs.Length - 1];
strs = str.Split('.');
str = strs[0];
scene_names[i] = str;
//场景的名字
Debug.Log("场景的名字为:" + str);
}
}