Class AssetsService
This class is used to load and unload all the scene assets (music, sound, textures, etc.).
Inheritance
Implements
Inherited Members
Namespace: Evergine.Framework.Services
Assembly: Evergine.Framework.dll
Syntax
public class AssetsService : UpdatableService, IDependencyObject
Methods
GetAssetPath(Guid, Type)
Gets the asset path from its ID.
Declaration
protected string GetAssetPath(Guid id, Type type = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | id | The asset ID. |
| Type | type | The type of the asset. |
Returns
| Type | Description |
|---|---|
| string | The key. |
GetAssetSource<T>(Guid)
Creates a new AssetSource for the given asset ID.
Declaration
public T GetAssetSource<T>(Guid id) where T : AssetSource
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | id | The asset ID. |
Returns
| Type | Description |
|---|---|
| T | A new AssetSource for the given asset ID. |
Type Parameters
| Name | Description |
|---|---|
| T | The asset source type. |
Load(Guid, Type, bool)
Loads an asset.
Declaration
public virtual ILoadable Load(Guid id, Type desiredType = null, bool forceNewInstance = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | id | The name of the asset. |
| Type | desiredType | The desired type to load. If null, the asset type will be determined using the file extension. |
| bool | forceNewInstance | True to force returning a new instance of the asset. |
Returns
| Type | Description |
|---|---|
| ILoadable | The loaded asset. |
Load<T>(Guid, bool)
Loads an asset.
Declaration
public virtual T Load<T>(Guid id, bool forceNewInstance = false) where T : ILoadable
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | id | The ID of the asset. |
| bool | forceNewInstance | True to force returning a new instance of the asset. |
Returns
| Type | Description |
|---|---|
| T | The loaded asset. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the asset to load. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the ID is null or empty. |
Load<T>(string, bool)
Loads an asset.
Declaration
public virtual T Load<T>(string path, bool forceNewInstance = false) where T : ILoadable
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path of the asset. |
| bool | forceNewInstance | True to force returning a new instance of the asset. |
Returns
| Type | Description |
|---|---|
| T | The loaded asset. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the asset to load. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If path is null or empty. |
Load<T>(string, Stream, bool)
Loads an asset.
Declaration
public virtual T Load<T>(string name, Stream stream, bool forceNewInstance = false) where T : ILoadable
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the asset. |
| Stream | stream | The stream of the asset. |
| bool | forceNewInstance | True to force a new instance of the asset. |
Returns
| Type | Description |
|---|---|
| T | The loaded asset. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the asset to load. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Stream is null. |
| ArgumentException | Asset name is null or empty. |
OnAttached()
Invoked when the object is attached to the system.
Declaration
protected override bool OnAttached()
Returns
| Type | Description |
|---|---|
| bool | True if everything is OK. |
Overrides
OnDestroy()
Invoked when the object is about to be disposed.
Declaration
protected override void OnDestroy()
Overrides
OnLoaded()
Invoked when the object is loaded.
Declaration
protected override void OnLoaded()
Overrides
Refresh(Guid)
Refreshes the asset.
Declaration
public virtual void Refresh(Guid id)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | id | The ID of the asset. |
Refresh<T>(string)
Refreshes the asset.
Declaration
public virtual void Refresh<T>(string path) where T : ILoadable
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path of the asset. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the asset to load. |
RegisterInstance<T>(ILoadable)
Registers an instance of an asset into the assets service.
Declaration
public bool RegisterInstance<T>(ILoadable asset) where T : ILoadable
Parameters
| Type | Name | Description |
|---|---|---|
| ILoadable | asset | The new asset. |
Returns
| Type | Description |
|---|---|
| bool | True if the asset has been registered properly; false otherwise. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the asset. |
RegisterSourceFactory(IAssetSourceFactory)
Registers the source factory.
Declaration
public void RegisterSourceFactory(IAssetSourceFactory assetSourceFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| IAssetSourceFactory | assetSourceFactory | The asset source factory. |
RegisterSourceLoader(IAssetSourceLoadableConverter)
Registers the source loader converter.
Declaration
public void RegisterSourceLoader(IAssetSourceLoadableConverter assetSourceLoadableConverter)
Parameters
| Type | Name | Description |
|---|---|---|
| IAssetSourceLoadableConverter | assetSourceLoadableConverter | The asset source loader converter. |
Unload(Guid)
Unloads an asset.
Declaration
public virtual void Unload(Guid id)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | id | ID of the asset to unload. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the ID is null or empty. |
Unload(string)
Unloads an asset.
Declaration
public virtual Guid Unload(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | Path of the asset to unload. |
Returns
| Type | Description |
|---|---|
| Guid | The unloaded asset's ID. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the path is null or empty. |
UnregisterSourceFactory(Guid)
Unregisters the source factory for the specified id, if it is registered.
Declaration
public void UnregisterSourceFactory(Guid id)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | id | The asset id. |
UnregisterSourceFactory(string)
Unregisters the source factory for the specified path, if it is registered.
Declaration
public void UnregisterSourceFactory(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The asset path. |
Update(TimeSpan)
Updates this instance.
Declaration
public override void Update(TimeSpan gameTime)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | gameTime | The elapsed game time since the last update. |