我正在使用Windows为MonoGame创建一些工具。我正在使用您可以在Xbox论坛上找到的教程。我实现了Graphics设备,但不知道如何加载内容。有人能帮我吗?
我正在使用MonoGame 3.4和Visual 2015
发布于 2015-10-16 14:23:00
要加载内容,您需要ContentManager。Monogame 3.4中的ContentManager构造函数接受一个IServiceProvider实例,并解析IGraphicsDeviceService以获取GraphicsDevice实例。
既然您已经实现了GraphicsDevice,那么您所需要做的就是实现IGraphicsDeviceService和IServiceProvider。
我将只实现ContentManager工作所必需的东西。
首先实现IGraphicsDeviceService以返回GraphicsDevice。
public class DeviceManager : IGraphicsDeviceService
{
public DeviceManager(GraphicsDevice device)
{
GraphicsDevice = device;
}
public GraphicsDevice GraphicsDevice
{
get;
}
public event EventHandler<EventArgs> DeviceCreated;
public event EventHandler<EventArgs> DeviceDisposing;
public event EventHandler<EventArgs> DeviceReset;
public event EventHandler<EventArgs> DeviceResetting;
}然后实现IServiceProvider以返回IGraphicsDeviceService
public class ServiceProvider : IServiceProvider
{
private readonly IGraphicsDeviceService deviceService;
public ServiceProvider(IGraphicsDeviceService deviceService)
{
this.deviceService = deviceService;
}
public object GetService(Type serviceType)
{
return deviceService;
}
}最后,您可以初始化ContentManager的一个新实例。
var content = new ContentManager(
new ServiceProvider(
new DeviceManager(graphicsDevice)));不要忘记添加对Microsoft.Xna.Framework.Content的引用。
https://stackoverflow.com/questions/33055136
复制相似问题