Show / Hide Table of Contents

Class StreamAssetProvider

Asset provider base class for implementing asset providers based on streams. Used to implement FileAssetProvider and Android ApkAssetProviders.

Inheritance
System.Object
StreamAssetProvider
ApkAssetProvider
AssetProvider
FileAssetProvider
Implements
IAssetProvider
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Fusee.Base.Common
Assembly: Fusee.Base.Common.dll
Syntax
public abstract class StreamAssetProvider : IAssetProvider

Constructors

StreamAssetProvider()

Initializes a new instance of the StreamAssetProvider class.

Declaration
protected StreamAssetProvider()
Exceptions
Type Condition
System.ArgumentNullException

Methods

BeginGetAsset(String, GetCallback)

Asynchronous get method.

Declaration
public 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" handler 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.

Exceptions
Type Condition
System.NotImplementedException

CanGet(String, Type)

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

Declaration
public 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
public async 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
public 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.

CheckExists(String)

Checks the existence of the identified asset. Implement this on a given platform.

Declaration
protected abstract bool CheckExists(string id)
Parameters
Type Name Description
System.String id

The asset identifier.

Returns
Type Description
System.Boolean

Implementors should return true if a stream can be created.

CheckExistsAsync(String)

Checks the existence of the identified asset as an async method. Implement this on a given platform.

Declaration
protected abstract Task<bool> CheckExistsAsync(string id)
Parameters
Type Name Description
System.String id

The asset identifier.

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

Implementors should return true if a stream can be created.

GetAsset(String, Type)

Retrieves the asset identified by the given string.

Declaration
public 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.

Exceptions
Type Condition
System.ArgumentNullException

GetAssetAsync(String, Type)

Retrieves the asset identified by the given string with an async method.

Declaration
public async 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.

Exceptions
Type Condition
System.ArgumentNullException

GetStream(String)

Implement this on a given platform to create a stream for the asset identified by id.

Declaration
protected abstract Stream GetStream(string id)
Parameters
Type Name Description
System.String id

The asset identifier.

Returns
Type Description
System.IO.Stream

Implementors should return null if the asset cannot be retrieved.

GetStreamAsync(String)

Implement this on a given platform to create an async stream for the asset identified by id.

Declaration
protected abstract Task<Stream> GetStreamAsync(string id)
Parameters
Type Name Description
System.String id

The asset identifier.

Returns
Type Description
System.Threading.Tasks.Task<System.IO.Stream>

Implementors should return null if the asset cannot be retrieved.

RegisterTypeHandler(AssetHandler)

Registers the given asset type handler.

Declaration
public 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).

Exceptions
Type Condition
System.ArgumentNullException

Implements

IAssetProvider
Generated by DocFX
GitHub Repo
Back to top