Export (0) Print
Expand All

ContentManager.ReadAsset Generic Method

Low-level worker method that reads asset data.

Namespace: Microsoft.Xna.Framework.Content
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

protected T ReadAsset<T> (
         string assetName,
         Action<IDisposable> recordDisposableObject
)

Type Parameters

T
Type of the asset specified for loading.

Parameters

assetName
The name of the asset to be loaded from disk.
recordDisposableObject
Delegate function for handling the disposition of assets. If recordDisposableObject is null, the default lifespan tracking and management is used, so unloading or disposing of the content manager frees everything that has been loaded through it. If recordDisposableObject specifies a valid delegate, that delegate is used instead of the default lifespan tracking and is called every time the loader encounters a type that implements IDisposable. You must use your own code to unload assets loaded in this fashion, since ContentManager's Unload method will not be aware of them.

Return Value

Returns the loaded asset.

Exception typeCondition
ObjectDisposedException ReadAsset was called after the ContentManager was disposed.
ArgumentNullException The assetName argument is null.

This protected method loads an .xnb file from disk. Unlike ContentManager's public Load method, it always returns a new copy of the specified asset, even if the asset has been loaded previously.

You can customize how shared assets are managed by overriding ContentManager's Load method. In your own Load method, keep track of what has been loaded, and call ReadAsset when you need a new asset from disk.

Xbox 360, Windows XP SP2, Windows Vista, Zune

Community Additions

ADD
Show:
© 2014 Microsoft