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.html
一般狀況下,Unity能夠經過雙擊桌面上的圖標啓動,也能夠經過輸入命令行啓動(例如,MacOS終端或者Windows的CMD窗口),經過這種方式在啓動時會接受命令和信息,這對測試對象,自動生成和其餘製做任務是很是有用的。windows
Under MacOS, you can launch Unity from the Terminal by typing:-服務器
在MacOs中,你能夠在終端輸入如下命令來啓動Unity網絡
/Applications/Unity/Unity.app/Contents/MacOS/Unity
app
...while under Windows, you should typeless
在windows下,你能夠在CMD中輸入編輯器
"C:\Program Files (x86)\Unity\Editor\Unity.exe"
ide
...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).
這個窗口將以彈出的方式建立(沒有框體)