Unity3D自带MonoDevelop编辑器断点调试教程

断点调试功能可谓是程序员必备的功能了。Unity3D支持编写js和c#脚本,但很多人可能不知道,其实Unity3D也能对程序进行断点调试的。不过这个断点调试功能只限于使用Unity3D自带的MonoDevelop编辑器。而用Visual Studio是不行的。听说有个叫做UnityVS的东西可以使用VS对Unity进行断点Debug,不过没试过。

好了,简单的说说做法吧:

首先肯定是先要把脚本编辑器指定为MonoDevelop了

选择好之后,可以在项目面板右键选择Sync MonoDevelop Project来打开MonoDevelop。

因为需要有脚本才能对脚本进行调试,所以我写了个很简单的脚本,里面有两个按钮,按第一个“add”按钮的时候,程序会用一个循环的方式把从0到9的数加起来,然后累加给sum。按第二个按钮时,会把sum清零。 

写好脚本之后,把脚本随便拖到场景的物体上面,我们准备调试了。在调试之前,我们需要把MonoDevelop和Unity3D进行连接。

具体的连接方法有2种:

第一种,先把当前场景保存一下,然后关掉Unity。回到MonoDevelop,按F5或者点击Debug按钮。

这样,MonoDevelop会打开一个新的Unity3D界面,这时候连接完成了。

第二种方法,无需关掉Unity,在MonoDevelop的Run菜单下选择Attach to Process 

然后选择Unity的进程,点击Attach按钮。

 这时候,MonoDevelop就连接上了Unity了。

当连接好了Unity3D之后,右边的调试按钮就变成可用了,我们把视窗显示选择Debug。

debug模式脚本下面的位置会多出两个窗口。 

回到Unity,点击运行按钮,会看到刚才的脚本已经运行了。里面有两个按钮。 

回到MonoDevelop,在脚本里面我们打一个断点(在行号左边点一下) 

 然后回到Unity里面,点击第一个按钮“add”。这时候断点起作用了,程序会暂停,MonoDevelop跳到断点的行。

留意看下面debug的Locals信息,会看到当前状态下的变量i和sum的值。

使用调试按钮,让程序单步的运行

我们看到了当前的变量i和sum的实际变化情况。

到这里,断点调试已经完成。

调试完之后,我建议最好把MonoDevelop和Unity3D的连接断开。假如你不断开的话,Unity会一直处于很卡的状态。

断开的方法也是有几种了,首先对应Debug按钮有一个断开的按钮,可以直接点击断开。

或者我们可以把刚才附加的进程Detach掉。 

再或者,我们可以点击这个插头按钮,把Debugger 断开。

这两种方法连接Unity,我建议还是使用第二种附加进程的方式吧。毕竟你不可能每次调试都要关掉一次Unity然后再从MonoDevelop打开一次Unity。所以,编写脚本的时候,把连接Detach掉,等需要调试的时候,再把进程Attach上去,进行调试就行了。

请看安装说明安装 很难的的工具 1. If you have previously installed UnityVS uninstall it now, run ccleaner to remove any left over files & registry keys and reboot. 2. Run UnityVS 2012.msi to install UnityVS 3. Run "make Dir.bat" as ADMINISTRATOR, if you see any errors then make sure you have admin rights and run it again. 4. Right click "copy rhino.bat" and choose edit to open it in notepad 5. replace PATH_TO_THIS_DIRECTORY with the directory which you extracted the .bat and "Rhino.Licensing.dll" to. You should end up with something that looks like this 'copy "D:\extracted\Rhino.Licensing.dll" "%SystemRoot%\assembly\GAC_MSIL\Rhino.Licensing\1.2.0.0__0b3305902db7183f"' 6. Save the edit .bat and run it as ADMINISTRATOR, if you get any errors check the file again and make sure it saved correctly. 7. Navigate to "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\SyntaxTree\UnityVS" and DELETE the "Rhino.Licensing.dll" File (it should ask you for admin rights to do this) 8. Now move (Cut & paste) the "log4net.dll" file from the current UnityVS Directory to the Visual Studio IDE directory (Go up 3 Directories - "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE") 9. Launch Visual Studio 2012 (If you get any errors from visual studio at this point or after make sure you've followed every step correctly, if you have uninstall UnityVs, uninstall visual studio 2012, run ccleaner for both temp files and the registry then reboot and start again) 10. It should now prompt you for your key, open up the key.txt extracted earlier and copy the contents into the box, it should now enable the OK button, click that and you're done! 11.If you still have errors after installing the crack try changing "1.2.0.0__0b3305902db7183f" to "1.2.0.0__49e34be443e62e2a" in both the make dir.bat and copy rhino.bat files and run them again.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值