手动将 .NET 4.5 脚本添加到 Unity:潜在问题?
Manually adding .NET 4.5 scripts to Unity: Potential issues?
我最近不得不在 Unity 中进行一些工作,这些工作需要 classes 仅在更高版本的 .NET 中可用,Unity 尚不支持。我设法下载了我丢失的极少数脚本并将其添加到我的项目中,它似乎工作正常。我想知道的是,为什么我不能将整个 .NET 源代码放入我的项目中?这样做的含义是什么?
编辑:到目前为止我添加的脚本是 WeakReference 的通用版本以及它需要的任何依赖项(System.Diagnostics.Contract 中的合同)。
编辑 编辑:我基本上想知道为什么我不能简单地将在较新版本的 .NET 中找到的 C# class 文件添加到使用较旧版本的 .NET 的 Unity。是软件问题吗?是硬件问题吗?是不是因为Unity的系统组件是对应.NET早期版本构建的?
简答:
安装 Visual Studio Tools for Unity(它应该会在您安装 Unity 时自动安装),安装时您可以在 "target framework" 下拉菜单中告诉您的 .csproj 以特定版本的 . NET Unity 使用,您将只能编译具有 Unity 支持的方法和类型的 dll。
长答案:
这是因为Unity没有使用您电脑上安装的.NET版本。 Unity 使用 Mono,而且是一个非常旧的版本。这允许统一在多个平台和操作系统上 运行。因此,您只能使用受支持的 Mono 版本中的功能。
但是,如果您查看 at their roadmap alpha 版本,您会看到
Scripting: C# Compiler Upgrade
Upgrade Mono C# compiler against our
current .Net 2.0 and 2.0 Subset profiles. Note that this is an upgrade
of the C# compiler only, not the full Mono runtime
然后在 "research" 阶段
Scripting: .NET Profile Upgrade
Upgrade .Net profile to 4.6 enabling access to the latest .Net functionality and APIs.
更新:
您可以从 the stickied post here 获得使用 4.6 配置文件的实验版本。
的注释
- For this release, the Editor and the following players should be working:
- Windows, OSX, Linux standalone
- iOS with IL2CPP
- Android with IL2CPP and Mono
- Other platforms are known to not work yet, and are probably not worth installing.
- Managed debugging via Visual Studio Tools for Unity or MonoDevelop is not supported in this release. If you want to use VSTU for
editing please use the special build linked at the bottom of this
post.
- The compiler targets the C# 6 language.
- The compiler by default will still target the .Net 4.6 framework profile.
- Known issues
- The Android/Mono build does not work properly with managed code stripping. Please disable managed code stripping for now.
- For some projects, the Windows standalone player can crash on Windows 8.1. This is intermittent, so we would love to see any crash
reports or data about this
之前回答过类似的问题。就像我在你的其他问题中描述的那样,你可以 "inject" 更新的东西并使用它们,但它们迟早会适得其反(例如,无法编译到特定系统,可以编译但不能在任何移动商店中发布,执行速度出奇地慢,构建庞大等。最坏的情况是您的项目将受到损害)。
如果你真的不能重构你正在做的项目并且你觉得你必须使用 'up-to-date technology',请记住注入的 类 代码必须是数据对象,意味着,与 [=11= 完全无关] 在可能的时间和地点。
编辑:但我会推荐我之前告诉你的内容(重构)或链接的答案描述的内容('export' 与 mono/.net2.0 不兼容的代码到外部 dll 并从那里使用它)
我最近不得不在 Unity 中进行一些工作,这些工作需要 classes 仅在更高版本的 .NET 中可用,Unity 尚不支持。我设法下载了我丢失的极少数脚本并将其添加到我的项目中,它似乎工作正常。我想知道的是,为什么我不能将整个 .NET 源代码放入我的项目中?这样做的含义是什么?
编辑:到目前为止我添加的脚本是 WeakReference 的通用版本以及它需要的任何依赖项(System.Diagnostics.Contract 中的合同)。
编辑 编辑:我基本上想知道为什么我不能简单地将在较新版本的 .NET 中找到的 C# class 文件添加到使用较旧版本的 .NET 的 Unity。是软件问题吗?是硬件问题吗?是不是因为Unity的系统组件是对应.NET早期版本构建的?
简答:
安装 Visual Studio Tools for Unity(它应该会在您安装 Unity 时自动安装),安装时您可以在 "target framework" 下拉菜单中告诉您的 .csproj 以特定版本的 . NET Unity 使用,您将只能编译具有 Unity 支持的方法和类型的 dll。
长答案:
这是因为Unity没有使用您电脑上安装的.NET版本。 Unity 使用 Mono,而且是一个非常旧的版本。这允许统一在多个平台和操作系统上 运行。因此,您只能使用受支持的 Mono 版本中的功能。
但是,如果您查看 at their roadmap alpha 版本,您会看到
Scripting: C# Compiler Upgrade
Upgrade Mono C# compiler against our current .Net 2.0 and 2.0 Subset profiles. Note that this is an upgrade of the C# compiler only, not the full Mono runtime
然后在 "research" 阶段
Scripting: .NET Profile Upgrade
Upgrade .Net profile to 4.6 enabling access to the latest .Net functionality and APIs.
更新:
您可以从 the stickied post here 获得使用 4.6 配置文件的实验版本。
的注释
- For this release, the Editor and the following players should be working:
- Windows, OSX, Linux standalone
- iOS with IL2CPP
- Android with IL2CPP and Mono
- Other platforms are known to not work yet, and are probably not worth installing.
- Managed debugging via Visual Studio Tools for Unity or MonoDevelop is not supported in this release. If you want to use VSTU for editing please use the special build linked at the bottom of this post.
- The compiler targets the C# 6 language.
- The compiler by default will still target the .Net 4.6 framework profile.
- Known issues
- The Android/Mono build does not work properly with managed code stripping. Please disable managed code stripping for now.
- For some projects, the Windows standalone player can crash on Windows 8.1. This is intermittent, so we would love to see any crash reports or data about this
如果你真的不能重构你正在做的项目并且你觉得你必须使用 'up-to-date technology',请记住注入的 类 代码必须是数据对象,意味着,与 [=11= 完全无关] 在可能的时间和地点。
编辑:但我会推荐我之前告诉你的内容(重构)或链接的答案描述的内容('export' 与 mono/.net2.0 不兼容的代码到外部 dll 并从那里使用它)