Version: 2017.1
构建播放器管线
幕后工作

命令行参数

Unity is usually launched by double-clicking its icon from the desktop. However, it is also possible to run it from the command line (from the macOS Terminal or the Windows Command Prompt). When launched in this way, Unity can receive commands and information on startup, which can be very useful for test suites, automated builds and other production tasks.

On macOS, type the following into the Terminal to launch Unity:

/Applications/Unity/Unity.app/Contents/MacOS/Unity

On 64-bit Windows, type the following into the Command Prompt to launch Unity:

C:\Program Files\Unity\Editor\Unity.exe

On 32-bit Windows, type the following into the Command Prompt to launch Unity:

C:\Program Files (x86)\Unity\Editor\Unity.exe

Use the same method to launch standalone Unity games.

以静默方式启动 Unity

On macOS, type the following into the Terminal to silently launch Unity:

/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -serial SB-XXXX-XXXX-XXXX-XXXX-XXXX -username 'JoeBloggs@example.com' -password 'MyPassw0rd'

On 64-bit Windows, type the following into the Command Prompt to silently launch Unity:

     "C:\Program Files\Unity\Editor\Unity.exe" -quit -batchmode -serial SB-XXXX-XXXX-XXXX-XXXX-XXXX -username "JoeBloggs@example.com" -password "MyPassw0rd"

On 32-bit Windows, type the following into the Command Prompt to silently launch Unity:

 "C:\Program Files (x86)\Unity\Editor\Unity.exe" -quit -batchmode -serial SB-XXXX-XXXX-XXXX-XXXX-XXXX -username "JoeBloggs@example.com" -password "MyPassw0rd"

选项

As mentioned above, the Editor and built Unity games can be supplied with additional commands and information on startup. This section describes the command line options available.

