Jypeli 10
The simple game programming library
XnaSerialization.cs
Siirry tämän tiedoston dokumentaatioon.
1using System;
2using System.IO;
3
4#if WINRT
5using Windows.Storage.Streams;
6#endif
7
8namespace Jypeli
9{
10 public partial class FileManager
11 {
12 public LoadState BeginLoadContent( string assetName )
13 {
14 if ( Game.Instance == null )
15 throw new InvalidOperationException( "Content can not be loaded here, because the game has not been initialized." );
16
17 StorageFile contentFile = Game.Instance.Content.Load<StorageFile>( assetName );
18 return new LoadState( contentFile, assetName );
19 }
20
21 public T LoadContent<T>( T obj, string assetName )
22 {
23 if ( Game.Instance == null )
24 throw new InvalidOperationException( "Content can not be loaded here, because the game has not been initialized." );
25
26 byte[] contentData = Game.Instance.Content.Load<byte[]>( assetName );
27 MemoryStream contentStream = new MemoryStream( contentData );
28 StorageFile contentFile = new StorageFile( assetName, contentStream );
29
30 LoadState state = BeginLoad( contentFile, assetName );
31 T result = state.Load<T>( obj, "default" );
32 state.EndLoad();
33 return result;
34 }
35 }
36}
T LoadContent< T >(T obj, string assetName)
LoadState BeginLoadContent(string assetName)
LoadState BeginLoad(string fileName)
Definition: Serialization.cs:8
static Game Instance
Käynnissä olevan pelin pääolio.
Definition: Game.cs:96
object Load(object obj, Type type, string name)
Definition: LoadState.cs:90
void EndLoad()
Definition: LoadState.cs:31