So i am currently developing an app for a national park in Africa and have currently hit a snag. I download the images to the users device if they do not exist locally to be used by the app. The problem is with my current approach.
I go through all the animals data and apply all of this to the animals page then also apply the image from local storage. When i do this the app freezes and currently on my PC it takes over 8 seconds to load the pictures into the sprite. Again remembering there are over 100 animals being loaded here.
How would you load all these images and remove the hang of the app? This is the code i use to load the images to sprites. My biggest concern here is that in the apps “Birds section” there are over 250 images
Stopwatch timer = new Stopwatch();
timer.Start();
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture("File:///"+Application.persistentDataPath + "/" + FilePath + ".jpg"))
{
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
{
UnityEngine.Debug.Log(uwr.error);
}
else
{
//// Get downloaded asset bundle
var texture = DownloadHandlerTexture.GetContent(uwr);
var NewSprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0), PixelsPerUnit, 0, spriteType);
UnityEngine.Debug.Log("NS:::::::::::::::::" + NewSprite);
onComplete(NewSprite);
timer.Stop();
TimeSpan timeTaken = timer.Elapsed;
UnityEngine.Debug.Log("Time Taken To Load Images " + timeTaken);
}
}