简体   繁体   English

我想在 XBox360 上使用常规的 class 库!

[英]I want to use a regular class library on XBox360!

why can't I use regular class libraries in XBox360 games?为什么我不能在 XBox360 游戏中使用常规 class 库?

I have application logic which I want to keep independent from XNA and use in both WPF and XNA applications.我有应用程序逻辑,我想保持独立于 XNA 并在 WPF 和 XNA 应用程序中使用。

Does anyone know good practice to share code between XBox/Phone7 applications and "regular" windows applications?有谁知道在 XBox/Phone7 应用程序和“常规”windows 应用程序之间共享代码的良好做法?

Have a look at Portable Class Libraries: http://msdn.microsoft.com/en-us/library/gg597391.aspx看看便携式 Class 库: http://msdn.microsoft.com/en-us/library/gg597391.aspx

Using the Portable Class Library project, you can build portable assemblies that work without modification on the .NET Framework, Silverlight, Windows Phone 7, or XNA (Xbox) platforms.使用便携式 Class 库项目,您可以构建无需修改即可在 .NET 框架、Silverlight、ZAEA23489CE3AA9B6406EBB28ENACD(Xbox 406EBB28E0)平台上工作的便携式程序集。 Without the Portable Class Library project, you must target a single platform and then manually rework the class library for other platforms.如果没有便携式 Class 库项目,您必须针对单个平台,然后为其他平台手动修改 class 库。 The Portable Class Library project supports a subset of assemblies from these platforms, and provides a Visual Studio template that makes it possible to build assemblies that run without modification on these platforms.便携式 Class 库项目支持来自这些平台的程序集子集,并提供了一个 Visual Studio 模板,可以构建无需修改即可在这些平台上运行的程序集。

Edit : Check out JoDG's answer for a nicer solution.编辑:查看JoDG 的答案以获得更好的解决方案。

You could try linked files...您可以尝试链接文件...

In your Xbox project, right-click -> Add Existing File, then after selecting the file(s), click the little drop-down arrow on the "Add" button and click "Add As Link", as shown here:在您的 Xbox 项目中,右键单击 -> 添加现有文件,然后选择文件后,单击“添加”按钮上的小下拉箭头,然后单击“添加为链接”,如下所示:

添加为链接

This might not work if you need to share more than just files, but it's an easy way to share code.如果您需要共享的不仅仅是文件,这可能不起作用,但这是一种共享代码的简单方法。

JoDG's answer is probably the most practically useful. JoDG 的答案可能是最实用的。 But just to provide additional information:但只是为了提供更多信息:

why can't I use regular class libraries in XBox360 games?为什么我不能在 XBox360 游戏中使用常规 class 库?

Because the different XNA platforms target different versions of the .NET framework.因为不同的 XNA 平台针对不同版本的 .NET 框架。

XNA Game Studio itself provides a mechanism ( documented here and more info here ) for automatically mirroring the source files of a project between two projects. XNA Game Studio 本身提供了一种机制(在此处记录并在此处获得更多信息)用于在两个项目之间自动镜像项目的源文件。 This mechanism can be used for creating copies of your library projects for each platform, as well as for your game projects.此机制可用于为每个平台以及您的游戏项目创建库项目的副本。

For XNA-related work, this is the preferred method for creating cross-platform libraries.对于 XNA 相关的工作,这是创建跨平台库的首选方法。 When you have to also make your library work on WPF you have to take additional steps:当您还必须使您的库在 WPF 上工作时,您必须采取额外的步骤:

On Windows, an XNA game is just like any other .NET application, and a XNA library for Windows is just like any other .NET library.在 Windows 上,XNA 游戏就像任何其他 .NET 应用程序一样,Windows 的 XNA 库就像任何其他 Z303CB0EF59EDB90872DAZ61 库一样。 Except for the fact that they reference XNA assemblies.除了它们引用 XNA 程序集这一事实。 So your WPF application can reference a Windows version of your XNA library.因此,您的 WPF 应用程序可以引用 XNA 库的 Windows 版本。 But if you want your application to work on systems without XNA installed, you need to remove the XNA assembly references from the Windows project for that XNA library.但是,如果您希望您的应用程序在没有安装 XNA 的系统上运行,您需要从该 XNA 库的 Windows 项目中删除XNA 程序集引用。

XNA Game Studio will still mirror changes between the Windows library and the Xbox 360 library for you. XNA Game Studio 仍将为您镜像 Windows 库和 Xbox 360 库之间的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM