Skip to content

API reference

Class AssetStore

Namespace: MicroEngine.Content
Assembly: MicroEngine.Content.dll
Guide: Assets

One entry per asset key for the whole game, shared by the scopes that hold it: a scope that asks for an asset another scope already loaded gets the same object and holds it too; the object is disposed (when it is IDisposable) once the last scope holding it releases it, and its handles become stale. Games never count references: lifetimes follow scopes.

C#
public sealed class AssetStore : IAssetStore, IDisposable

Inheritance

object ← AssetStore

Implements

IAssetStore, IDisposable

Remarks

Used from the game’s thread; loaders may be given work done elsewhere through Add``1.

Constructors

AssetStore(IContentSource, AssetLoaderRegistry?)

A store reading from source.

C#
public AssetStore(IContentSource source, AssetLoaderRegistry? loaders = null)

Parameters

source IContentSource

loaders AssetLoaderRegistry?

Exceptions

ArgumentNullException

source is null.

AssetStore(Func<IContentSource>, AssetLoaderRegistry?)

A store whose source is opened by openSource on the first read, so a game without content files never needs one.

C#
public AssetStore(Func<IContentSource> openSource, AssetLoaderRegistry? loaders = null)

Parameters

openSource Func<IContentSource>

loaders AssetLoaderRegistry?

Exceptions

ArgumentNullException

openSource is null.

Properties

Count

How many assets are loaded (each once, however many scopes hold it). Allocates nothing.

C#
public int Count { get; }

Property Value

int

IsSourceOpen

Whether Source has been opened.

C#
public bool IsSourceOpen { get; }

Property Value

bool

Loaders

The loaders, one per kind of asset.

C#
public AssetLoaderRegistry Loaders { get; }

Property Value

AssetLoaderRegistry

Log

Where reports of slow loads during play go; standard error when null.

C#
public ILog? Log { get; set; }

Property Value

ILog?

Root

The scope that lives as long as the store; create child scopes from it for levels and scenes.

C#
public AssetScope Root { get; }

Property Value

AssetScope

Source

Where content files are read from, opened on first use.

C#
public IContentSource Source { get; }

Property Value

IContentSource

Exceptions

AssetLoadException

The source cannot be opened (a missing folder or archive); its kind is “content source”.

Methods

Dispose()

Releases every scope’s assets, disposing them. The source is not disposed: whoever made it owns it.

C#
public void Dispose()

Get<T>(Asset<T>)

The asset of asset.

C#
public T Get<T>(Asset<T> asset) where T : class

Parameters

asset Asset<T>

Returns

T

Type Parameters

T

Exceptions

InvalidOperationException

The handle is None, stale (every scope released it) or of another store.

IsLoaded<T>(Asset<T>)

Whether asset still refers to a loaded asset.

C#
public bool IsLoaded<T>(Asset<T> asset) where T : class

Parameters

asset Asset<T>

Returns

bool

Type Parameters

T

TryGet<T>(Asset<T>, out T?)

The asset of asset, if it is still loaded and of type T.

C#
public bool TryGet<T>(Asset<T> asset, out T? value) where T : class

Parameters

asset Asset<T>

value T?

Returns

bool

Type Parameters

T