[Docs] Added Content Extensions (#395)

This commit is contained in:
Robert Wallis
2017-05-25 12:25:47 +08:00
committed by Dylan Wilson
parent 2ec6cba497
commit 6a7bac3f90
2 changed files with 65 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
# ContentManager extensions
## ContentManager.OpenStream
`System.IO.Stream ContentManager.OpenStream(string filename)`
**OpenStream** allows easy access to `TitleContainer.OpenStream` so you can use the `Game.Content` object to load compiled resources *and* included resources.
```csharp
// my-file.txt is in the RootDirectory
var stream = Content.OpenStream("my-file.txt");
// do something with file
stream.Close();
```
## ContentManager.GetGraphicsDevice
`GraphicsDevice ContentManager.GetGraphicsDevice()`
**GetGraphicsDevice** returns the current `GraphicsDevice` from the services.
```csharp
var graphicsDevice = Content.GetGraphicsDevice();
var width = graphicsDevice.DisplayMode.Width;
```
# ContentReader extensions
The `ContentReader` extensions help when writing your own content pipeline readers.
## ContentReader.GetGraphicsDevice
`GraphicsDevice ContentManager.GetGraphicsDevice()`
**GetGraphicsDevice** returns the current `GraphicsDevice` to help when loading content for the current display.
```csharp
public class MyTypeReader : ContentTypeReader<MyType> {
protected override MyType Read(ContentReader reader, MyType existingInstance)
{
var graphicsDevice = reader.GetGraphicsDevice();
// ...
}
}
```
## ContentReader.GetRelativeAssetName
`string ContentReader.GetRelativeAssetName(string relativeName)`
**GetRelativeAssetName** helps when your content type loads a different type, and you want to know the name to give `ContentManager.Load`.
```csharp
public class MyTypeReader : ContentTypeReader<MyType> {
protected override MyType Read(ContentReader reader, MyType existingInstance)
{
var assetName = reader.GetRelativeAssetName(reader.ReadString());
var other = reader.ContentManager.Load<OtherType>(assetName);
// ...
}
}
```
+1
View File
@@ -12,6 +12,7 @@ pages:
- Core:
- BitmapFonts: MonoGame.Extended/BitmapFonts.md
- Camera2D: MonoGame.Extended/Camera2D.md
- Content Extensions: MonoGame.Extended/Content.md
- Collections: MonoGame.Extended/Collections.md
- Object Pooling: MonoGame.Extended/Object-Pooling.md
- Screens: MonoGame.Extended/Screens.md