简体   繁体   English

VSCode 与 Unity 2017.1 的集成:IntelliSense 无法建议任何类型的数据

[英]VSCode integration with Unity 2017.1: IntelliSense not able to suggest any type of data

I just heard that Unity will be dropping support on MonoDevelop on its 2018.1 version and went to search for an alternative.我刚刚听说 Unity 将在其 2018.1 版本上放弃对 MonoDevelop 的支持,并开始寻找替代方案。 VSCode was the best option so I downloaded it and installed all suggested Unity extensions. VSCode 是最好的选择,所以我下载了它并安装了所有建议的 Unity 扩展。 ( https://code.visualstudio.com/docs/other/unity ) ( https://code.visualstudio.com/docs/other/unity )

I also changed my External Script Editor to Code.我还将我的外部脚本编辑器更改为代码。 I've created a new Unity project for testing.我创建了一个新的 Unity 项目进行测试。 The code snippets are working great for unity methods such as Start () and Update () but whenever I try to declare a variable like:代码片段非常适用于诸如 Start () 和 Update () 之类的统一方法,但是每当我尝试声明一个变量时,例如:

private Rigidbody rb;

The rigid body is not suggested.不建议刚体。 I decided to test with other data types, the most essentials like int, float, etc. And none of them are suggested either.我决定用其他数据类型进行测试,最重要的数据类型,如 int、float 等。也不建议使用它们。 What could be happening?会发生什么? Why is IntelliSense not working properly?为什么 IntelliSense 无法正常工作? I've already downloaded the C# extension as suggested at https://code.visualstudio.com/docs/editor/intellisense我已经按照https://code.visualstudio.com/docs/editor/intellisense 的建议下载了 C# 扩展

I'm on a Mac using MacOS Sierra with the most current version of VSCode and Unity 2017.1.我在 Mac 上使用 MacOS Sierra 和最新版本的 VSCode 和 Unity 2017.1。

[EDIT] The problem was solved after I reinstalled, MonoDevelop, VisualStudio for Mac, VSCode and all it's extensions and used mad.meesh suggestion of searching the .sln on project opening. [编辑] 在我重新安装 MonoDevelop、VisualStudio for Mac、VSCode 及其所有扩展并使用 mad.meesh 建议在项目打开时搜索 .sln 后,问题解决了。 I still don't understand why, but it's working.我仍然不明白为什么,但它正在工作。

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.csprojproject-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.启用 .csproj 文件生成。
  3. Double click on a script in Unity.在 Unity 中双击脚本。

This fixed my issue.这解决了我的问题。

I followed the tutorial from Microsoft for VS Code with Unity and it seemed to finally do the trick... https://code.visualstudio.com/docs/other/unity我跟着微软的 VS Code with Unity 教程,它似乎终于成功了...... https://code.visualstudio.com/docs/other/unity

Steps I took:我采取的步骤:

  1. Installed https://dotnet.microsoft.com/download已安装https://dotnet.microsoft.com/download
  2. Installed https://www.mono-project.com/download/stable/安装https://www.mono-project.com/download/stable/
  3. Installed C# extension in VS Code.在 VS Code 中安装了 C# 扩展。
  4. Unity > Preferences (cmd + , on Mac) > External Tools (left toolbar) > External Script Editor > Visual Studio Code. Unity > 首选项(cmd + ,在 Mac 上)> 外部工具(左侧工具栏)> 外部脚本编辑器 > Visual Studio 代码。
  5. Then this is the trick I found to work after doing all of this... I open up VS Code prior to starting my Unity Project and manually go into the Unity Project folder and open up everything in VS Code FIRST.然后这是我在完成所有这些之后发现的工作技巧......我在启动我的 Unity 项目之前打开 VS Code,然后手动进入 Unity 项目文件夹并首先打开 VS Code 中的所有内容。 Then, with that project already open and working in VS Code with Intellisense, I double click the script in Unity and it will open it up in the already opened VS Code editor and have Intellisense already working!然后,该项目已经打开并使用 Intellisense 在 VS Code 中工作,我在 Unity 中双击脚本,它将在已经打开的 VS Code 编辑器中打开它,并且 Intellisense 已经在工作! Do my normal workflow for the day and close everything down... then when I start up the next time, just be sure to open the project in VS Code FIRST and then VS Code will recognize it's a C# project and initiate Intellisense and all that jazz.执行我当天的正常工作流程并关闭所有内容...然后当我下次启动时,请确保首先在 VS Code 中打开该项目,然后 VS Code 将识别出它是一个 C# 项目并启动 Intellisense 和所有这些爵士乐。

Hope this helps!希望这有帮助!

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

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