Skip to content

Tutorials Asset Engine Service and Engine

Takumii edited this page Feb 8, 2014 · 3 revisions

HomeTutorialsAsset Engine ▸ Service and Engine

Service and Engine

What is an asset 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);

What is an asset engine service

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.


How to create an asset engine service

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);

How to get the asset engine service

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));

How to get an asset engine instance

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;

How to implement a custom asset engine service

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; }
}