IT圈老男孩1 发表于 2023-2-2 07:34

Unity3d命令行参数 Command line arguments

题外话:最近在帮忙做一个PC端的Unity游戏,刚好他的应用程序启动用到了命令行参数,主要作用就是可以把Unity开发的游戏客户端既可以作为客户端启用,也可以通过命令行参数当做服务器启动,作为一个服务器使用。所以就整理了一下网上的Unity命令参数,自我积累的同时也能帮助一下需要这方面资料的人。

通常情况下,Unity可以通过双击桌面上的图标启动,也可以通过输入命令行启动(例如,MacOS终端或者Windows的CMD窗口),通过这种方式在启动时会接受命令和信息,这对测试对象,自动生成和其他制作任务是非常有用的。

在MacOs中,你可以在终端输入以下命令来启动Unity(下面是我的Unity安装目录)
/Applications/Unity/Unity.app/Contents/MacOS/Unity

在windows下,你可以在CMD中输入(下面是我的Unity安装目录)
"C:\Program Files (x86)\Unity\Editor\Unity.exe"

如上所述,编辑器和建立游戏也能在启动时选择性的提供额外的命令和信息。这是使用下面的命令行参数
-batchmode
在批处理模式下运行Unity。应始终与其他命令行参数一起使用,因为它确保不会弹出窗口,无需任何人为的干预。当脚本代码在执行过程中发生异常,资源服务器更新失败或其他操作失败时Unity将立即退出,并返回代码为1。请注意,在批处理模式下, Unity将向控制台发送输出版本最小的日志。当然,日志文件将包含完整的日志信息。
-quit
其他命令执行完毕后将退出Unity编辑器。请注意,这可能会导致错误消息被隐藏(但他们将显示在Editor.log文件)
-buildWindowsPlayer <pathname>
建立一个单独的Windows游戏(例如:-buildWindowsPlayer path/to/your/build.exe)
-buildOSXPlayer <pathname>
建立Mac游戏(例如:-buildOSXPlayer path/to/your/build.app)
-importPackage <pathname>
导入提供的package,不会显示导入对话框
-createProject <pathname>
根据提供的路径建立一个空项目
-projectPath <pathname>
打开指定路径的项目
-logFile <pathname>
Specify where the Editor log file will be written.
指定将要被写入编辑的log文件
-assetServerUpdate <IP[:port] projectName username password >
可通过ip端口强制更新资源服务器的项目。端口是可选的,如果不是的话可以假定一个标准端口(10733)。最好使用此命令配合- projectpath参数确保你在正确的项目里工作。如果没有提供项目名字是那么就是最后一个Unity打开的项目。如果没有选择项目的路径则由- projectpath自动创建。
-exportPackage <exportAssetPath exportFileName>
根据路径导出package。exportAssetPath是一个文件夹(相对Unity项目的根目录)为了导出Unity项目并且exportFileName是package的名称。目前,此选项只能在同一个时间导出整个文件夹。这个命令通常需要使用- projectpath参数
-nographics (Windows only)
当运行在批处理模式,不会初始化显卡设备。这使得它可以在你的机器上自动按工作流程运行,甚至它没有GPU。
-executeMethod <ClassName.MethodName>
在Unity启动的同时会执行静态方法,该项目是开放的并且是在可选资源服务器更新完成之后。这可以用来不断的整合,进行单元测试,制作模型,准备一些数据等。如果你想通过命令行返回一个错误,你可以抛出一个异常,会引发代码为1的Unity关闭或其他引发EditorApplication.Exit非零代码。

Unity Standalone Player command line arguments
Unity 独立版游戏命令行参数
Standalone players built with Unity also understand some command line arguments:
Unity创建独立版游戏也要了解一些命令行参数:
-batchmode
Run the game in "headless" mode. The game will not display anything or accept user input. This is mostly useful for running servers fornetworked games.
在"headless"模式下运行游戏。游戏将不显示任何内容,或接受用户输入。这对运行网络游戏的服务器有很大的作用的。
-force-opengl (Windows only)
Make the game use OpenGL for rendering, even if Direct3D is available. Normally Direct3D is used but OpenGL is used if Direct3D 9.0c is not available.
让游戏使用OpenGL进行渲染,即使有可用的Direct3D。通常情况是使用Direct3D,但如果是Direct3D 9.0c的不可用的话则会选用OpenGL。
-single-instance (Windows only)
Allow only one instance of the game to run at the time. If another instance is already running then launching it again with -single-instance will just focus the existing one.
在同一时候只允许一个游戏实例运行。如果另一个实例已在运行,然后再次通过 -single-instance启动它的话会调节到现有的这个实例。
-nolog (Windows only)
Do not produce output log. Normally output_log.txt is written in the *_Data folder next to the game executable, where Debug.Log output is printed.
不产生输出日志。 通常output_log.txt被写在游戏输出目录下的*_Data文件夹中 ,在debug.log中打印输出的地方。
-force-d3d9-ref (Windows only)
Make the game 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.
使游戏运行在Direct3D的"Reference"软件渲染模式,必须要安装DirectX SDK才能使其工作。这主要是用于建立自动化测试对象,这样您可以确保不管是使用什么显卡,其渲染效果是完全一样的。
-adapter N (Windows only)
Allows the game to run full-screen on another display, where N denotes the display number.
允许游戏全屏运行在另一台显示器上,其中N表示显示的号码。
-popupwindow (Windows only)
The window will be created as a a pop-up window (without a frame).
这个窗口将以弹出的方式创建(没有框架)
页: [1]
查看完整版本: Unity3d命令行参数 Command line arguments