Debugging in Unity (C#) + Visual Studio Code Work

2020-06-08 05:09发布

I really like the idea of working with Visual Studio, C# and Unity on OS X.

Has anyone made debugging with C# in Unity work with Visual Studio Code on OS X?

8条回答
Fickle 薄情
2楼-- · 2020-06-08 05:30

Hi the solution is https://github.com/dotBunny/VSCode This plugin works on both MacOS and Windows and gives you the following capabilities:

•An option to enable VS Code integration (Editor –> Assets –> Enable Integration), this updates your solution files and (more importantly) keeps them in sync. This also sets the preferred external tool editor in the Unity preferences. *Note, the old “Sync MonoDevelop” option is now gone in the Unity editor from V5.2

•It writes out the necessary (and sometimes hard to find) VS Code configuration files, including the ability to hide “non-code” files in the editor (hides things like .sln, .csproj and the ever present unity .meta files) There are a couple of other settings in there to help speed up the integration.

•Automatically launches VS Code direct to your project folder, EVERY-TIME. no longer do you have to worry about keeping that window open, or switching around if you work on multiple projects

One thing to be aware of, once you enable the VSCode integration, changing your preferred code editor in the External Tools preferences will have no effect as the plugin takes over opening code files. If you want to use another editor, you’ll have to disable the integration first.

unity_plugin

These are just the main highlights as there are more features in there as well.

Currently you need to download the plugin files from GitHub

查看更多
闹够了就滚
3楼-- · 2020-06-08 05:32

To build Unity in Visual Studio Code, you can hook up Mono xbuild compiler as a task runner, so you don't even have to leave IDE to have errors and warnings.

See https://twitter.com/_eppz/status/846859856787259392 for more.

查看更多
我只想做你的唯一
4楼-- · 2020-06-08 05:32

Update, 2016 - the petition was popular enough that some VS Code extensions have been written for it: https://marketplace.visualstudio.com/search?term=unity&target=VSCode&sortBy=Relevance


Petition for it on the Visual Studio UserVoice page: http://visualstudio.uservoice.com/forums/293070-visual-studio-code/suggestions/7752702-unity-integration

查看更多
迷人小祖宗
5楼-- · 2020-06-08 05:33

It's a little unstable. But it's possible from recent VSC version.

1) Install this VSC Unity plugin-in. https://github.com/dotBunny/VSCode/

2) Follow these commands. (Step 1, 2 and 3) https://code.visualstudio.com/Docs/runtimes/unity

3) After you complete the settings, launch the VSC using Unity menu.

Assets/Open C# Project in Code

4) Play the Unity project. You can see the debug port number on the unity console. And the project's launch.json file will be renewed automatically.

To open launch.json, click option icons. enter image description here
the file exists in this folder.

.vscode/launch.json

sample.

{
    "version":"0.1.0",
    "configurations":[ 
        {
            "name":"Unity",
            "type":"mono",
            "address":"localhost",
            "port":56621
        }
    ]
}

5) Start debug in VSC debug tab.

That's it. Hope this help.

查看更多
ゆ 、 Hurt°
6楼-- · 2020-06-08 05:34

Yes it works absolutely fine. Unity is C#, JavaScript or Boo. So, you don't need .NET for it. Unity uses Mono runtime. So, an existing VS project can be opened in Unity for Mac OS X.

EDIT

Here is a link that helps you to attach a debugger to the VS endpoint. http://www.yunspace.com/2015/01/19/integrating-visualstudio-with-unity3d-on-mac-using-vstools/

You can try VS Tools for Unity too. http://unityvs.com

UPDATE

There is this awesome Unity Plugin by dotBunny that solves the problem and integrates Code with Unity tools.

查看更多
一夜七次
7楼-- · 2020-06-08 05:44

[Feb 2017] It is now possible to do this without the dotBunny plugin.

i.e. Support is built into Unity natively.

Just to repeat, you don't need to fiddle with Unity, just VSCode.

Instructions here

Instructions are incomplete though, and I didn't take screenshots (please do!), but basically what I did was:

(...and please improve these instructions as you go, I'm working from memory...)

  1. I deleted/renamed my .vscode/Launch.json file, as per the link.
  2. Double-click on some file to bring up the project in VSCode (maybe first make sure that in Unity's settings you have selected VSCode as your default code editor)
  3. clicking the bug icon then the cogwheel, as per the link.
  4. I had to install that vscode-unity-debug plugin in VSCode, just filtering the search with 'unity' found it.
  5. I then had to press the green 'play' triangle.
  6. I set a breakpoint in my code.
  7. Now over to unity and press play, and the breakpoint gets hit.
查看更多
登录 后发表回答