在Unity中使用动态关键字/.NET 4.6功能 [英] Use the dynamic keyword/.NET 4.6 feature in Unity

查看:286
本文介绍了在Unity中使用动态关键字/.NET 4.6功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将GraphQL实施到Unity3D(2017.1.0f3个人版)中.我正在使用.NET 4.6(实验性),但是尽管如此,Unity不支持动态关键字.奇怪的是,由于.NET 4.0是.NET的一部分,因此.除Unity外.我一直在寻找一些解决方案来实现它的工作,但是没有找到对dynamic关键字的解决方案.错误是这样的:

I am trying to implement GraphQL into Unity3D (version 2017.1.0f3 Personal). I am using .NET 4.6 (Experimental), but despite this, Unity does not support dynamic keyword. Which is odd, since .NET 4.0 it is the part of .NET. Except in Unity. I was googling for some solution how to get it work, but no solutions to the dynamic keyword. The error is this:

Severity    Code    Description Project File    Line    Suppression State
Error   CS1980  Cannot define a class or member that utilizes 'dynamic' 
because the compiler required type 
'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you 
missing a reference?    skiing-prototype (1)    D:\skiing-prototype 
(1)\Assets\Scripts\GraphQL.cs   62  Active

那是使用GraphQL C#客户端的唯一警告.有没有人尝试过使其工作?我还没有找到更大的努力来启动它并运行它.

That is the only caveat of using GraphQL C# client. Has anyone tried it yet to get it work? I hadn't found any greater efforts to get it up and running yet.

我在这里使用此客户端: https://github.com/bkniffler/graphql-网络客户端

I am using this client here: https://github.com/bkniffler/graphql-net-client

这也是Visual Studio的错误,但是在Unity控制台中它也显示错误,将立即准确更新

Also this is an error from visual studio, but in Unity console it shows errors too, will update what exactly momentarily

Assets/Scripts/GraphQL.cs(80,16): error CS1980: Dynamic keyword requires 
`System.Runtime.CompilerServices.DynamicAttribute' to be defined. Are you 
missing System.Core.dll assembly reference?

这是统一编辑器错误,似乎与Visual Studio中的错误相同

this is the unity editor error, which seems to be the same that in visual studio

推荐答案

第一步是检查Unity是否从

The first step is to check if Unity recognizes these 2 basic C# 6 features from MS site.

1 .尝试使用索引初始化器"功能:

1.Try "Index Initializers" feature:

private Dictionary<int, string> webErrors = new Dictionary<int, string>
{
    [404] = "Page not Found",
    [302] = "Page moved, but left a forwarding address.",
    [500] = "The web server can't come out to play today."
};

2 .然后是字符串插值"功能:

2. then "String Interpolation" feature:

private string FirstName = "";
private string LastName = "";
public string FullName => $"{FirstName} {LastName}";

如果他们给您错误,则问题不是不是,而是dynamic关键字,而是Visual Studio无法识别Unity设置的 .NET 版本的问题.

If they give you error then the problem is not just the dynamic keyword but a problem that Visual Studio cannot recognize the .NET version being set by Unity.

在注释部分,您的Unity无法编译第一个示例.

From the comment section your Unity failed to compile the first example.

一步一步地进行操作以获得可能的解决方法. 跳过它们.

Go through the steps one by one for a possible fix. Do not skip of them.

1 .转到编辑->项目设置->播放器->其他设置->配置->脚本运行时版本->实验(等效于.Net 4.6).

1.Go to Edit --> Project Settings --> Player --> Other Settings --> Configuration --> Scripting Runtime Version --> Experimental (.Net 4.6 Equivalent).

2 .转到编辑->项目设置->播放器->其他设置->配置-> Api兼容级别-> .NET 4.6

2.Go to Edit --> Project Settings --> Player --> Other Settings --> Configuration --> Api Compatibility Level --> .NET 4.6

3 .重新启动Unity Editor和Visual Studio.您必须同时重新启动.

3.Restart Unity Editor and Visual Studio. You must restart both.

测试以上两个C#功能.如果它们起作用,那么dynamic关键字也应该如此.如果他们不这样做,则继续前进到#4.

Test both C# features above. If they work then the dynamic keyword should as-well. If they don't then move on to #4.

4 .更新Visual Studio.这个非常重要.将visual Studio更新到最新版本/补丁.

4.Update Visual Studio. This is very important. Update the visual Studio to the latest version/patch.

5 .如果仍然无法同时获得上述两个C#6功能,请重新安装Visual Studio和Unity,然后执行步骤#1 #2 ,因为缺少某些文件.

5.If you can't still get both C#6 features above to compile then Re-install both Visual Studio and Unity then perform step #1 and #2 again as some files are missing.

6 .最后,如果您同时使用了C#6的所有功能,但dynamic关键字仍然无法使用,请从 Unity 2017.1 更新为

6.Finally, if you get both C#6 features working but the dynamic keyword is still not working then update from Unity 2017.1 to Unity 2017.2. This version fixed many .NET issues.

请注意,我正在将 Unity 2017.2 dynamic关键字一起使用没有任何问题.另外,GraphQL正常工作.

Note that I am using Unity 2017.2 with the dynamic keyword without any issue. Also, GraphQL is working fine.

这篇关于在Unity中使用动态关键字/.NET 4.6功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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