Unity中Debug的用法

UnityEngine.Debug:

Class containing methods to ease debugging while developing a game.

該類中包含了一些便於遊戲開發時的調試方法。
Class Variables

 isDebugBuild

static var isDebugBuild : boolean

In the Build Settings dialog there is a check box called "Development Build".

在"Build Settings" 對話框中有一個"Development Build"的選項。

If it is checked isDebugBuild will be true. In the editor isDebugBuild always returns true. It is recommended to remove all calls toDebug.Log when deploying a game, this way you can easily deploy beta builds with debug prints and final builds without.  

如果複選框被選擇,isDebugBuild則爲true。在編輯器中isDebugBuild總是返回true。在遊戲發佈時,這個命令可以移除所有Debug.Log調用。這樣,你就可以輕鬆地發佈帶有調試輸出的測試版和沒有這些調試信息的最終版。

Class Functions

 DrawLine

static function DrawLine (start :Vector3, end :Vector3, color :Color =Color.white, duration : float = 0.0f) : void

Draws a line from the point start to end with color for a duration of time. If duration is 0 then the line is rendered 1 frame.

繪製一條從開始點到結束點的線,需要指定繪線的顏色和持續時間。如果持續時間爲0,那麼該線只會被渲染1幀。

The line will be drawn in the scene view of the editor. If gizmo drawing is enabled in the game view, the line will also be drawn there.

該線被繪製在編輯器下的Scene窗口中。如果Gimzo繪製方法被開啓,那麼該線同樣會被繪製到Game窗口中。

 DrawRay

static function DrawRay (start :Vector3, dir :Vector3, color :Color =Color.white, duration : float = 0.0f) : void
Draws a line from start to start + dir with color for a duration of time. If duration is 0 then the line is rendered 1 frame.

從開始點繪製一條dir方向和長度的線,需要指定繪線的顏色和持續時間。如果持續時間爲0,那麼該線只會被渲染1幀。

The line will be drawn in the scene view of the editor. If gizmo drawing is enabled in the game view, the line will also be drawn there.

該線被繪製在編輯器下的Scene窗口中。如果Gimzo繪製方法被開啓,那麼該線同樣會被繪製到Game窗口中。

 Break

static function Break () : void

Pauses the editor.

使編輯器暫停。

This is useful when you want to check certain values on the inspector and you are not able to pause it manually.

當你想在運行到某種情況下游戲自動暫停下來以方便你查看對象屬性面板中的值時,這是非常有用的。

 Log

static function Log (message : object) : void

Logs message to the Unity Console.

將日誌信息輸出到Unity控制檯。

static function Log (message : object, context :Object) : void
Logs message to the Unity Console.

將日誌信息輸出到Unity控制檯。

When you select the message in the console a connection to the context object will be drawn. This is very useful if you want know on which object an error occurs.

當你在控制檯中選中調試信息時,Unity將繪製一個調試信息與觸發對象之間的連接。當你想知道在哪個對象上發送錯誤時,這是非常有用的。

 LogError

static function LogError (message : object) : void

A variant of Debug.Log that logs an error message to the console.

Debug.Log的一個變種,它將輸出一個Erro類型的調試信息到控制檯。

static function LogError (message : object, context :Object) : void

A variant of Debug.Log that logs an error message to the console.

Debug.Log的一個變種,它將輸出一個Erro類型的調試信息到控制檯。

When you select the message in the console a connection to the context object will be drawn. This is very useful if you want know on which object an error occurs.

當你在控制檯中選中調試信息時,Unity將繪製一個調試信息與觸發對象之間的連接。當你想知道在哪個對象上發送錯誤時,這是非常有用的。 

 Warning

static function LogWarning (message : object) : void
A variant of 
Debug.Log that logs a warning message to the console.

Debug.Log的一個變種,它將輸出一個Warning類型的調試信息到控制檯。

static function LogWarning (message : object, context : Object) : void

A variant of Debug.Log that logs a warning message to the console.

Debug.Log的一個變種,它將輸出一個Warning類型的調試信息到控制檯。

When you select the message in the console a connection to the context object will be drawn. This is very useful if you want know on which object a warning occurs.

當你在控制檯中選中調試信息時,Unity將繪製一個調試信息與觸發對象之間的連接。當你想知道在哪個對象上發送錯誤時,這是非常有用的。

 

Unity調試方法:

1.安裝Unity3D安裝包內置的MonoDevelop,MonoDevelop官方下載的版本是沒有Unity3D 的調試插件的。

2.打開Unity ,選擇Edit –> Preference ,設置外部編輯器爲MonoDevelop 。

3.運行MonoDevelop(如果MonoDevelop不能運行,則需要安裝 .Net 3.5 ),選擇菜單(Tools –> Preference) 打開選項設置窗口,在左邊的導航窗口的最後一個節點(Unity –> Debugger),在右邊設置Editor Location爲正確的位置(即Unity.exe執行文件Path),然後勾選Launch Unity Automatically和Build Project in MonoDevelop ,按OK按鈕保存。

4.在Unity Editor的Project窗口點擊鼠標右鍵,在彈出菜單中選擇Sync MonoDevelop Project(或者選擇菜單欄中的Assets -> Sync MonoDevelop Project),將自動運行MonoDevelop並打開對應的項目。

5.在MonoDevelop中編程、爲源代碼設置斷點(F9),關閉Unity Editor,擊調試按鈕(F5)開始調試,在自動打開的Unity Editor中點擊Play按鈕,斷點就開始起作用了。

6.MonoDevelop的調試需要完成本幀所有調試才能返回給Unity,即調試中途Unity Scene的信息將不會更新。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章