So, we’re developing a game where we need to download for each game a certain gif. We have split these gifs into spritesheets and they are stored in our database, which we can access through the Rest communicating with Server.
Problem: After I load a spritesheet from the outside, thats about 4000x4000 pixels, the game eats like 100MB of RAM, which is a problem here. Here is a snippet of my code:
private IEnumerator LoadImageFromURL(_AnimatedSprite a)
{
Debug.Log("Checking url");
WWW www;
if(a.HasThumbnail)
{
www = new WWW(a.URL);
}
else
{
www = new WWW(a.URLThumnail);
}
Debug.Log("Started downloading");
yield return www;
if (www.error != null)
{
Debug.Log("Error!");
Switcher.mb.showMessage(MessageBox.MessageType.negative, www.error);
a.Loaded = true;
running = false;
}
else
{
if (!a.HasThumbnail)
{
www.LoadImageIntoTexture(a.Thumbnail);
// a.Thumbnail.LoadImage(www.bytes);
// a.Thumbnail.Compress(false);
a.HasThumbnail = true;
}
else
{
www.LoadImageIntoTexture(a.SpriteSheet);
// a.SpriteSheet.LoadImage(www.bytes);
// a.SpriteSheet.Compress(true);
a.Loaded = true;
}
Texture2D.Destroy(www.texture);
Texture2D.Destroy(www.textureNonReadable);
Resources.UnloadUnusedAssets();
}
running = false;
www.Dispose();
www = null;
string s = a.HasThumbnail ? "animation" : "thumbnail";
Debug.Log("Finished downloading " + s);
}
Any help is appreciated. Thanks!