[英]How to get intellisense in Visual Studio Code for Unity functions names?
I am following a tutorial about Unity and I see that the instructor has intellisense when writes the method's name.我正在关注有关 Unity 的教程,并且我看到讲师在编写方法名称时具有智能感知功能。
However I have only intellisense with classes and variables, I mean Unity classes like Rigidbody and my own variables.但是我只有类和变量的智能感知,我的意思是像刚体这样的 Unity 类和我自己的变量。
I have also read: Autocompletion not working in Visual studio我还阅读了: Autocompletion not working in Visual Studio
How to enable intellisense in Visual Studio 2017 for Unity 如何在 Visual Studio 2017 for Unity 中启用智能感知
Old question, but I had the same problem just recently.老问题,但我最近遇到了同样的问题。
There must have been an issue in your Assembly-CSharp.csproj or project-name.sln files.您的Assembly-CSharp.csproj或project-name.sln文件中一定存在问题。 Most likely to be the .csproj file.最有可能是.csproj文件。 If you take a look at it, you will see various references to .dll files.如果你看一看,你会看到对 .dll 文件的各种引用。
You can tell Unity (my version: v2019.2.20f1 ) to create these for you by enabling Edit > Preferences > Generate all .csproj files.您可以通过启用 Edit > Preferences > Generate all .csproj files 告诉 Unity(我的版本: v2019.2.20f1 )为您创建这些文件。
1. Delete both files.
2. Enable .csproj file generation.
3. Double click on a script in Unity.
This fixed my issue.这解决了我的问题。
Although the answer by Alex Myers is helps, its not 100% right.尽管 Alex Myers 的回答有帮助,但并非 100% 正确。 Unity Snippets does give you some snippets, and the illusion of typeahead, it's not actually intellisense. Unity Snippets 确实为您提供了一些片段,以及预先输入的错觉,它实际上并不是智能感知。
For true intellisense you need to:对于真正的智能感知,您需要:
More information can be found here: https://code.visualstudio.com/docs/languages/dotnet更多信息可以在这里找到: https : //code.visualstudio.com/docs/languages/dotnet
You can test you have dotnet installed by typing dotnet
into the terminal within VSCode.您可以通过在 VSCode 中的终端中键入dotnet
来测试您是否安装了dotnet
。
Note In the image below how I get a full method signature, reference counts, and the yellow hint globe.注意在下图中,我如何获得完整的方法签名、引用计数和黄色提示球。 These are only available when using dotnet + extension (and not available when using the snippets)这些仅在使用 dotnet + 扩展时可用(在使用代码段时不可用)
I would really like to clear things up a bit for everyone trying to get intellisense working with Visual Studio Code.我真的很想为每个尝试使用 Visual Studio Code 进行智能感知的人澄清一下。
First of all I am writing this for Unity 2019.4.14 as it is the newest version.首先,我是为 Unity 2019.4.14 编写的,因为它是最新版本。
These are the things you MUST do for this to work:这些是你必须做的事情:
The reference assemblies for .NETFramework,Version=v4.7.1 were not found.未找到 .NETFramework,Version=v4.7.1 的参考程序集。 To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application.要解决此问题,请为此框架版本安装开发人员包(SDK/目标包)或重新定位您的应用程序。
dotnet
in the VSCode terminal.通过在 VSCode 终端中输入dotnet
来检查您是否安装了 .NET。Now, what about Unity Code Snippets and Debugger for Unity extensions?现在,用于 Unity 扩展的 Unity 代码片段和调试器怎么样? Well these are useful helper extensions but they have nothing to do with Intellisense.好吧,这些是有用的辅助扩展,但它们与 Intellisense 无关。 The first is for quickly typping common Unity patterns and the second is for showing Unity Debug warnings and errors as you type instead of saving and going back to Unity and reading the console.第一个用于快速输入常见的 Unity 模式,第二个用于在您输入时显示 Unity Debug 警告和错误,而不是保存并返回 Unity 并阅读控制台。
Hope this was of any help.希望这有任何帮助。
Check out the guide for Unity Development with VS Code .查看使用 VS Code进行Unity 开发的指南。 They recommend a few extensions:他们推荐了一些扩展:
I believe the Unity Snippets extension is what you are looking for.我相信Unity Snippets扩展是您正在寻找的。
Note: my solution does not solve intellisense to function names, but this was the first question that come in fixing intellisense more generally in VSCode.注意:我的解决方案没有解决函数名称的智能感知,但这是在 VSCode 中更普遍地修复智能感知的第一个问题。
I needed to update the VSCode package in unity .我需要统一更新 VSCode 包。
In Unity, click Window, then Package Manager, then look for Visual Studio Code Editor.在 Unity 中,单击 Window,然后单击 Package Manager,然后查找 Visual Studio Code Editor。 Expand it by pressing triangle, and upgrade to the latest version (for me, it was 1.2.0
. I restarted VSCode and it worked.按三角形展开它,并升级到最新版本(对我来说,它是1.2.0
。我重新启动了 VSCode 并且它工作了。
v1.1.4 had a bug that caused this problem, and was not fixed for about 3 months. v1.1.4有一个bug导致这个问题,大约3个月没有修复。 It is still the default package installed with a new default project, so you have to change this package version to 1.2.0 in every new project, until they update it.它仍然是与新默认项目一起安装的默认包,因此您必须在每个新项目中将此包版本更改为 1.2.0,直到他们更新它。
Intellisense is a pure workflow of .Net Environment. Intellisense 是 .Net Environment 的纯工作流。 So, you need to have .Net 'Developer pack' (not Runtime) installed on your system as it installs all three necessary components below:因此,您需要在系统上安装 .Net 'Developer pack'(不是运行时),因为它安装了以下所有三个必要组件:
reference link: https://dotnet.microsoft.com/download/visual-studio-sdks参考链接: https : //dotnet.microsoft.com/download/visual-studio-sdks
It is directly installed to a system admin-accessible path, so no need setting it up.它直接安装到系统管理员可访问的路径,因此无需设置。 Now, you have to tell VS Code which .Net version to use (whichever you have installed).现在,您必须告诉 VS Code 要使用哪个 .Net 版本(无论您安装了哪个版本)。 Your Unity project will have these two files in the root directory:您的 Unity 项目将在根目录中包含以下两个文件:
In these both files search for line (probably 16):在这两个文件中搜索行(可能是 16):
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
Edit version that you had just installed (I had 4.8).编辑您刚刚安装的版本(我有 4.8)。 Then reopen VS Code.然后重新打开 VS Code。 Now everything should work fine.现在一切正常。
对我来说只是在 Unity 中, Edit/Preferences/External Script Editor
,并将其更改为My_Install_Location\\Microsoft VS Code\\Code.exe
(可能点击 Regenerate Project Files)
Sorry, I don't have good English, but I'll show you what worked for me.对不起,我的英语不好,但我会告诉你什么对我有用。
I opened the C # script in Visual Studio Code and looked for the Assembly-CSharp.csproj file, then, on line 16, I changed the following:我在 Visual Studio Code 中打开 C# 脚本并查找 Assembly-CSharp.csproj 文件,然后,在第 16 行,我更改了以下内容:
<TargetFrameworkVersion> v4.5 </TargetFrameworkVersion>
For:为了:
<TargetFrameworkVersion> v4.5.1 </TargetFrameworkVersion>
This solved the Intellisense issue.这解决了智能感知问题。
I found another solution since none of the other solutions were working for me and i was searching for hours.(07/08/2021):我找到了另一个解决方案,因为其他解决方案都不适合我,而且我搜索了几个小时。(07/08/2021):
I got the feeling i found the solution for a lot of people since i reinstalled windows recently and simply downloaded everything needed to start without other problems.我感觉我为很多人找到了解决方案,因为我最近重新安装了 Windows 并且只需下载启动所需的所有内容而没有其他问题。
I got the same error with .NET, .NET Core or .NET Framework, here are some screenshots of the errors:我在 .NET、.NET Core 或 .NET Framework 上遇到了同样的错误,以下是一些错误截图:
In the error output, it says to install the Developer Pack for this framework version.在错误输出中,它说要为此框架版本安装 Developer Pack。 You can find the version in the .csproj file:您可以在 .csproj 文件中找到版本:
By installing the .NET Framework of this version on the dotnet microsoft site: .NET Framework download list i fixed the error after reloading VSCode and got my Intellisense working for Unity.通过在 dotnet microsoft 站点上安装此版本的 .NET Framework: .NET Framework 下载列表,我在重新加载 VSCode 后修复了错误并使我的 Intellisense 为 Unity 工作。
TLDR: My fix was too install .NET Framework version 4.7.1 TLDR:我的修复是安装 .NET Framework 版本 4.7.1
Though the question is 2 years old, the problem pops up occasionally, just like happened to me.虽然这个问题是 2 年前的问题,但偶尔会弹出这个问题,就像发生在我身上一样。
I had the issue myself, so this one is possibly the first that should be checked.我自己也遇到了这个问题,所以这个问题可能是第一个应该检查的。
WHY?为什么?
First of all, I work with dotnet core, not the standard, so I don't have standard libraries installed on my computer.首先,我使用 dotnet core,而不是标准,所以我的计算机上没有安装标准库。 When I started trying Unity, and VS Code with it, this was the missing part I wasn't aware of.当我开始尝试使用 Unity 和 VS Code 时,这是我不知道的缺失部分。
When I hit the issue, I searched the net a while and see this question.当我遇到这个问题时,我在网上搜索了一段时间并看到了这个问题。 Took me another while to notice this framework sentence in "Enabling code completion" section of VS Code and Unity page.我又花了一段时间才注意到VS Code 和 Unity页面的“启用代码完成”部分中的这个框架语句。 So I tried and now I am happy I tried.所以我尝试了,现在我很高兴我尝试了。
Just don't forget you need to restart at least VS Code to get the intellisense working.只是不要忘记您至少需要重新启动 VS Code 才能使智能感知工作。
PS: Framework version may, and will most possibly, be changed depending on what year we are in, and which versions we use. PS:框架版本可能会,也很可能会根据我们所处的年份和我们使用的版本而改变。 So if "4.6" is not working then you probably need another version.因此,如果“4.6”不起作用,那么您可能需要另一个版本。
PS2: If it is Mac you are looking for, follow the same link above and find the same section I mentioned above to get a link for .NET SDK. PS2:如果您正在寻找 Mac,请按照上面的相同链接找到我上面提到的相同部分以获取 .NET SDK 的链接。
Follow these steps:按着这些次序:
Edit
.转到Edit
。Projects preferences
.转到Projects preferences
。External tools
.转到External tools
。then it should work.那么它应该工作。
对于在Mac上遇到相同问题的任何人,请尝试在您的.vscode/settings.json (或在用户设置而不是工作区设置中)设置此值
"omnisharp.useGlobalMono": "always"
If you still can't enable IntelliSense, make sure you have VS Code opened in the same directory as the .sln file (I had mine opened deeper in the Assets before).如果您仍然无法启用 IntelliSense,请确保您在 .sln 文件所在的目录中打开了 VS Code(我之前在 Assets 中打开过更深的目录)。
Source: https://code.visualstudio.com/docs/other/unity来源: https : //code.visualstudio.com/docs/other/unity
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.