Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XNA如何创建单独的ContentManager?_C#_Windows Phone 7_Xna - Fatal编程技术网

C# XNA如何创建单独的ContentManager?

C# XNA如何创建单独的ContentManager?,c#,windows-phone-7,xna,C#,Windows Phone 7,Xna,在XNA 4.0中,我尝试通过以下方式为不同的游戏屏幕创建多个内容管理器: ContentManager myManager = new ContentManager(Content.ServiceProvider, Content.RootDirectory); 由于内容是系统提供给我的原始ContentManager 然而,结果并不像我预期的那样。如果调用myManager.Unload(),那么使用原始ContentManager加载的所有内容也将被卸载。就好像这两个人持有相同的数据 我

在XNA 4.0中,我尝试通过以下方式为不同的游戏屏幕创建多个内容管理器:

ContentManager myManager = new ContentManager(Content.ServiceProvider, Content.RootDirectory);
由于内容是系统提供给我的原始ContentManager

然而,结果并不像我预期的那样。如果调用myManager.Unload(),那么使用原始ContentManager加载的所有内容也将被卸载。就好像这两个人持有相同的数据


我怎样才能将它们分开,使一个经理的卸任不影响另一个经理?

您发布的代码没有问题。就我个人而言,我使用的是
Game.Services
——但是
Content.ServiceProvider
也很好——它们都指向完全相同的对象

错误必须在代码的其他地方。您是否绝对确定在每种情况下都使用了正确的内容管理器


您是否尝试过在调试器中单步执行代码?以及使用“生成对象ID”功能?(在监视变量或鼠标悬停的变量的上下文菜单中。)

为什么您的游戏需要多个内容管理器?我认为问题可能在于两个内容管理器都使用相同的
内容
内容.ServiceProvider
。尝试创建一个单独的内容管理器而不使用它们。我希望当任何屏幕变为非活动状态时,其内容会自动卸载,以免占用太多内存。ContentManager构造函数需要这两个参数(ServiceProvider和RootDirectory)我不知道还能从哪里得到这些,所以我使用了游戏提供给我的原始内容管理器。我认为你应该跟踪当前为活动屏幕加载的所有不可加载对象,然后在切换到新屏幕时卸载它们。这就像冰箱门上有很多磁铁,然后扔掉整个冰箱,而不是每次都把所有磁铁从冰箱门上取下来。