Class AssetsService
This class is used to load and unload all the scene assets (music, sound, textures,...).
Inheritance
Implements
Inherited Members
Namespace: Evergine.Framework.Services
Assembly: Evergine.Framework.dll
Syntax
public class AssetsService : UpdatableService, IDependencyObject
Methods
GetAssetPath(Guid)
Gets the asset path from its id.
Declaration
protected string GetAssetPath(Guid id)
Parameters
Type | Name | Description |
---|---|---|
Guid | id | The asset id. |
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 is null, the asset type will be found 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 name 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 name 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 name 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 name 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. |
ArgumentNullException | 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 all is OK. |
Overrides
OnDestroy()
Invoked when the object is going to be disposed.
Declaration
protected override void OnDestroy()
Overrides
OnLoaded()
Invoked when the object is loaded.
Declaration
protected override void OnLoaded()
Overrides
Refresh(Guid)
Refresh the asset.
Declaration
public virtual void Refresh(Guid id)
Parameters
Type | Name | Description |
---|---|---|
Guid | id | The id of the asset. |
Refresh<T>(string)
Refresh the asset.
Declaration
public virtual void Refresh<T>(string path) where T : ILoadable
Parameters
Type | Name | Description |
---|---|---|
string | path | The name of the asset. |
Type Parameters
Name | Description |
---|---|
T | Type of the asset to load. |
RegisterInstance<T>(ILoadable)
Register 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 name is null or empty. |
Unload(string)
Unloads an asset.
Declaration
public virtual Guid Unload(string path)
Parameters
Type | Name | Description |
---|---|---|
string | path | Name of the asset to unload. |
Returns
Type | Description |
---|---|
Guid | The unloaded asset's id. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If name is null or empty. |
UnregisterSourceFactory(Guid)
Unregisters the source factory for the specified id, if 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 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. |