Unity中的调试

来源:互联网 发布:国家安全网络宣传周 编辑:程序博客网 时间:2024/04/20 05:26

Unity中的调试  

2011-12-01 00:39:51|  分类:Unity |  标签:|字号 订阅

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的信息将不会更新。

 

实例演示:

using UnityEngine;using System.Collections;

public class GUITest : MonoBehaviour{    int i = 0;    void OnGUI()    {        if (GUI.Button(new Rect(0, 0, 100, 50), "Cliclk"))        {            i++;            Debug.DrawLine(transform.position, transform.position + 5 * Vector3.up, Color.red, 5);            Debug.DrawLine(transform.position, transform.position + 5 * Vector3.right, Color.green, 5);            Debug.DrawLine(transform.position, transform.position + 5 * Vector3.forward, Color.blue, 5);            Debug.LogError("Click", this);        }    }}

Game:
Unity中的调试 - LoveGame - 游戏人生
Scene:
Unity中的调试 - LoveGame - 游戏人生
MonoDevelop:
Unity中的调试 - LoveGame - 游戏人生
 
 
原创粉丝点击