整合Unity游戏引擎和 Visual Studio Code 代码编辑器 第二弹

孙广东 2015.10.22

Visual Studio Code can be a great companion to Unity for editing and debugging C# files. All of the C# features are supported and more. In the screen below you can see code colorization, bracket matching, IntelliSense, Code Lens and that’s just the start.

Read on to find out how to configure Unity and your project to get the best possible experience.

Note: VS Code uses a more recent version of Mono than that included with Unity. If you get OmniSharp errors, you may need to update your Mono version. See this for additional details.

Connecting Unity and VS Code

The easiest way to get going is to leverage a Unity plug-in maintained by @Reapazor. This plug-in streamlines the integration process significantly by performing the following tasks:

Note: Debugging support is only offered on OS X today. Windows does not support debugging via Mono. We have also not done any significant testing of the plug-in with the Linux Unity build.

Step 1: Download the plug-in code

Open up a console and do a clone of the repo to get the plug-in source code.

git clone https://github.com/dotBunny/VSCode.gitStep 2: Add the plug-in to your project

Go to the folder where you downloaded the plug-in source code and copy the Plugins\Editor\dotBunny folder to your Unity project.

Tip: You may need to create a Plugins folder. Typically this should be stored under Assets.

To turn on the use of the provided integration you will need to go to Unity Preferences and select the newly created VSCode tab.

Click the browse button and set the VS Code executable (under Program Files (x86)\Microsoft VS Code\Code.exe) as the External Script Editor.

This will enable Unity to launch VS Code whenever you open a script.

Q: I want to set the command line arguments when I launch VS Code.

A: The workflow between Unity and VS Code is much smoother if you reopen an existing editor window and pass in context so that the editor lands on the exact line number and column location (for example to navigate to a compile bug).

Note: This option is only available in the Windows version of Unity. For Mac users, the Unity plug-in described above handles setting up the command line arguments.

To configure Unity to pass this data to VS Code, set the Editor Args to be -r -g "$(File):$(Line). You can see this step completed in the image above.

Q: How can I change the file exclusions?

A: Unity creates a number of additional files that can clutter your workspace in VS Code. You can easily hide these so that you can focus on the files you actually want to edit.

我们人生中最大的懒惰,就是当我们明知自己拥有作出选择的能力,

整合Unity游戏引擎和 Visual Studio Code 代码编辑器 第二弹

相关文章:

你感兴趣的文章:

标签云: