Unity 支持许多 .NET 配置文件。每个配置文件为 C# 代码提供不同的 API 表面来与 .NET 类库交互。可在 Player 设置(选择 Edit > Project Settings__,然后选择 Player__ 类别)中更改 .NET 配置文件,为此需要使用 Other Settings 面板的 Api Compatibility Level 选项。
旧版脚本运行时支持两种不同的配置文件:.NET 2.0 Subset 和 .NET 2.0。这两者都与 Microsoft 的 .NET 2.0 配置文件密切相关。.NET 2.0 Subset 配置文件小于 .NET 4.x 配置文件,可用于访问大多数 Unity 项目使用的类库 API。此配置文件是大小受限平台(比如移动平台)的理想选择,并提供了一组可移植的 API 来实现多平台支持。默认情况下,大多数 Unity 项目应使用 .NET Standard 2.0 配置文件。
稳定脚本运行时支持两种不同的配置文件:.NET Standard 2.0 和 .NET 4.x。 .NET Standard 2.0 配置文件的名称可能有点误导,因为该配置文件与来自旧版脚本运行时的 .NET 2.0 和 .NET 2.0 Subset 配置文件无关。相反,Unity 支持的 .NET Standard 2.0 配置文件对应于 .NET Foundation 发布的同名配置文件。Unity 中的 .NET 4.x 配置文件对应于来自 .NET Framework 的 .NET 4 系列(.NET 4.5、.NET 4.6、.NET 4.7 等等)配置文件。
仅当需要确保与外部库的兼容性时,或者需要的功能在 .NET Standard 2.0 中不可用时,才应使用 .NET 4.x 配置文件。
Unity 致力于在所有平台上支持 .NET Standard 2.0 配置文件中的绝大多数 API。虽然并非所有平台都完全支持 .NET Standard,但是旨在实现跨平台兼容性的库应指向 .NET Standard 2.0 配置文件。.NET 4.x 配置文件包含的 API 表面要大得多,包括可能在很少平台上运行甚至无法在任何平台上运行的部分。
在 Unity 外部编译的托管代码插件可使用 Unity 中的 .NET Standard 2.0 配置文件或 .NET 4.x 配置文件。下表描述了 Unity 支持的配置:
API Compatibility Level: | ||
---|---|---|
.NET Standard 2.0 | .NET 4.x | |
编译的目标托管插件: | ||
.NET Standard | 受支持 | 受支持 |
.NET Framework | 受限 | 受支持 |
.NET Core | 不受支持 | 不受支持 |
注意:
从 2018.2 版开始,Unity 在除 WebGL 之外的所有平台上提供完整的 TLS 1.2 支持。这是通过 UnityWebRequest API 和所有 .NET 4.x API 实现的。
证书验证通过特定于平台的证书存储区(如果可用)自动完成。如果无法访问证书存储区,Unity 将使用嵌入式根证书存储区。
.NET 3.5 及更低版本的 TLS 支持因平台而异,无法保证支持哪些功能。
2018–03–15 页面已修订
在 2018.1 版中添加了 .NET 配置文件支持 NewIn20181
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.