在Visual Studio中编辑的Unity脚本不提供自动完成功能 [英] Unity Scripts edited in Visual studio don't provide autocomplete

查看:375
本文介绍了在Visual Studio中编辑的Unity脚本不提供自动完成功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我要编辑C#Unity脚本时,它们会在Visual Studio中打开。应该为所有与Unity相关的代码提供自动完成功能,但是它不起作用。


在这里您可以看到缺少的功能:



如图所示,


其他文件该消息可能由于多种原因发生:


  1. 当您从另一个文件夹中打开Unity C#文件而不是从Unity Editor中打开它时,可能会发生该消息。 / p>


  2. 这也可能发生,因为在Visual Studio仍处于打开状态时Unity崩溃了,因此损坏了某些文件。



  3. 之所以会发生这种情况,是因为先关闭Unity再重新打开,但不再连接到Visual Studio。打开Visual Studio时,会显示 其他文件。并且没有自动完成功能。



  4. 如果未安装 Visual Studio Tools for unity ,则会发生这种情况。

    p>

  5. 当您从Unity创建脚本时,请在Unity完成处理之前或圆形图标动画素材完成动画之前快速打开它。






在大多数情况下,重新启动Unity和Visual Studio应该可以解决此问题。


我无法确定是哪个引起了问题,但我将介绍解决此问题的最有可能的解决方案。


修复第1部分







修复第2部分


如果新创建的C#文件显示为其他,请按照以下说明进行操作:


  1. 从Visual Studio中,转到工具选项... Unity工具其他 。在显示连接性图标下,将其设置为 true ,然后重新启动Visual Studio。




  2. 重新启动时,Visual Studio现在应该可以使用连接图标。单击它,然后选择要连接的Unity实例。现在,红色的 x图标应变为棕色的选中标记图标。现在,当您在Unity中创建一个新的C#文件时,它应该打开而无需说 Miscellaneous







修复第3部分


仍然不固定吗?


重新导入项目,然后打开C#项目。


  1. 关闭Visual Studio。



  2. 从Unity中,通过转到 Assets Reimport重新导入项目。全部




  3. 现在,通过转到资产打开C#项目在Visual Studio中打开项目。这将重新加载项目并解决可能的解决方案文件问题。







修复第4部分


仍然不固定吗?


分别修复每个C#文件。


  1. 单击显示所有文件图标。




  2. 选择不包含以下内容的脚本自动完成,然后右键单击并选择包含在项目中







修复第5部分


不修复


贷方到 chrisvarnz 似乎适用于多个人。


  1. 关闭Visual Studio



  2. 转到项目目录并删除所有生成的Visual Studio文件。


    这些是要删除的文件扩展名:



    • .csproj

    • .user

    • .sln


    示例:


    让我们假设您的项目名称为 Target_Shoot ,这些就是要删除的文件的样子:



    • Target_Shoot.csproj

    • Target_Shoot.Editor.csproj

    • Target_Shoot.Editor.csproj.user

    • Target_Shoot.Player.csproj

    • Target_Shoot.Player.csproj.user

    • Target_Shoot.sln


    请勿删除其他任何内容。



  3. 再次从Unity 双击脚本,该脚本将生成新的Visual Studio文件,然后打开Visual Studio。这可能会解决您的问题。






修复第6部分


如果不起作用,请检查是否没有错误:


GetReferenceNearestTargetFrameworkTask找不到任务




  1. 安装 Nuget PackageManager ://marketplace.visualstudio.com/items?itemName = NuGetTeam.NuGetPackageManager rel = noreferrer>此处



  2. 重新启动Visual Visual。



请参见答案以获取更多信息。


When I want to edit C# Unity scripts, they open in Visual Studio. It is supposed to provide auto complete for all Unity related code, but it doesn't work.

Here you can see the missing functionality:

As seen, the transform object does not open the autocomplete menu.

Unity version: 5.5.2f1
Visual studio 2015
Visual Studio Tools for Unity is installed

解决方案

There is no auto-completion because the script says "Miscellaneous Files" instead of the of the name of the Project. Take a look at the image below that came from the video in your question:

The "Miscellaneous Files" message can happen for many reasons:

  1. It can happen when you open your Unity C# file from another folder instead of opening it from Unity Editor.

  2. This can also happen because Unity crashed while Visual Studio is still open therefore corrupting some files.

  3. It can happen because Unity was closed then re-opened but is no longer connected to Visual Studio. When Visual Studio is opened you get "Miscellaneous Files" and no auto-completion.

  4. This can happen when Visual Studio Tools for unity is not installed.

  5. When you create a script from Unity then quickly open it before Unity finish processing it or before the round icon animation stuff finish animating.


Most of the times, restarting Unity and Visual Studio should fix this.

I can't tell which one is causing the problem but I will cover the most likely solution to fix this.

Fix Part 1:

  1. Download and Install Visual Studio Tools for unity from this link. Do this while Unity and Visual Studio are both closed.

  2. From Unity Editor, go to EditPreferences... → External Tools. On the External Script Editor drop down menu, change that to Visual Studio 2015.


Fix Part 2:

If newly created C# files are coming up as Miscellaneous then follow the instruction below:

  1. From Visual Studio, go to ToolsOptions...Tools for UnityMiscellaneous. Under Show connectivity icon, set it to true then restart Visual Studio.

  2. When you re-start, connection icon should now be available in Visual Studio. Click it then choose the Unity instance to connect to. The red 'x' icon should now turn into a brown checkmark icon. Now, when you create a new C# file in Unity, it should open without saying Miscellaneous.


Fix Part 3:

Still not fixed?

Re-import project then open C# Project.

  1. Close Visual Studio.

  2. From Unity, re-import project by going to AssetsReimport All.

  3. Now, open the project in Visual Studio by going to AssetsOpen C# Project. This will reload the project and fix possible solution file problems.


Fix Part 4:

Still not fixed?

Fix each C# file individually.

  1. Click on Show All Files icon.

  2. Select the script that doesn't do auto-complete then right-click and select Include In Project.


Fix Part 5:

Not fixed yet?

Credit goes to chrisvarnz for this particular solution which seems to have worked for multiple people.

  1. Close Visual Studio

  2. Go your project directory and delete all the generated Visual Studio files.

    These are the files extensions to delete:

    • .csproj
    • .user
    • .sln

    Example:

    Let's say that the name of your Project is called Target_Shoot, these are what the files to delete should look like:

    • Target_Shoot.csproj
    • Target_Shoot.Editor.csproj
    • Target_Shoot.Editor.csproj.user
    • Target_Shoot.Player.csproj
    • Target_Shoot.Player.csproj.user
    • Target_Shoot.sln

    Do not delete anything else.

  3. Double click on the script again from Unity which should generate new Visual Studio file then open Visual Studio. This may solve your problem.


Fix Part 6:

If not working, check if you are having this error:

The "GetReferenceNearestTargetFrameworkTask" task was not found

  1. Install Nuget PackageManager from here.

  2. Restart Visual Visual.

See this answer for more information.

这篇关于在Visual Studio中编辑的Unity脚本不提供自动完成功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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