您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

50 行
1.7 KiB

using UnityEngine.SceneManagement;
/// <summary>
/// LOAD command. Load the specified scene by name.
/// </summary>
namespace UnityConsole.Commands
{
public static class LoadSceneCommand
{
public static readonly string name = "LoadScene";
public static readonly string description =
"Load the specified scene by name. Before you can load a scene you have to add it to the list of levels used in the game. Use File->Build Settings... in Unity and add the levels you need to the level list there.";
public static readonly string usage = "Load scene";
public static ConsoleCommandResult Execute(params string[] args)
{
if (args.Length == 0)
{
return HelpCommand.Execute(name);
}
return LoadLevel(args[0]);
}
private static ConsoleCommandResult LoadLevel(string sceneName)
{
try
{
SceneManager.LoadScene(sceneName, LoadSceneMode.Single);
}
catch
{
return ConsoleCommandResult.Failed($"Failed to load {sceneName}.");
}
Scene scene = SceneManager.GetSceneByName(sceneName);
if (scene.IsValid() && scene.isLoaded)
{
// Assume success if we had to load the scene we were already in
return ConsoleCommandResult.Succeeded($"Success loading {sceneName}.");
}
return ConsoleCommandResult.Failed(
$"Failed to load {sceneName}. Are you sure it's in the list of levels in Build Settings?");
}
}
}