- Home /
Asyncchronous image loading
I have a gallery filled with thumbnails, and I need it to load each one asynchronously, with progress if possible.
I did a little research and I ended up testing StartCoRoutine, but it didnt work as I thought it would, first because it freezed my UI, and secondly because all the "coroutines" ended at the same time, and I was thinking about queueing them, anyway, my worst problem is the screen freezing.
Thanks
edit: files are local
Answer by dkozar · Feb 02, 2013 at 08:19 PM
There is a handy HttpConnector class allowing you to handle multiple server calls asynchronously - with ease - and attaching callbacks for each image (each firing after the image is loaded): https://github.com/dkozar/eDriven/blob/master/eDriven.Networking/Rpc/Core/HttpConnector.cs
eDriven is a free/open source framework. In the addition, there is eDriven.Gui which handles the GUI part (not free), but its examples use the mentioned HttpConnector so you could learn from them:
Demo: http://edrivenunity.com/load-images Source: http://edrivenunity.com/backend/source/load-images-source/
When in need for loading a single image asynchronously, you could do it even with less code:
private static readonly IAsyncLoader TextureLoader = new TextureLoader();
TextureLoader.Load(ImageUrl, OnTextureLoaded); // assign the callback
private void OnTextureLoaded(Texture texture) // callback { // do something with texture }
More in this demo source: http://edrivenunity.com/backend/source/animation-demo-source/
Cheers!
Answer by DaveA · Sep 18, 2012 at 10:46 PM
http://docs.unity3d.com/Documentation/ScriptReference/WWW-texture.html
Does not have progress. But you could fire off a bunch of those at the same time and they will end when they end.