Show / Hide Table of Contents

Interface IAssetProvider

An AssetProvider knows how to acquire assets of certain types from a certain kind of storage.

Namespace: Fusee.Base.Common
Assembly: Fusee.Base.Common.dll
Syntax
public interface IAssetProvider
Remarks

In a normal world, a good design would separate the many aspects of asset acquisition (storage, serialization, codec, asynchronicity). Unfortunately, in JavaScript-Land, it's all mixed (or should I say messed) up. You tell the JavaScript API "get me an image" and JavaScript magically loads the raw image data, converts it to a two-dimensional pixel array and calls a user-provided callback when its all done. No way to replace a single step by something self-provided. So this is FUSEE's pitiful approach for an asset acquisition abstraction which is capable of being implemented by poorly designed JavaScript APIs.

Methods

BeginGetAsset(String, GetCallback)

Asynchronous get method.

Declaration
void BeginGetAsset(string id, GetCallback getCallback)
Parameters
Type Name Description
System.String id

The identifier string.

GetCallback getCallback

Code to call when the loading is done.

Remarks

The design doesn't follow any of the standard .NET asynchronous patterns like APM, EAP, or TAP. It's close to JavaScript where you just provide an "onLoad" decoder that's called when the object is retrieved and decoded. This is to enable AssetProviders to be implemented using standard JavaScript DOM objects like Image. See the article Interop with Other Asynchronous Patterns and Types to get an idea how to map this pattern, which is similar to APM (albeit simpler), to the currently en-vogue TAP (async/await) pattern.

CanGet(String, Type)

Determines whether this asset provider can get the specified asset without actually getting it.

Declaration
bool CanGet(string id, Type type)
Parameters
Type Name Description
System.String id

The identifier string.

System.Type type

The expected type of the asset.

Returns
Type Description
System.Boolean

true if this asset will produce a result. Otherwise false.

CanGetAsync(String, Type)

Determines whether this asset provider can get the specified asset without actually getting it.

Declaration
Task<bool> CanGetAsync(string id, Type type)
Parameters
Type Name Description
System.String id

The identifier string.

System.Type type

The expected type of the asset.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

true if this asset will produce a result. Otherwise false.

CanHandleType(Type)

Determines whether this instance can handle assets of the specified type (in general).

Declaration
bool CanHandleType(Type type)
Parameters
Type Name Description
System.Type type

The asset type in question (such as typeof(ImageDate, Font, Sound, ...)).

Returns
Type Description
System.Boolean

true if this instance can handle the specified type. false otherwise.

GetAsset(String, Type)

Retrieves the asset identified by the given string.

Declaration
object GetAsset(string id, Type type)
Parameters
Type Name Description
System.String id

The identifier string.

System.Type type

The type of the asset.

Returns
Type Description
System.Object

The asset, if this provider can acquire an asset with the given id and the given type. Otherwise null.

GetAssetAsync(String, Type)

Retrieves the asset identified by the given string in async.

Declaration
Task<object> GetAssetAsync(string id, Type type)
Parameters
Type Name Description
System.String id

The identifier string.

System.Type type

The type of the asset.

Returns
Type Description
System.Threading.Tasks.Task<System.Object>

The asset, if this provider can acquire an asset with the given id and the given type. Otherwise null.

RegisterTypeHandler(AssetHandler)

Registers the given asset type decoder.

Declaration
void RegisterTypeHandler(AssetHandler handler)
Parameters
Type Name Description
AssetHandler handler

The handler.

Remarks

This method is rather for internal purposes. While an asset provider typically implements access to a given kind of asset storage, sometimes its hard to implement asset type handlers (decoders) capable of handling a certain type without knowing much about the contents (like images, etc).

Generated by DocFX
GitHub Repo
Back to top