Class TileDataService<T>
Downloads and caches tiles to the hard drive.
Namespace: Holoride.ElasticSDK
Assembly: Holoride.ElasticSDK.Library.Runtime.dll
Syntax
public abstract class TileDataService<T> : ITileDataService<T>, ITileDataProvider<T>
Type Parameters
| Name | Description |
|---|---|
| T |
Constructors
TileDataService(TileDataServiceConfiguration)
Instantiates a TileDataService.
Declaration
protected TileDataService(TileDataServiceConfiguration configuration)
Parameters
| Type | Name | Description |
|---|---|---|
| TileDataServiceConfiguration | configuration |
Fields
CacheVersion
Version of the cached files. Used in case of incompatibility with previously downloaded files.
Declaration
protected readonly int CacheVersion
Field Value
| Type | Description |
|---|---|
| int |
Configuration
Configuration for this service.
Declaration
protected readonly TileDataServiceConfiguration Configuration
Field Value
| Type | Description |
|---|---|
| TileDataServiceConfiguration |
VersionedCacheSubDirectory
The fully qualified path to the tile data cache, of the specific service, based on its name and version.
Declaration
protected readonly string VersionedCacheSubDirectory
Field Value
| Type | Description |
|---|---|
| string |
Methods
CacheMapTileDataAsync(TileAreaDescription, IProgress<float>, CancellationToken)
Caches all map tiles of a given tile array.
Declaration
public UniTask<LoadResourceResult> CacheMapTileDataAsync(TileAreaDescription tileAreaDescription, IProgress<float> onProgressUpdate = null, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| TileAreaDescription | tileAreaDescription | A tile array. |
| IProgress<float> | onProgressUpdate | A callback providing the current caching progress as a value between 0 and 1. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Cysharp.Threading.Tasks.UniTask<T><LoadResourceResult> |
CacheMapTileDataAsync(int, Vector2Int, IProgress<float>, CancellationToken)
Caches a single map tile.
Declaration
public UniTask<LoadResourceResult> CacheMapTileDataAsync(int zoomLevel, Vector2Int tilePos, IProgress<float> onProgressUpdate = null, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| int | zoomLevel | The zoom level the tile position refers to. |
| Vector2Int | tilePos | The global position index with respect to the chosen zoom level. |
| IProgress<float> | onProgressUpdate | A callback providing the current caching progress as a value between 0 and 1. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Cysharp.Threading.Tasks.UniTask<T><LoadResourceResult> |
Deserialize(byte[], out T)
Defines how the downloaded data is deserialized. This function will be called on the Unity main thread.
Declaration
protected virtual bool Deserialize(byte[] data, out T result)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The downloaded data. |
| T | result | The deserialized object. |
Returns
| Type | Description |
|---|---|
| bool | Whether the object was deserialized successfully. |
Deserialize(Stream, out T)
Defines how the downloaded data is deserialized. This function will be called on the Unity main thread.
Declaration
protected virtual bool Deserialize(Stream data, out T result)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | data | The downloaded data. |
| T | result | The deserialized object. |
Returns
| Type | Description |
|---|---|
| bool | Whether the object was deserialized successfully. |
DeserializeAsync(byte[], out T)
Defines how the downloaded data is deserialized. This function is an alternative to the Deserialize function and will be called in an extra thread. Therefore, it is not applicable for Unity objects.
Declaration
protected virtual bool DeserializeAsync(byte[] data, out T result)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The downloaded data. |
| T | result | The deserialized object. |
Returns
| Type | Description |
|---|---|
| bool | Whether the object was deserialized successfully. |
DeserializeAsync(Stream, out T)
Defines how the downloaded data is deserialized. This function is an alternative to the Deserialize function and will be called in an extra thread. Therefore, it is not applicable for Unity objects.
Declaration
protected virtual bool DeserializeAsync(Stream data, out T result)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | data | The downloaded data. |
| T | result | The deserialized object. |
Returns
| Type | Description |
|---|---|
| bool | Whether the object was deserialized successfully. |
GetFileName(int, Vector2Int)
The file name based on a given tile position and zoom level.
Declaration
protected abstract string GetFileName(int zoomLevel, Vector2Int tilePos)
Parameters
| Type | Name | Description |
|---|---|---|
| int | zoomLevel | The zoom level the tile position refers to. |
| Vector2Int | tilePos | The tile position of the tile which should get downloaded. |
Returns
| Type | Description |
|---|---|
| string | The file name. |
GetWebRequest(int, Vector2Int, CancellationToken)
The download URL based on a given tile position and zoom level.
Declaration
protected abstract UniTask<Func<UnityWebRequest>> GetWebRequest(int zoomLevel, Vector2Int tilePos, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| int | zoomLevel | The zoom level the tile position refers to. |
| Vector2Int | tilePos | The tile position of the tile which should get downloaded. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Cysharp.Threading.Tasks.UniTask<T><Func<UnityWebRequest>> | The download url. |
PrepareTileData(int, Vector2Int, IProgress<float>, CancellationToken, string, bool)
This only exists for Elastic SDK tests; it will go a way in a future refactor. Do not override this method outside of tests. It is only visible to all sub-classes due to C# limitations, not by design.
Declaration
protected virtual Task<LoadResourceResult> PrepareTileData(int zoomLevel, Vector2Int tilePos, IProgress<float> onProgressUpdate, CancellationToken cancellationToken, string fileName, bool retryUntilDownloadedSucceeded = true)
Parameters
| Type | Name | Description |
|---|---|---|
| int | zoomLevel | |
| Vector2Int | tilePos | |
| IProgress<float> | onProgressUpdate | |
| CancellationToken | cancellationToken | |
| string | fileName | |
| bool | retryUntilDownloadedSucceeded |
Returns
| Type | Description |
|---|---|
| Task<LoadResourceResult> |
RequestMapTileDataAsync(int, Vector2Int, Action<T>, CancellationToken)
Requests a tile data.
Declaration
public UniTask RequestMapTileDataAsync(int zoomLevel, Vector2Int tilePos, Action<T> onTileLoaded, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| int | zoomLevel | The zoom level the tile position refers to. |
| Vector2Int | tilePos | The global position index with respect to the chosen zoom level. |
| Action<T> | onTileLoaded | A callback providing the object that has been loaded. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Cysharp.Threading.Tasks.UniTask |