使用Visual Studio 2019加快Unity中的编程工作流的10种方法

Visual Studio 2019 offers world-class debugging, and lots of new tools and customization options so that you can set up your coding environment exactly the way you want it. It also comes with a range of powerful features for working with C# in Unity that helps you write and refactor code quicker than before. In this blog post, we will take a look at 10 tips on some of these features which may speed up your workflow too.

Visual Studio 2019提供了世界一流的调试功能,以及许多新工具和自定义选项,因此您可以完全按照自己的方式设置编码环境。 它还具有用于在Unity中使用C#的一系列强大功能,可帮助您比以前更快地编写和重构代码。 在此博客文章中,我们将介绍其中一些功能的10个技巧,这些技巧也可能会加速您的工作流程。

Our Unity evangelist Arturo Nereu and Abdullah Hamed, program manager for Visual Studio Tools for Unity at Microsoft, recently hosted a Unite Now session sharing tips and tricks on how to get the most out of Visual Studio 2019 when developing in Unity.

我们的Unity传播者 Arturo Nereu 和 Microsoft Visual Studio Tools for Unity的项目经理 Abdullah Hamed 最近 主持了一个Unite Now会话, 共享有关在Unity中进行开发时如何充分利用Visual Studio 2019的技巧和窍门。

演示地址

This post shows a quick overview of some of these tips. We also added links directly to those sections from the talk as well as other related content, if you want to dig deeper.

这篇文章展示了其中一些技巧的快速概述。 如果您想深入了解,我们还直接添加了指向演讲中这些部分以及其他相关内容的链接。

提示1:将调试器附加到Unity and Play (Tip 1: Attach the Debugger to Unity and Play)

Using Console.Log is an easy and quick way to help debug your project utilizing Unity’s console view. However, Visual Studio offers a more efficient way which becomes increasingly valuable as your project gets more complex. In Visual Studio, simply click the Attach to Unity button in the Visual Studio menu. This creates a connection between the two applications so that you can insert breakpoints and step through your code, while being in Play mode in Unity. You can also click Attach to Unity and play to start the execution without leaving your IDE. The beauty here is that it allows you to inspect the state of your code flow and values of the properties etc. at runtime. While this may seem trivial, being able to pause the execution at any time during gameplay and step through to inspect the specific state of the game and values of your properties in that exact frame, is a very powerful tool when debugging. 

使用 Console.Log 是使用Unity的控制台视图帮助调试项目的简便快捷方法。 但是,Visual Studio提供了一种更有效的方法,随着您的项目变得越来越复杂,它变得越来越有价值。 在Visual Studio中, 只需单击 Visual Studio菜单中的 附加到Unity” 按钮 。 这将在两个应用程序之间建立连接,以便您可以在Unity的“播放”模式下插入断点并单步执行代码。 您也可以单击 附加到Unity并播放 以开始执行而无需离开IDE。 这里的好处是,它允许您在运行时检查代码流的状态以及属性的值等。 尽管这似乎微不足道,但是在调试时,能够在游戏过程中随时暂停执行并逐步检查游戏的特定状态以及该属性在特定框架中的属性值是非常强大的工具。


Another handy option when working with breakpoints is that you can insert your own conditions with related actions such as a conditional expression which has to evaluate as true before applying in your debug flow. 


使用断点时的另一个方便的选择是,您可以 将自己的条件插入 相关操作中,例如条件表达式,在应用到调试流程之前必须将条件表达式评估为true。

提示2:获取性能见解和最佳实践建议 (Tip 2: Get performance insights and suggestions for best practices )

Visual Studio 2019 introduces Unity Analyzers. An analyzer works by detecting a code pattern and can offer to replace it with a more recommended pattern. Unity Analyzers are a collection of Unity-specific code diagnostics and code fixes that are open source and available on GitHub. Analyzers can provide you with a better understanding of Unity-specific diagnostics or simply help your project by removing general C# diagnostics that don’t apply to Unity projects. An example could be a simple conditional statement where you need to check if the GameObject has a specific tag to apply a certain behavior to it.

Visual Studio 2019引入了Unity分析器。 分析器通过检测代码模式来工作,并可以提出用更推荐的模式替换它。 Unity Analyzers是Unity特定的代码诊断和代码修复的集合,这些诊断和代码修复是开源的,可以在 GitHub上获得 。 分析器可以使您更好地了解Unity特定的诊断,或者通过删除不适用于Unity项目的常规C#诊断来帮助您的项目。 一个示例可能是一个简单的条件语句,您需要在其中检查GameObject是否具有特定标签以对其应用特定行为。

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值