How to properly load textures?

Hello everyone I have this particular problem where I don’t know how to load and reference a texture in a prototype I’m making.

I want to be able to procedurally generate level, depending on a texture. This texture is located on a folder where there is other informations about the level (name, size, etc.), stored in JSON text files. Loading those files is easy using deserialization. There could be hundred of different levels, so hundred of folders containing different textures.

How can I load and reference a particular texture given the correct folder among the others?

Is using many “Resources” folders the only solution?

Hi !

Yes, it seems it’s the only solution. I think the names should be something

Level-1

Level-2

Level-11

Level-36

Level-101

Then you can:

Resources.Load("LevelTextures/Level-" + level) as Texture;

And also you can have in another folder the jsons, and so almost the same to get them.

Resources.Load("LevelJsons/Level-" + level) as TextAsset;

Hope it helps, cheers !

You can load image data using Texture2D.LoadImage.

You can get the image data into a byte array using File.ReadAllBytes.