public void DownloadTexture(UUID textureID)
{
//return;
if (!textures.ContainsKey(textureID) && !bitmaps.ContainsKey(textureID))
{
if (Client.Assets.Cache.HasAsset(textureID))
{
//Debug.Log("Cache hits!");
byte[] jpg = Client.Assets.Cache.GetCachedAssetBytes(textureID);
Bitmap img = Jpgbytes2Bitmap(jpg);
if (img == null) return;
bitmaps[textureID] = img; //fixme: there may be access violation
}
else
{
TextureDownloadCallback handler = (state, asset) =>
{
//Debug.Log("state is " + state.ToString());
try{
switch (state)
{
case TextureRequestState.Finished:
{
Bitmap img = Jpgbytes2Bitmap(asset.AssetData);
if (img == null) return;
bitmaps[textureID] = img; //fixme: there may be access violation
break;
}
case TextureRequestState.Aborted:
case TextureRequestState.NotFound:
case TextureRequestState.Timeout:
break;
}
}
catch(Exception ex)
{
Debug.Log("what happened?:" + ex.Message);
}
};
Client.Assets.RequestImage(textureID, ImageType.Normal, handler);
}
}
}