So, i have a large item database. It is about 100000 entries long. Each item has the attribute iconId. There are much less icons than items, since many of them are reused. They are located in “.\icons<id>.png”
(The icon ids are not just 1,2,3… They go up to about 50000 and begin an maybe 1000. Although there are much less than 40000 icons.)
Now, how would i go about loading them in runtime? The folder structure gets obfuscated. I mean, how do i do this efficiently.
I have two ideas but both are terribly inefficient . I thought about just creating an icon sprite array and to populate it via an editor script.
This way i would have to iterate through it every time i want an icon… Slow as heck.
My second idea was to just create a sprite[maxId] array and to populate it along these lines:
//pseude editor code
for (sprite s in folder "icon")
{
spriteArr[id] = getFile(s) ;
}
This way most of the array would just be null values, but i could just call Sprite ico = icons[45219];
This would be really fast, but kind of memory wasting.
Sure, i could save maybe a thousand entries by offsetting every id by the smallest id but that would just be a drop in the barrel.
Have you looked at the Addressables system? You could mark each item as addressable and then just use the address to get them. The address could be a unique name, path, guid etc. You can even use labels to filter for various types of icons. The icons can then be packed into asset bundles and loaded only when they are needed. https://docs.unity3d.com/Packages/com.unity.addressables@1.4/manual/index.html