简体   繁体   English

Visual Studio 代码自动完成

[英]Visual studio code auto-complete

I have just downloaded unity and saw that now it supports Visual studio code, I downloaded it and made it the default editor.我刚刚下载了 unity,看到它现在支持 Visual Studio 代码,我下载了它并将其设为默认编辑器。

After trying to edit a script, it prompted me to download c# extension and I did, but there is no auto-complete for unity functions.在尝试编辑脚本后,它提示我下载 c# 扩展并且我下载了,但是没有针对统一功能的自动完成功能。 How can I get that?我怎样才能得到那个? I'm on Mac.我在 Mac 上。 Any help is appreciated.任何帮助表示赞赏。

Maybe too late, but for future comers ...也许为时已晚,但对于未来的人......

There is an extension now for visual studio code called MonoBehaviour Snippets by Rachod Petchpho .现在有一个由Rachod Petchpho 开发的名为MonoBehaviour Snippets的 Visual Studio 代码扩展。

Press Ctrl+shift+x in the IDE to open extensions panel then search for MonoBehaviour Snippets , install and reload the IDE, now you will find all the autocomplete for the function names and objects just like MonoDevelop.在 IDE 中按Ctrl+shift+x打开扩展面板,然后搜索MonoBehaviour Snippets ,安装并重新加载 IDE,现在您将找到函数名称和对象的所有自动完成功能,就像 MonoDevelop 一样。

I had the same situation and I bang my head to the wall for days.我有同样的情况,我的头撞在墙上好几天了。 There was no solution on the net as there are few people using Unity on linux with Visual Studio Code.网络上没有解决方案,因为很少有人在 linux 上使用 Visual Studio Code 使用 Unity。 I finally removed mono and went to their site and downloaded the Visual Studio build (even though we use Visual Studio Code).我最终删除了 mono 并访问了他们的站点并下载了 Visual Studio 版本(即使我们使用 Visual Studio Code)。 Then volaaa.然后哇哦。 Auto complete and suggestions related to Unity functions were there.自动完成和与 Unity 功能相关的建议在那里。 Of course after installing the necessary extensions.当然在安装必要的扩展之后。

https://www.mono-project.com/download/vs/ https://www.mono-project.com/download/vs/

I had the same problem with Unity + VS Code combo.我在 Unity + VS Code 组合中遇到了同样的问题。

I have found an extension called Unity CodeSnippets我找到了一个名为Unity CodeSnippets的扩展

I highly recommend to download it.我强烈建议下载它。 This is much better than any of other snippets collection for VSCode.这比 VSCode 的任何其他片段集合要好得多。

Intellisense (Autocompletion) is a pure workflow of .Net Environment. Intellisense(自动完成)是 .Net 环境的一个纯工作流。 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'(不是运行时),因为它安装了以下所有三个必要组件:

  1. .Net framework .Net框架
  2. .Net Target pack .Net 目标包
  3. .net SDK .net SDK

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 项目将在根目录中包含以下两个文件:

  1. Assembly-CSharp.cs汇编-CSharp.cs
  2. Assembly-CSharp-Editor.cs Assembly-CSharp-Editor.cs

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.现在一切正常。

You can use the unity integration plugin:您可以使用统一集成插件:

https://code.visualstudio.com/Docs/runtimes/unity https://code.visualstudio.com/Docs/runtimes/unity

Follow the instructions to get set up.按照说明进行设置。 It seems a lot of things to do but I think that's the best one.似乎有很多事情要做,但我认为这是最好的。

If you still hit the issue even by using that plugin then follow this issue at their github page.如果即使使用该插件仍然遇到问题,请在他们的 github 页面上关注此问题

https://forum.unity.com/threads/cant-get-vscode-to-work-properly-with-unity.538224/ https://forum.unity.com/threads/cant-get-vscode-to-work-properly-with-unity.538224/

there are people that found a workaround.有些人找到了解决方法。 unityoracle user said: "This issue is that Unity Editor expects the file used to launch VSCode to have a specific name. " and: "Specifically, creating a symlink named "code" that opens VSCode fixed this issue" unityoracle 用户说:“这个问题是 Unity 编辑器希望用于启动 VSCode 的文件具有特定名称。”和:“具体来说,创建一个名为“code”的符号链接来打开 VSCode 解决了这个问题”

I have just downloaded unity and saw that now it supports Visual studio code, I downloaded it and made it the default editor.我刚刚下载了unity,看到它现在支持Visual Studio代码,我下载了它并将其设置为默认编辑器。

After trying to edit a script, it prompted me to download c# extension and I did, but there is no auto-complete for unity functions.尝试编辑脚本后,它提示我下载c#扩展名,但确实这样做了,但是统一功能没有自动完成功能。 How can I get that?我该怎么办? I'm on Mac.我在Mac上。 Any help is appreciated.任何帮助表示赞赏。

I have just downloaded unity and saw that now it supports Visual studio code, I downloaded it and made it the default editor.我刚刚下载了 unity,看到它现在支持 Visual Studio 代码,我下载了它并将其设为默认编辑器。

After trying to edit a script, it prompted me to download c# extension and I did, but there is no auto-complete for unity functions.尝试编辑脚本后,它提示我下载 c# 扩展并且我下载了,但是没有针对统一功能的自动完成功能。 How can I get that?我怎么能得到那个? I'm on Mac.我在 Mac 上。 Any help is appreciated.任何帮助表示赞赏。

对我来说,它的工作原理是下载 .NET Framework 4.7.1 Developer Pack 这里是链接

Follow the steps from https://code.visualstudio.com/docs/other/unity按照https://code.visualstudio.com/docs/other/unity 中的步骤操作

Then in unity editor, set VS Code as the default Script editor:然后在统一编辑器中,将 VS Code 设置为默认脚本编辑器:

Edit -> Preferences -> External Tools -> External Script Editor编辑 -> 首选项 -> 外部工具 -> 外部脚本编辑器

Right below, set Embedded packages and Local packages to true在右下方,将嵌入式包和本地包设置为 true

i used these methods and it worked我使用了这些方法并且有效

  1. Change in External Tools: Edit -> Preferences :choose " Visual Studio Code"更改外部工具:编辑 -> 首选项:选择“Visual Studio Code”
  2. Open file : Assembly-CSharp-Editor in your project folder and Download the Framework Version that is the same as the version in this file EX: v4.7.1在您的项目文件夹中打开文件:Assembly-CSharp-Editor 并下载与此文件中版本相同的框架版本 EX:v4.7.1
  3. Open VScode tool - Settings - >code lens and tick.打开VScode工具-设置->代码镜头并打勾。

source from here: https://www.ehforex.com/2022/01/visual-studio-code-auto-complete-with.html来源: https : //www.ehforex.com/2022/01/visual-studio-code-auto-complete-with.html

我安装了旧版本的c# vscode extensionversion 1.16.21 ,它正在工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM