C# MonogameAndroid:如何从流或web服务加载XNB模型?

C# MonogameAndroid:如何从流或web服务加载XNB模型?,c#,android,monogame,C#,Android,Monogame,我正在为Xamarin Android项目开发Monogame。 有人知道如何加载从web服务创建的XNB模型吗?基本上,我的web服务将返回一个XNB文件,Android设备应该能够让该文件立即显示3D模型。我知道如何从Assets Content文件夹加载静态XNB模型,但不知道如何从stream或外部web服务加载它,类似于这样: protected override void LoadContent() { spriteBatch = new Sprit

我正在为Xamarin Android项目开发Monogame。 有人知道如何加载从web服务创建的XNB模型吗?基本上,我的web服务将返回一个XNB文件,Android设备应该能够让该文件立即显示3D模型。我知道如何从Assets Content文件夹加载静态XNB模型,但不知道如何从stream或外部web服务加载它,类似于这样:

protected override void LoadContent()
{            
     spriteBatch = new SpriteBatch(GraphicsDevice);
     myModel = Content.Load<Model>("http://mywebservice.com/getXNBModel/1/");
}

我最终创建了从ContentManager派生的新类:

class XNBContentManager : ContentManager
{
        class FakeGraphicsService : IGraphicsDeviceService
        {   
            public FakeGraphicsService(GraphicsDevice graphicDevice)
            {
                GraphicsDevice = graphicDevice;
            }

            public GraphicsDevice GraphicsDevice { get; private set; }

#pragma warning disable 67
            public event EventHandler<EventArgs> DeviceCreated;
            public event EventHandler<EventArgs> DeviceDisposing;
            public event EventHandler<EventArgs> DeviceReset;
            public event EventHandler<EventArgs> DeviceResetting;
#pragma warning restore 67
        }

        class FakeServiceProvider : IServiceProvider
        {
            GraphicsDevice _graphicDevice;
            public FakeServiceProvider(GraphicsDevice graphicDevice)
            {
                _graphicDevice = graphicDevice;
            }

            public object GetService(Type serviceType)
            {
                if (serviceType == typeof(IGraphicsDeviceService))
                    return new FakeGraphicsService(_graphicDevice);

                throw new NotImplementedException();
            }
        }

        private readonly MemoryStream _xnbStream;

        public XNBContentManager(MemoryStream xnbStream, GraphicsDevice graphicDevice)
            : base(new FakeServiceProvider(graphicDevice), "Content")
        {
            _xnbStream = xnbStream;
        }

        protected override Stream OpenStream(string assetName)
        {
            return new MemoryStream(_xnbStream.GetBuffer(), false);
        }
 }
然后在LoadContent方法中使用它:

protected override void LoadContent()
{
    spriteBatch = new SpriteBatch(GraphicsDevice);
    var content = new XNBContentManager(_xnbStream, this.GraphicsDevice);
    myModel = content.Load<Model>("WhateverName");
}