在 Unity 中,通常使用脚本来创建功能,但也可使用__插件__形式包含 Unity 外部创建的代码。可在 Unity 中使用两种插件:_托管插件_和_原生插件_。
_托管插件_是使用 Visual Studio 等工具创建的托管 .NET 程序集。此类插件仅包含 .NET 代码,因此无法访问 .NET 库不支持的任何功能。但是,Unity 使用的标准 .NET 工具可以访问托管代码来编译脚本。因此,托管插件代码和 Unity 脚本代码之间几乎没有用法差异,唯一的区别是插件在 Unity 外部编译而成,因此源代码可能不可用。
_原生插件_是特定于平台的本机代码库。此类插件可访问操作系统调用和第三方代码库等功能;Unity 无法通过其他方式使用这些功能。但是,Unity 的工具无法以托管库的方式访问这些库。例如,如果忘记将托管插件文件添加到项目中,您将收到标准编译器错误消息。如果也忘记将原生插件添加到项目中,则只会在尝试运行项目时看到错误报告。
以下页面介绍了如何创建插件以及在 Unity 项目中使用插件:
2018–03–19 页面已修订
从 2018.1 开始,MonoDevelop 由 Visual Studio 取代
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.