XNA - 根据目标平台有条件地包含对象
我正在为 Windows 和 xbox 构建 XNA 4.0 应用程序。
在 Windows 版本中,我有一个调试控制台,它引用 IronPython 和一些紧凑框架中不支持的 CLR/DLR 程序集。我还有一些引用这些项目的部分类。
我知道我可以从 xbox 项目中删除引用以保持兼容性。但是,我还需要删除引用这些项目的类。问题是这些类由需要它们的其他类实例化,但仅限于 Windows。
解决这个困境的明显解决方案就是将对不支持的类的调用包装在 #if
预处理器指令中:
#if WINDOWS
InitializeScriptingEngine(....);
#endif
另外,我想我可以以相同的方式包装整个类/部分类以防止其被编译。有更好的方法吗?我想避免在代码中加入预处理器指令。
另外,我似乎找不到在整个解决方案范围内指定条件的方法。
I'm building an XNA 4.0 app for both Windows and the xbox.
In the Windows version, I have a debug console that references IronPython and some CLR/DLR assemblies that are not supported in the compact framework. I've also got a few partial classes that reference those items.
I know that I can remove references from the xbox project to maintain compatibility. However, I also need to remove the classes that reference those items. The issues is that those classes are instantiated by other classes that require them, but only for Windows.
The obvious solution to this quandary is just to wrap calls to the unsupported classes in #if
preprocessor directives:
#if WINDOWS
InitializeScriptingEngine(....);
#endif
Also, I suppose I could wrap an entire class/partial class the same way to keep it from being compiled. Is there a better way to do this? I'd like to avoid peppering the code with preprocessor directives.
Also, I can't seem to find a way to specify conditionals on a solution-wide basis.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 Game Studio 的内置功能“为 Xbox 360 创建项目副本”(Zune 和 Windows Phone 也是如此),则以下操作将在项目之间镜像:
至关重要的是,以下操作不在项目之间镜像:
MSDN 上的跨平台游戏项目转换器页面。此过程由项目文件中的
元素控制。结果是,您可以简单地从该平台上的项目中排除包含不相关类的文件。
就我个人而言,我更喜欢创建在平台缺少某些功能的情况下替代存根类。如果您为存根函数附加
[Conditional("NEVER_DEFINED")]
属性,那么编译器将删除对它们的调用。我相当肯定,在 Visual Studio 中没有解决方案范围内指定定义常量的方法。
If you're using Game Studio's built-in functionality for "Create copy of project for Xbox 360" (ditto for Zune and Windows Phone), then the following operations will be mirrored between projects:
Crucially, the following operations are not mirrored between projects:
This is explained (with a lot more detail) on the Cross-Platform Game Project Converter page on MSDN. This process is controlled by the
<XnaCrossPlatformGroupID>
element in the project files.The upshot is that you can simply exclude the files containing the irrelevant classes from your project on that platform.
Personally I prefer, instead of scattering
#ifdef
throughout my project, to create alternate stub classes in cases where a platform is missing some functionality. And if you attach a[Conditional("NEVER_DEFINED")]
attribute your stub functions, then the compiler will remove calls to them.I am reasonably certain that there is no solution-wide way of specifying define constants in Visual Studio.