在 Unity 4.1 项目中,我希望将所有 C# 脚本都放在 DLL 中。 Unity 创建了一个 Visual Studio 项目,我能够正确编译代码。 编译生成 DLL,但 Unity 无法识别所有类,只能识别继承 MonoBehaviour 的类。所有类(class)都是公开的,并且 Unity 是专业版。 如何让 Unity“看到”所有类?
我尝试使用 Mono 2.8 进行编译,它构建了 DLL。所有的类似乎都在那里,但没有任何作用,我收到这些错误:
ApplicationException: Unable to find a suitable compiler
UnityEditor.Scripting.ScriptCompilers.CreateCompilerInstance (MonoIsland island, Boolean buildingForEditor, BuildTarget targetPlatform) (at
C:/BuildAgent/work/7535de4ca26c26ac/Editor/Mono/Scripting/ScriptCompilers.cs:99)
和
Failed to create compiler instance
最佳答案
确保您针对 .NET Framework 3.5 或更低版本编译 DLL。
To change the targeted .NET Framework version in an existing project:
- 打开您要更改的项目。
- 在解决方案资源管理器工具栏中,选择属性按钮。
- 您还可以在解决方案资源管理器中选择项目节点,打开上下文菜单(右键单击该节点),然后选择属性。
- 您应该会在应用程序选项卡上看到设置。如果不这样做,请选择它。
- 在目标框架下拉列表中,选择所需的.NET Framework版本。然后点击确定按钮。
关于c# - DLL 中的 Unity C# 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18094118/