使用Mac开发Unity项目时,使用VS总会出现一些未知的小问题,写起来也很不方便,于是给VSCode配置了开发Unity所需要的基础环境,本文篇幅并不长,VSCode里面还有很多别的个性化配置可以再自己Diy一下。
配置后效果如下:
首先阅读官方文档Visual Studio Code and Unity
描述如下:
Prerequisites#
From Using .NET Core in Visual Studio Code:
- Install the .NET Core SDK, which includes the Runtime and the dotnet command.
- [Windows only] Logout or restart Windows to allow changes to %PATH% to take effect.
- [macOS only] To avoid seeing “Some projects have trouble loading. Please review the output for more details”, make sure to install the latest stable Mono release.
Note: This version of Mono, which is installed into your system, will not interfere with the version of MonoDevelop that is installed by Unity. - Install the C# extension from the VS Code Marketplace.
方式一:
下载地址:Download .NET 5.0
下载完成后直接打开安装即可
方式二:
如果mac电脑安装了 HomeBrew,也可以通过如下命令进行下载安装
#安装 brew install dotnet-sdk #查看安装是否成功 dotnet --version跨平台 .NET 环境 Mono(macOS)
对于 macOS 需要安装跨平台 .NET 环境 Mono
下载地址:Download - Stable | Mono
根据自己的需求,下载对应的版本,下载完成后直接打开安装即可
安装完成后输入mono --version检验是否安装成功,如下表示成功安装
下载地址:Download Visual Studio Code
接下来需要安装几个插件,在官方文档中也有列出来,如下图:
我自己安装的插件如下:
C# C# Extensions C# FixFormat Fixed Debugger for Unity Unity Tools Unity Code Snippets Unity Snippets Modified Unity Snippets #用惯了idea的快捷键所以下载的,可根据个人需求安装此插件 IntelliJ IDEA Keybindings3. 配置omnisharp
如果不配置这个,确实可以开发了,但是各种类型不认
设置路径:Code -> Preferences -> Settings, 检索mono, 点击settings.json
接下来需要重新编辑 settings.json,在最后新增如下两句配置:
"omnisharp.monoPath": "/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono", "omnisharp.useGlobalMono": "always"3. 设置.zshrc/.bash_profile环境变量(目前我自己发现设不设没有影响)
export FrameworkPathOverride=/Library/Frameworks/Mono.framework/Versions/Current
4. 代码调试(可选配置) 1. 创建启动文件如果OUTPUT 处开始下载最新版的 OmniSharp(这里有个小坑),需要等到下载完成(一定要下载完成,请记住, Windows 用户这里不需要担心,VSCode 会弹出提示框自行下载,比 macOS 要便捷的多
打开 VSCode,在左侧栏中选择调试按钮,在点击create a launch.json file
在搜索框中搜索 Unity Debbger 或者直接在下拉列表中寻找这个选项
通过点击绿色三角形就进行调试了
设置路径:Unity-> Preferences -> External Tools
因为下载的版本较新,所以需要在 Unity 中修改 .NET 的版本到 4.X
修改路径:Edit->Project Settings->Player
现在就可以各种愉快的开发Unity了



