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

44 行
1.4 KiB

using UnityEngine.SceneManagement;
namespace UnityConsole.Commands
{
public static class SetActiveSceneCommand
{
public static readonly string name = "SetActiveScene";
public static readonly string description = "Sets the named scene as the active scene";
public static readonly string usage = "SetActiveScene sceneName";
public static ConsoleCommandResult Execute(params string[] args)
{
if (args.Length == 0)
{
return HelpCommand.Execute(name);
}
return SetActiveScene(args[0]);
}
private static ConsoleCommandResult SetActiveScene(string sceneName)
{
Scene scene = SceneManager.GetSceneByName(sceneName);
try
{
SceneManager.SetActiveScene(scene);
}
catch
{
return ConsoleCommandResult.Failed($"Failed to set {sceneName} as active.");
}
if (scene.IsValid() && SceneManager.GetActiveScene() == scene)
{
return ConsoleCommandResult.Succeeded(
$"Success setting {sceneName} as active.");
}
return ConsoleCommandResult.Failed(
$"Failed to set {sceneName} as active. Are you sure it's in the list of levels in Build Settings?");
}
}
}