Coding4Fun is doing a VS Code Theme Week and I tried to hunt down something, anything, related to the Kinect and VS Code.
Well, I've been blogging about the Kinect and Unity a bunch, so showing how VS Code and Unity work together is close enough, right? Um... yeah... It's a stretch, but close enough. :)
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 FAQ topic for additional details.
Connecting Unity and VS Code
- Sets VS Code as the default editor - opening a script now opens it in VS Code
- Configures Unity to pass file and line numbers and reuse the existing window - so VS Code opens in the correct context
- Scrubs the Unity project file to ensure that OmniSharp can work with it - to get the best editing experience
- Configures VS Code to ignore certain Unity file types - removing clutter from the VS Code file explorer
- Configures a
launch.jsonfile with the correct debug port - to enable debugging
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
With the solution file selected, you are now ready to start editing with VS Code. Here is a list of some of the things you can expect:
- Syntax Highlighting
- Bracket matching
- Code Lens
- Go-to Definition
- Code Actions/Lightbulbs
- Go to symbol
Read on to learn more about:
Project Information URL: https://code.visualstudio.com/docs/runtimes/unity
Today (September 10th) marks another notch in the VS Code journey to become THE lightweight multi-platform editor, the one editor to rule them all.
If you’ve been following previous articles of mine and others, there has been a big push to use VS Code’s C# features with Unity and to integrate them together seamlessly (well almost)
This wasn’t without pain however:
- When you opened VS Code for the first time, you had to go through a process to open your project folder to get Intellisense working
- If you accidentally closed VS Code, you had to repeat the above again
- If you were working on multiple project, well it was a pain.
- Unity does not have a concept of a folder when launching an external application, so couldn’t help.
Most devs however were happy to live with these constraints as the flexibility, power and speed they got from using the editor.
That is until NOW.
Enter VS Code Version 0.8.0
The VS Code team haven’t been sitting on their laurels, they have listened, they have watched and through it all (with the help of the community) they have acted.
As of 0.8.0, the Unity integration has gotten even tighter and most of the old hindrances have been cast aside, giving developers a much more fluid working environment (and if you are on a MAC, it’s even better #Grumble)
You can grab VS Code direct from the VS Code website at:
If you are on Windows, you’ll notice the installer also got an upgrade, so they can deliver more features directly to your machine. If you don’t like automatic updating, you can also turn that off if you wish (https://code.visualstudio.com/Docs/supporting/FAQ#_how-do-i-opt-out-of-vs-code-autoupdates).
Starting with the documentation, Unity has been promoted as one of the main integration’s for VS code, now with its own documentation page, which you can find here:
There’s lots of info in here, some of which I’ll highlight next.
An integration asset
Thanks to a community member who jumped straight on the insider track for VS Code, a Plugin has been built for Unity to streamline the integration.
To use this plugin, you need a minimum of Unity V5.0+ and VSCode 0.8.0 (for best results I found uninstalling the old version of VSCode first and then installing the latest best)
This can be found at:
Project Information URL: http://darkgenesis.zenithmoon.com/vscode-and-unity-take-another-bold-step-forward/
In the previous videos we discussed how to integrate Unity and Visual Studio Code from scratch. But thanks to Unity plugin from @reapazor you can simplify this work.
As you know, it’s possible to use Unity plugins to extend Unity interface and execute almost everything. If you have source code of a Plugin you simply need to place it anywhere in the Assets folder and Unity will compile it on fly and use attributes there to extend the standard menu.
The VS Code plugin contains one source code file only, so, you can clone the full repository using
git clone https://github.com/dotBunny/VSCode.git
or extract the file itself from zip package.
In my experiments I am using Unity3D 5.2, so it’s not very important where to place this file. For example, you can place it as before using Plugins/Editor folder or you can select any other folder in your Assets tree.
Once you add the file to your Assets folder, Unity will compile it, and you can find new menu item using the context menu or Assets menu item: Open C# Project in Code.
Using Open C# Project in Code you can open Visual Studio Code and it will open the right catalog and select the right project by default. But the plugin supports much more things. In order to see al features there, let’s open Unity->Preferences and you will find VSCode there:
Let’s make a short overview to the options there:
- Enable Integration – if this option is checked, you can use VS Code as the default editor. This option should be on by default but you can change it any time instead by using Unity->Preferences->External Tools tab;
- Always Write Launch File – by default you cannot debug the project. In order to enable debugging you need to create launch.json file and configure it. But the plugin can create the launch.json for you. In order to do it you need to enable this feature, turning on the checkbox and run your project from Unity editor. The plugin will read information about the debugging port and update/create launch.json file;
- Write Workspace Settings – If you open your project in VS Code you can find lots of different files that you don’t want to see. It’s easy to fix, add your own settings for the workspace and exclude all not needed files. Using this button, you can do it automatically – just click it;
(the latest version contains one more checkbox and a button that allow to update the plugin without visiting GitHub).
So, as you can see we spent less time than before in order to integrate Unity and VS Code using the plugin. ...
Project Information URL: http://blogs.msdn.com/b/cdndevs/archive/2015/10/16/a-better-way-to-integrate-code-and-unity.aspx