命令 详细信息
-assetServerUpdate <IP[:port] projectName username password [r <revision>]> Force an update of the project in the Asset Server given by IP:port. The port is optional, and if not given it is assumed to be the standard one (10733). It is advisable to use this command in conjunction with the -projectPath argument to ensure you are working with the correct project. If no project name is given, then the last project opened by Unity is used. If no project exists at the path given by -projectPath, then one is created automatically.
-batchmode Run Unity in batch mode. This should always be used in conjunction with the other command line arguments, because it ensures no pop-up windows appear and eliminates the need for any human intervention. When an exception occurs during execution of the script code, the Asset server updates fail, or other operations that fail, Unity immediately exits with return code 1.
Note that in batch mode, Unity sends a minimal version of its log output to the console. However, the Log Files still contain the full log information. Opening a project in batch mode while the Editor has the same project open is not supported; only a single instance of Unity can run at a time.
-buildLinux32Player <pathname> 构建 32 位独立平台 Linux 播放器(例如,-buildLinux32Player path/to/your/build)。
-buildLinux64Player <pathname> 构建 64 位独立平台 Linux 播放器(例如,-buildLinux64Player path/to/your/build)。
-buildLinuxUniversalPlayer <pathname> 构建 32 位和 64 位组合独立平台 Linux 播放器(例如,-buildLinuxUniversalPlayer path/to/your/build)。
-buildOSXPlayer <pathname> 构建 32 位独立平台 Mac OSX 播放器(例如,-buildOSXPlayer path/to/your/build.app)。
-buildOSX64Player <pathname> 构建 64 位独立平台 Mac OSX 播放器(例如,-buildOSX64Player path/to/your/build.app)。
-buildOSXUniversalPlayer <pathname> 构建 32 位和 64 位组合独立平台 Mac OSX 播放器(例如,-buildOSXUniversalPlayer path/to/your/build.app)。
-buildTarget <name> Allows the selection of an active build target before a project is loaded. Possible options are: win32, win64, osx, linux, linux64, ios, android, web, webstreamed, webgl, xboxone, ps4, psp2, wsaplayer, tizen, samsungtv.
-buildWindowsPlayer <pathname> 构建 32 位独立平台 Windows 播放器(例如,-buildWindowsPlayer path/to/your/build.exe)。
-buildWindows64Player <pathname> 构建 64 位独立平台 Windows 播放器(例如,-buildWindows64Player path/to/your/build.exe)。
-stackTraceLogType Detailed debugging feature. StackTraceLogging allows features to be controlled to allow detailed logging. All settings allow None, Script Only and Full to be selected. (for example, -stackTraceLogType Full)
-createProject <pathname> 在指定路径中创建一个空项目。
-editorTestsCategories 按类别过滤 Editor 测试。使用逗号分隔测试类别。
-editorTestsFilter 按名称过滤 Editor 测试。使用逗号分隔测试名称。
-editorTestsResultFile Path where the result file should be placed. If the path is a folder, a default file name is used. If not specified, the results are placed in the project’s root folder.
-executeMethod <ClassName.MethodName> Execute the static method as soon as Unity is started, the project is open and after the optional Asset server update has been performed. This can be used to do tasks such as continous integration, performing Unit Tests, making builds or preparing data. To return an error from the command line process, either throw an exception which causes Unity to exit with return code 1, or call EditorApplication.Exit with a non-zero return code. To pass parameters, add them to the command line and retrieve them inside the function using System.Environment.GetCommandLineArgs. To use -executeMethod, you need to place the enclosing script in an Editor folder. The method to be executed must be defined as static.
-exportPackage <exportAssetPath1 exportAssetPath2 ExportAssetPath3 exportFileName> Export a package, given a path (or set of given paths). In this example exportAssetPath is a folder (relative to to the Unity project root) to export from the Unity project, and exportFileName is the package name. Currently, this option only exports whole folders at a time. This command normally needs to be used with the -projectPath argument.
-force-d3d9 (Windows only) Make the Editor use Direct3D 9 for rendering. Normally the graphics API depends on player settings (typically defaults to D3D11).
-force-d3d11(仅限 Windows) 使 Editor 使用 Direct3D 11 进行渲染。通常,图形 API 取决于播放器设置(通常默认为 D3D11)。
-force-glcore (Windows only) 使 Editor 使用 OpenGL 3/4 Core 配置文件进行渲染。Editor 会尝试使用可用的最佳 OpenGL 版本以及 OpenGL 驱动程序公开的所有 OpenGL 扩展。如果不支持该平台,则使用 Direct3D。
-force-glcoreXY (Windows only) -force-glcore 类似,但请求特定的 OpenGL 上下文版本。XY 的可接受值:32、33、40、41、42、43、44 或 45。
-force-gles(仅限 Windows) 使 Editor 使用 OpenGL for Embedded Systems 进行渲染。Editor 会尝试使用可用的最佳 OpenGL ES 版本以及 OpenGL 驱动程序公开的所有 OpenGL ES 扩展。
-force-glesXY(仅限 Windows) -force-gles 类似,但请求特定的 OpenGL ES 上下文版本。XY 的可接受值:30、31 或 32。
-force-clamped (Windows only) -force-glcoreXY 一起使用以防止检查其他 OpenGL 扩展,允许在具有相同代码路径的平台之间运行。
-force-free 使 Editor 运行,就像机器上有免费的 Unity 许可证一样,即使安装了 Unity Pro 许可证也是如此。
-importPackage <pathname> 导入指定的资源包。不显示导入对话框。
-logFile <pathname> Specify where the Editor or Windows/Linux/OSX standalone log file are written.
-nographics When running in batch mode, do not initialize the graphics device at all. This makes it possible to run your automated workflows on machines that don’t even have a GPU (automated workflows only work when you have a window in focus, otherwise you can’t send simulated input commands). Please note that -nographics does not allow you to bake GI on OSX, since Enlighten requires GPU acceleration.
-password <password> 用户的密码(启动时需要)。
-projectPath <pathname> 在指定路径下打开项目。
-quit 在其他命令执行完毕后退出 Unity Editor。请注意,这可能导致错误消息被隐藏(但是,它们仍会出现在 Editor.log 文件中)。
-returnlicense 将当前激活的许可证退回到许可证服务器。在删除许可证文件前请留出几秒钟,因为 Unity 需要与许可证服务器通信。
-runEditorTests 从项目中运行 Editor 测试。这个参数需要 projectPath,并且最好与 batchmode 参数一起运行。quit 不是必需的,因为 Editor 在运行完后自动关闭。
-serial <serial> 使用指定的序列号激活 Unity。最好还能传递 -batchmode-quit 参数,以便在完成时退出 Unity(如果用来自动激活 Unity)。在创建许可证文件前请留出几秒钟,因为 Unity 需要与许可证服务器通信。确保许可证文件的文件夹存在,并且在使用此参数运行 Unity 之前具有适当的权限。如果激活失败,请查看 Editor.log 获取信息。
-silent-crashes 不显示崩溃对话框。
-username <username> 在激活 Unity Editor 期间,在登录窗体中输入用户名。
-password <password> 在激活 Unity Editor 期间,在登录窗体中输入密码。
-disable-assembly-updater <assembly1 assembly2> 指定一个以空格分隔的程序集名称列表作为 Unity 在自动更新时忽略的参数。
以空格分隔的程序集名称列表是可选的:如果传递命令行选项时不带任何程序集名称,表示忽略所有程序集,如示例 1 所示。

示例 1
unity.exe -disable-assembly-updater

示例 2 有两个程序集名称,其中一个具有路径名。示例 2 无论 A1.dll 存储在哪个文件夹中都会将其忽略,但只有 A2.dll 存储在 subfolder 文件夹下时才会将其忽略:

示例 2
unity.exe -disable-assembly-updater A1.dll subfolder/A2.dll

如果在 -disable-assembly-updater 命令行参数中列出程序集(或者如果不指定程序集),Unity 会将以下消息记录到 Editor.log

[Assembly Updater] warning: Ignoring assembly [assembly_path] as requested by command line parameter.").

可用于在导入程序集时避免不必要的 API Updater 开销。

如果知道 Unity API 不需要更新,对于导入访问 Unity API 的程序集非常有用。在导入完全不访问 Unity API 的程序集时也很有用(例如,如果在 Unity 之外构建了游戏源代码或其中部分代码,并且想要将生成的程序集导入到 Unity 项目中)。

注意:如果对任何需要更新的程序集禁用更新,则可能会在编译时和/或运行时都出现难以跟踪的错误。

示例

C#:

using UnityEditor;
class MyEditorScript
{
     static void PerformBuild ()
     {
         string[] scenes = { "Assets/MyScene.unity" };
         BuildPipeline.BuildPlayer(scenes, ...);
     }
}

JavaScript:

static void PerformBuild ()
{
    string[] scenes = { "Assets/MyScene.unity" };
    BuildPipeline.BuildPlayer(scenes, ...);
}

The following command executes Unity in batch mode, executes the MyEditorScript.MyMethod method, and then quits upon completion.

Windows:

C:\program files\Unity\Editor\Unity.exe -quit -batchmode -executeMethod MyEditorScript.MyMethod

Mac OS:

/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod MyEditorScript.MyMethod

The following command executes Unity in batch mode, and updates from the Asset server using the supplied project path. The method is executed after all Assets have been downloaded and imported from the Asset server. After the function has finished execution, Unity automatically quits.

/Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -projectPath ~/UnityProjects/AutobuildProject -assetServerUpdate 192.168.1.1 MyGame AutobuildUser l33tpa33 -executeMethod MyEditorScript.PerformBuild -quit

Unity Editor 特殊命令行参数

These should only be used under special circumstances, or when directed by Unity Support.

命令 详细信息
-enableIncompatibleAssetDowngrade 如果资源由较新的不兼容 Unity 版本制作而成,并希望将其降级以便与当前版本的 Unity 一起使用,请使用此选项。启用此选项后,如果尝试打开需要该资源的项目,Unity 会显示一个对话框,要求确认此降级。
注意:此过程不受支持且风险很高,应仅用作最后的手段。

Unity 独立平台播放器命令行参数

使用 Unity 构建的独立平台播放器也能识别一些命令行参数:

