source: 2014/24/EemeliK/Zombieland/Jypeli/Storage/FileManager/XnaSerialization.cs @ 5974

Revision 5974, 1.3 KB checked in by empaheik, 4 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.IO;
6
7namespace Jypeli
8{
9    public partial class FileManager
10    {
11        public LoadState BeginLoadContent( string assetName )
12        {
13            if ( Game.Instance == null )
14                throw new InvalidOperationException( "Content can not be loaded here, because the game has not been initialized." );
15
16            StorageFile contentFile = Game.Instance.Content.Load<StorageFile>( assetName );
17            return new LoadState( contentFile, assetName );
18        }
19
20        public T LoadContent<T>( T obj, string assetName )
21        {
22            if ( Game.Instance == null )
23                throw new InvalidOperationException( "Content can not be loaded here, because the game has not been initialized." );
24
25            byte[] contentData = Game.Instance.Content.Load<byte[]>( assetName );
26            MemoryStream contentStream = new MemoryStream( contentData );
27            StorageFile contentFile = new StorageFile( assetName, contentStream );
28
29            LoadState state = BeginLoad( contentFile, assetName );
30            T result = state.Load<T>( obj, "default" );
31            state.EndLoad();
32            return result;
33        }
34    }
35}
Note: See TracBrowser for help on using the repository browser.