-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorials Asset Engine Service and Engine
Home ▸ Tutorials ▸ Asset Engine ▸ Service and Engine
An asset engine is an engine used to manage and manipulate assets.
With Pulsar, the asset engine is represented by AssetEngine class . This class is the entry point to gain access to all functionalities.
You can create an instance of AssetEngine :
// The constructor only needs an instance of IServiceProvider
AssetEngine assetEngine = new AssetEngine(serviceProvider);
An asset engine service is a service that provides access to an asset engine.
With Pulsar, the asset engine service is defined by IAssetEngineService interface and implemented by AssetEngineService class.
You can create an instance of AssetEngineService :
// The constructor only needs an instance of Game class
IAssetEngineService assetEngineService = new AssetEngineService(Game game);
// or
AssetEngineService assetEngineService = new AssetEngineService(Game game);
When an AssetEngineService instance is created, it becomes automatically accessible from the service provider of your game.
// myGame is an instance of Game class
GameServiceContainer serviceProvider = myGame.Services;
IAssetEngineService assetEngineService = (IAssetEngineService)serviceProvider.GetService(typeof(IAssetEngineService));
There are two ways to get an asset engine instance :
- Create yourself the instance
- Get it from an IAssetEngineService instance
To get the asset engine instance from the service, you have to call the AssetEngine property :
IAssetEngineService assetEngineService = (IAssetEngineService)serviceProvider.GetService(typeof(IAssetEngineService));
AssetEngine assetEngine = assetEngineService.AssetEngine;
You can create your own asset engine service by implementing the IAssetEngineService interface.
Here is an example of implementation :
public class MyAssetEngineService : IAssetEngineService
{
public MyAssetEngineService(Game game)
{
Engine = new AssetEngine(game.Services);
game.Services.AddService(typeof(IAssetEngineService), this);
}
public AssetEngine Engine { get; private set; }
}