AssetLoadHelper Class |
Namespace: DigitalRune.Graphics.Content
The AssetLoadHelper type exposes the following members.
Name | Description | |
---|---|---|
Dispose |
Releases the AssetLoadHelper.
| |
Equals | (Inherited from Object.) | |
FixupT |
Wraps and registers a fix-up action.
| |
Get |
Gets the AssetLoadHelper for a specific asset.
| |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
AssetLoaded |
Occurs after all fix-up actions were executed and the asset is fully loaded.
|
Shared resources (see ReadSharedResource``1(ActionUMP)) are loaded deferred. When the Read(ContentReader, Object) method returns, shared resources might not yet be loaded. An AssetLoadHelper keeps track of the loading of shared resources for a specific asset. An AssetLoadHelper raises an event AssetLoaded when all fix-up actions have been executed and all shared resources have been loaded. This event can be used to initialize an asset as soon as it is loaded including all shared resources.
Each asset has a certain AssetLoadHelper which can be retrieved by calling Get(String). Any fixup actions of the asset must be wrapped using FixupT(ActionT) (see example below).
WARNING: The AssetLoadHelper can only be used to track shared resources when it is guaranteed that they have a value that is not . This is a limitation by the XNA Framework. (When a shared resource is loaded by calling ReadSharedResource``1(ActionUMP) the fix-up action only gets executed, when it has a value other than . When the value is the fix-up action will never get executed and the AssetLoadHelper will never realize that the loading of the asset has finished.)
internal class MyAssetReader : ContentTypeReader<MyAsset> { protected override MyAsset Read(ContentReader input, MyAsset existingInstance) { if (existingInstance == null) existingInstance = new MyAsset(); ... load properties of MyAsset ... // Load shared resources: // Use AssetLoadHelper to receive an event when the asset (including // all shared resources) is loaded. using (var helper = AssetLoadHelper.Get(input.AssetName)) { // When loading the shared resource, use AssetLoadHelper.Fixup() to // wrap the fix-up action. input.ReadSharedResource(helper.Fixup<MyResource>(res => existingInstance.Resource = res)); helper.AssetLoaded += existingInstance.OnAssetLoaded; } return existingInstance; } }