命令 详细信息
-adapter N(仅限 Windows) 允许游戏在另一个显示屏上全屏运行。N 映射到 Direct3D 显示适配器。在大多数情况下,适配器和视频卡之间存在一对一的关系。在支持多头显示器的显卡上(也就是说,可以通过一张卡驱动多个显示器),每个“头”可能是它自己的适配器。
-batchmode Run the game in “headless” mode. The game does not display anything or accept user input. This is mostly useful for running servers for networked games.
-force-d3d9 (Windows only) Force the game to use Direct3D 9 for rendering. Normally, the graphics API depends on player settings, and typically defaults to D3D11.
-force-d3d9-ref (Windows only) Force the game to run using Direct3D’s “Reference” software renderer. The DirectX SDK has to be installed for this to work. This is mostly useful for building automated test suites, where you want to ensure rendering is exactly the same no matter what graphics card is being used.
-force-d3d11(仅限 Windows) 强制游戏使用 Direct3D 11 进行渲染。
-force-d3d11-no-singlethreaded 强制在不使用 D3D11_CREATE_DEVICE_SINGLETHREADED 标志的情况下创建 DirectX 11.0。
-force-opengl (Windows only) Force the game to use OpenGL for rendering, even if Direct3D is available. Usually, OpenGL is only used if Direct3D 9.0c is not available.
-force-glcore (Windows only) 强制 Editor 使用 OpenGL Core 配置文件进行渲染。Editor 会尝试使用可用的最佳 OpenGL 版本以及 OpenGL 驱动程序公开的所有 OpenGL 扩展。如果不支持该平台,则使用 Direct3D。
-force-glcoreXY (Windows only) -force-glcore 类似,但请求特定的 OpenGL 上下文版本。XY 的可接受值:32、33、40、41、42、43、44 或 45。
-force-clamped (Windows only) -force-glcoreXY 一起使用,可防止检查其他 OpenGL 扩展,允许在具有相同代码路径的平台之间运行。
-nographics 在批处理模式下运行时,完全不初始化图形设备。这样,即使在没有 GPU 的机器上也能运行自动化工作流程。
-nolog(仅限 Linux 和 Windows) 不生成输出日志。通常,output_log.txt 写入到游戏可执行文件旁边的 *_Data 文件夹中,其中会打印 Debug.Log 输出。
-popupwindow 将窗口创建为弹出窗口,不带框架。
-screen-fullscreen 覆盖默认的全屏状态。此值必须是 0 或 1。
-screen-height 覆盖默认屏幕高度。此值必须是受支持分辨率中的整数。
-screen-width 覆盖默认屏幕宽度。此值必须是受支持分辨率中的整数。
-screen-quality 覆盖默认屏幕质量。示例用法为:/path/to/myGame -screen-quality Beautiful
-show-screen-selector 强制让屏幕选择器对话框显示。
-single-instance(仅限 Linux 和 Windows) 一次只允许运行一个游戏实例。如果另一个实例已在运行,则使用 -single-instance 再次启动会聚焦现有实例。
-parentHWND &lt;HWND> delayed(仅限 Windows) Embed the Windows Standalone application into another application. When using this, you need to pass the parent application’s window handle (‘HWND’) to the Windows Standalone application.

When passing -parentHWND 'HWND' delayed, the Unity application is hidden while it is running. You must also call SetParent from the Microsoft Developer library for Unity in the application. Microsoft’s SetParent embeds the Unity window. When it creates Unity processes, the Unity window respects the position and size provided as part of the Microsoft’s STARTUPINFO structure.

To resize the Unity window, check its GWLP_USERDATA in Microsoft’s GetWindowLongPtr function. Its lowest bit is set to 1 when graphics have been initialized and it’s safe to resize. Its second lowest bit is set to 1 after the Unity splash screen has finished displaying.
For more information, see this example: EmbeddedWindow.zip

通用 Windows 平台命令行参数

通用 Windows 应用程序默认情况下不接受命令行参数,因此要传递命令行参数,必须从 MainPage.xaml.cs/cpp 或 ** MainPage.cs/cpp** 调用一个特殊函数。例如:

appCallbacks.AddCommandLineArg("-nolog");

应在 appCallbacks.Initialize() 函数之前调用此函数。

命令 详细信息
-nolog 不生成 UnityPlayer.log。
-force-driver-type-warp 强制使用 DirectX 11.0 驱动程序类型 WARP 设备(有关更多信息,请参阅 Microsoft 的 Windows 高级光栅化平台 (Windows Advanced Rasterization Platform) 文档)。
-force-d3d11-no-singlethreaded 强制在不使用 D3D11_CREATE_DEVICE_SINGLETHREADED 标志的情况下创建 DirectX 11.0。
-force-gfx-direct 强制使用单线程渲染。
-force-feature-level–9–3 强制使用 DirectX 11.0 功能级别 9.3。
-force-feature-level–10–0 强制使用 DirectX 11.0 功能级别 10.0。
-force-feature-level–10–1 强制使用 DirectX 11.0 功能级别 10.1。
-force-feature-level–11–0 强制使用 DirectX 11.0 功能级别 11.0。

  • 2017–05–16 页面已修订并只进行了有限的编辑审查
构建播放器管线
幕后工作
Copyright © 2020 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961