Typically, Unity will be launched by double-clicking its icon from the desktop but it is also possible to run it from the command line (ie, 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.
通常情況下,Unity可以通過雙擊桌面上的圖標啟動,也可以通過輸入命令行啟動(例如,MacOS終端或者Windows的CMD窗口),通過這種方式在啟動時會接受命令和信息,這對測試對象,自動生成和其他制作任務是非常有用的。
Under MacOS, you can launch Unity from the Terminal by typing:-
在MacOs中,你可以在終端輸入以下命令來啟動Unity
/Applications/Unity/Unity.app/Contents/MacOS/Unity
...while under Windows, you should type
在windows下,你可以在CMD中輸入
"C:\Program Files (x86)\Unity\Editor\Unity.exe"
...at the command prompt. ......在命令提示符下。
Standalone Unity games can be launched in a similar way.
也可以用類似的方式啟動單獨的Unity游戲
Command Line Arguments 命令行參數
As mentioned above, the editor and also built games can optionally be supplied with additional commands and information on startup. This is done using the following command line arguments:-
如上所述,編輯器和建立游戲也能在啟動時選擇性的提供額外的命令和信息。這是使用下面的命令行參數:
- -batchmode
-
Run Unity in batch mode. This should always be used in conjunction with the other command line arguments as it ensures no pop up windows appear and eliminates the need for any human intervention. When an exception occurs during execution of script code, asset server updates fail or other operations fail Unity will immediately exit with return code 1. Note that in batch mode, Unity will send a minimal version of its log output to the console. However, the
Log Files still contain the full log information.
在批處理模式下運行Unity。應始終與其他命令行參數一起使用,因為它確保不會彈出窗口,無需任何人為的干預。當腳本代碼在執行過程中發生異常,資源服務器更新失敗或其他操作失敗時Unity將立即退出,並返回代碼為1。請注意,在批處理模式下, Unity將向控制台發送輸出版本最小的日志。當然,日志文件將包含完整的日志信息。 - -quit
-
Quit the Unity editor after other commands have finished executing. Note that this can cause error messages to be hidden (but they will show up in the Editor.log file).
其他命令執行完畢后將退出Unity編輯器。請注意,這可能會導致錯誤消息被隱藏(但他們將顯示在Editor.log文件) - -buildWindowsPlayer <pathname>
-
Build a standalone Windows player (eg, -buildWindowsPlayer path/to/your/build.exe).
建立一個單獨的Windows游戲(例如:-buildWindowsPlayer path/to/your/build.exe) - -buildOSXPlayer <pathname>
-
Build a standalone Mac OSX player (eg, -buildOSXPlayer path/to/your/build.app).
建立Mac游戲(例如:-buildOSXPlayer path/to/your/build.app) - -importPackage <pathname>
-
Import the given
package. No import dialog is shown.
導入提供的package,不會顯示導入對話框 - -createProject <pathname>
-
Create an empty project at the given path.
根據提供的路徑建立一個空項目 - -projectPath <pathname>
-
Open the project at the given path.
打開指定路徑的項目 - -logFile <pathname>
-
Specify where the Editor log file will be written.
指定將要被寫入編輯的log文件 - -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.
可通過ip端口強制更新資源服務器的項目。端口是可選的,如果不是的話可以假定一個標准端口(10733)。最好使用此命令配合- projectpath參數確保你在正確的項目里工作。如果沒有提供項目名字是那么就是最后一個Unity打開的項目。如果沒有選擇項目的路徑則由- projectpath自動創建。 - -exportPackage <exportAssetPath exportFileName>
-
Exports a package given a path. 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 can only export a whole folder at a time. This command normally needs to be used with the -projectPath argument.
根據路徑導出package。exportAssetPath是一個文件夾(相對Unity項目的根目錄)為了導出Unity項目並且exportFileName是package的名稱。目前,此選項只能在同一個時間導出整個文件夾。這個命令通常需要使用- projectpath參數 - -nographics (Windows only)
-
When running in batch mode, do not initialize graphics device at all. This makes it possible to run your automated workflows on machines that don't even have a GPU.
當運行在批處理模式,不會初始化顯卡設備。這使得它可以在你的機器上自動按工作流程運行,甚至它沒有GPU。 - -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 continous integration, perform Unit Tests, make builds, prepare some data, etc. If you want to return an error from the commandline process you can either throw an exception which will cause Unity to exit with 1 or else call
EditorApplication.Exit with a non-zero code.
在Unity啟動的同時會執行靜態方法,該項目是開放的並且是在可選資源服務器更新完成之后。這可以用來不斷的整合,進行單元測試,制作模型,准備一些數據等。如果你想通過命令行返回一個錯誤,你可以拋出一個異常,會引發代碼為1的Unity關閉或其他引發EditorApplication.Exit非零代碼。
To use -executeMethod you need to have a script in an Editor folder and a static function in the class.
使用executeMethod,你需要在編輯文件夾有一個腳本並且類里有一個靜態函數。
// C# example using UnityEditor; class MyEditorScript { static void PerformBuild () { string[] scenes = { "Assets/MyScene.unity" }; BuildPipeline.BuildPlayer(scenes, ...); } }
// JavaScript example static void PerformBuild () { string[] scenes = { "Assets/MyScene.unity" }; BuildPipeline.BuildPlayer(scenes, ...); }
Example usage 用法示例
Execute Unity in batch mode, execute MyEditorScript.MyMethod method, and quit upon completion.
在批處理模式下執行Unity,執行MyEditorScript.MyMethod方法,完成后退出。
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
Execute Unity in batch mode. Use the project path given and update from the asset server. Execute the given method after all assets have been downloaded and imported from the asset server. After the method has finished execution, automatically quit Unity.
在批處理模式下執行Unity。使用給定的項目路徑和從資源服務器上進行更新。在所有資源已被下載且從資源服務器導入后執行給定的方法。當執行的方法完成后會自動退出Unity。
/Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -projectPath ~/UnityProjects/AutobuildProject -assetServerUpdate 192.168.1.1 MyGame AutobuildUser l33tpa33 -executeMethod MyEditorScript.PerformBuild -quit
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 for
networked 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).
這個窗口將以彈出的方式創建(沒有框體)