要查看这些设置,请转到 Unity Editor 的 Project 窗口,选择插件文件,然后在 Inspector 窗口中导航到 Platform settings > __Universal Windows Platform__(Windows 图标)。
属性: | 功能: |
---|---|
SDK | 使用下拉选单使插件与 Any SDK 或特定 SDK 兼容。 |
CPU | 使用下拉选单使插件与 Any CPU 兼容,或将插件限制为 32-bit、64-bit 或 ARM 播放器。 |
Don’t process (仅适用于托管程序集) |
勾选此复选框可禁用此程序集的修补。当程序集包含 Unity 可序列化的类时,程序集需要修补。在这些情况下,Unity 会在程序集内注入额外的 IL 代码。如果您知道程序集没有这些类,那么禁用修补是安全的。 注意:Unity 会将序列化代码注入到程序集内,因此如果插件中有一个派生自 MonoBehaviour 的类,而 Unity 不对其进行修补,则可能会在运行时出现序列化错误。 |
Placeholder (仅适用于托管程序集) |
使用通用 Windows 平台的情况下,可根据 .NET Core 编译插件,但由于 Unity Editor 在 Mono 上运行,因此无法识别这些程序集。导致的结果是 C# 文件无法引用它们。为解决此问题,需提供根据 .NET 4.x 进行编译并具有相同 API 的程序集,它将充当真实插件的占位插件(请参阅下一部分:_占位插件_)。 |
请参阅有关 Plugin Inspector 的文档以了解更多信息。
如果使用 Windows 运行时 API,则无法在 Unity Editor 中使用特定于通用 Windows 平台的插件。本部分将介绍如何在 Unity Editor 中处理此问题。
如果只打算对通用 Windows 平台使用插件而不在 Unity Editor 中使用插件,则不需要创建占位插件,但需要使用以下语句对使用插件 API 的代码进行包装:
# if !UNITY_EDITOR
// 插件代码
# endif
如果打算将插件同时用于通用 Windows 平台和 Unity Editor,则需要占位插件。创建两个插件:
这两个插件必须共享相同的名称并具有相同的程序集版本。请注意,Unity Editor 的占位插件不能引用 UnityEditor.dll。如果进行此引用,Unity 会产生错误。
以下步骤描述了如何在 Editor 中为每个插件分配平台。
在 Unity Editor 的 Project 窗口中,选择与 Editor 兼容的占位插件。在 Inspector 窗口中,选择 Select platforms for plugin__,并选择 Editor__ 作为唯一兼容的平台。
在 Unity Editor 的 Project 窗口中,选择与通用 Windows 平台兼容的占位插件。在 Inspector 窗口中,选择 Select platforms for plugin__,并选择 Universal Windows Platform__ 作为唯一兼容的平台。
在与通用 Windows 平台兼容的插件的 Inspector 窗口中,将 Placeholder 字段设置为与 Editor 兼容的占位插件。
这意味着在进行以通用 Windows 平台为目标的构建时,Unity 在编译脚本时使用与 Editor 兼容的占位插件,而将与通用 Windows 平台兼容的插件复制到最终文件夹。这种机制实现了两个目的:Unity Editor 成功编译脚本,但构建的游戏本身仍然使用通用 Windows 平台特有插件中的 API。
• 2018–08–03 页面已修订并只进行了有限的编辑审查
在 2018.3 版中已弃用 .NET 3.5 脚本运行时
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.