VS Code IntelliSense 不适用于 Unity3d [英] VS Code IntelliSense not working for Unity3d

查看:30
本文介绍了VS Code IntelliSense 不适用于 Unity3d的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:IntelliSense 不适用于 Unity 特定的方法和函数(即,UpdateFixedUpdateAwake 等).

Problem: IntelliSense is not working for Unity specific methods and functions (i.e., Update, FixedUpdate, Awake, etc.).

然而,它确实适用于非 Unity 特定的方法(即,IEnumeratorvoidpublicfloatcode>、int 等)和 Unity 特定变量(即 Gameobjecttransformcamera、等)和 Unity 特定的命名空间(即 UnityEngineUnityEditorUnity 等).

It does work, however, for non Unity specific methods (i.e., IEnumerator, void, public, float, int, etc.) and for Unity specific variables (i.e., Gameobject, transform, camera, etc.) and Unity specific namespaces (i.e., UnityEngine, UnityEditor, Unity, etc.).

我正在使用:Visual Studio Code 1.41、Unity 3d 2018.4.15f1(我在使用 2019.2.x 时遇到了同样的问题).

I am using: Visual Studio Code 1.41, Unity 3d 2018.4.15f1 (I have the same problem when using 2019.2.x).

我尝试了以下解决方案都没有结果:

I have tried the following solutions to no results:

  1. 使用不同版本的 .NET
  2. 已删除项目中的 vscode 文件.
  3. 卸载并重新安装了 Unity 和 Visual Studio.
  4. 已将 v4.7.1 更改为 (当前安装的版本) 但统一自动默认返回到 v4.7.1

可能的问题:

  1. 项目创建的sln文件读取

  1. The sln file the project creates reads

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{B2B58FB2-4462-6B0C-A872-40DD957E5FE0}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Release|Any CPU = Release|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {B2B58FB2-4462-6B0C-A872-40DD957E5FE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {B2B58FB2-4462-6B0C-A872-40DD957E5FE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {B2B58FB2-4462-6B0C-A872-40DD957E5FE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {B2B58FB2-4462-6B0C-A872-40DD957E5FE0}.Release|Any CPU.Build.0 = Release|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(MonoDevelopProperties) = preSolution
        StartupItem = Assembly-CSharp.csproj
    EndGlobalSection
EndGlobal

出于某种原因,sln 文件似乎用于 Visual Studio 2010.我不知道这是故意的还是这是问题所在.

For some reason, the sln file seems to be used for Visual Studio 2010. I do not know if this is intentional or if this is the problem.

当尝试解决方案 4 时,如上所述,Unity(或我所知道的 VS Code)会自动将 .NET 版本从我手动输入的任何内容更改为 4.7.1.我已经安装了 4.7.1,所以这可能不是问题.

When attempting solution 4, as stated above, Unity (or VS Code for all I know) automatically changes .NET version from whatever I manually typed to 4.7.1. I have 4.7.1 already installed so this may not be the problem.

额外信息:

这是 omnisharp 日志:

Here is the omnisharp log:

Starting OmniSharp server at 2020. 1. 20. 오후 9:08:43
    Target: c:\Users\stpau\New Unity Project\New Unity Project.sln

OmniSharp server started.
    Path: C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\OmniSharp.exe
    PID: 2232

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Windows 6.2.9200.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 16.3 - "C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\.msbuild\Current\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to 'C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\.msbuild\Current\Bin\MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 16.3 - "C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\.msbuild\Current\Bin"
            CscToolExe = csc.exe
            CscToolPath = C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\.msbuild\Current\Bin\Roslyn
            MSBuildExtensionsPath = C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\.msbuild
            MSBuildToolsPath = C:\Users\stpau\.vscode\extensions\ms-vscode.csharp-1.21.9\.omnisharp\1.34.9\.msbuild\Current\Bin
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in 'c:\Users\stpau\New Unity Project'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in 'c:\Users\stpau\New Unity Project\New Unity Project.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for 'c:\Users\stpau\New Unity Project\Assembly-CSharp.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in 'c:\Users\stpau\New Unity Project'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: c:\Users\stpau\New Unity Project\Assembly-CSharp.csproj
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.EditorConfigWorkspaceOptionsProvider, Order: 200
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location 'c:\Users\stpau\New Unity Project' on host 8980.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file 'c:\Users\stpau\New Unity Project\Assembly-CSharp.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project 'c:\Users\stpau\New Unity Project\Assembly-CSharp.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Assembly-CSharp

我该如何解决这个问题?我也在 reddit 和 Unity 论坛上都问过这个问题,但都没有成功.

How can I solve this problem? I also asked this question on both reddit and the Unity forums with no success.

推荐答案

这不是您问题的解决方案,但我认为它完全没有问题.不幸的是,至于现在 IntelliSense for VS Code 不应该适用于 Unity 特定的方法和功能,我相信它.

It's not a solution for your problem, but I think that there is no problem with it at all. Unfortunately, as for now IntelliSense for VS Code isn't supposed to work for Unity specific methods and functions, I believe in it.

作为一种解决方法,您可以使用 Unity 代码片段扩展,它将为 IntelliSense 带来一些方法.对我来说唯一的问题是它使用了 K&R 格式,所以我制作了 我自己的片段文件 为此.

As a kind of workaround you can use Unity code snippets extension, it'll bring some methodes to IntelliSense. The only problem for me is that it used K&R formatting, so I made my own snippet file for that.

也许您也注意到了,但是如果您的脚本中已经定义了一些 Unity 方法,IntelliSense 会检测到它们.

And also maybe you noticed, but if you already have some defined Unity methodes in your script, IntelliSense will detect them.

这篇关于VS Code IntelliSense 不适用于 Unity3d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