I’ve an inventory system, 500+ unique sprites.
What’s a good way to fetch a sprites?
Currently I just cycle through a bunch of spritesheets and throw all their sprites in a dictionary like this
string root = "UI/Inventory/Items/";
for ( int i = 0; i < 17; i++ )
{
Sprite[] s = Resources.LoadAll<Sprite>( root + i.ToString() );
for ( int j = 0; j < s.Length; j++ )
{
sprites.Add( i + ", " + j, s[j] );
}
}
And get the information like this
internal Sprite Get( int subcategory, int categoryIndex )
{
try
{
Debug.Log( string.Format( "Fetching {0}[{1}]", subcategory, v ) );
return sprites[subcategory + ", " +categoryIndex ];
}
catch ( Exception )
{
Debug.LogError( string.Format( InventoryItemRoot + "{0}[{1}] not found.", subcategory, categoryIndex ) );
throw;
}
}
But it feels pretty impractical having 500 odd sprites loaded all the time.