Reputation: 2724
I have around 200 images I need to display one at time in Unity. These need to be held in the application and can't be downloaded from the web.
Right now I have a list set up which takes all of my images and stores. Then, on the hit of a button, I iterate through the list showing each image one at a time. My code looks like this:
public static List <Texture2D> images = new List<Texture2D>();
void Start ()
{
System.Object[] textures = Resources.LoadAll("");
foreach(object o in textures)
{
images.Add(o as Texture2D);
}
}
public static void MoveForward()
{
if(_frameCount < images.Count-1)
{
_frameCount++;
}
else
{
_frameCount = 0;
}
}
However, due to the amount of images I need to store, it's eating my iPads memory. I was wondering if there is a better way in which I could do this where I don't need to load each image at run time, hopefully speeding up the application.
Upvotes: 0
Views: 1141
Reputation: 985
You can resolve this problem in two ways:
1) If you need extra responsibility and no loading time, you can put all your assets in one (or more) spritesheets, then load spritesheet and show specific sprites you need. You can optimize memory usage by compressing this sheet.
2) If you can stand a little loading time (or no noticeable delay, if your images are not big) you can load needed image when you click the button, or keep next image preloaded - then you will have only two images loaded at a time. After that, when you move on and don't need some image right now you can unload it by using Resources.Unload
.
Upvotes: 4