I have a SpriteManager that has several lists of sprites. I am using it to change sprite textures during runtime.
I have a folder with all the sprite atlases in it. Because all the “tree” sprites have the same parts, they use the same layout in their atlases. So [oak] has an [oak SpriteAtlas] with a [Limb] sprite, and [pine] has an [pine SpriteAtlas] with a [Limb] sprite.
When I load the sprites, I get [Limb] and [Limb] but do not know how to tell which atlas they came from.
So I want a way to load the sprite atlas as a whole, then load the sprites from that atlas. I do not want to have to specify the name of each tree, as there are too many.
Here is the code currently:
public IEnumerator LoadSprites()
{
Debug.Log("Loading sprites");
//first, we can find all the sprites
allSpriteObjects = Resources.LoadAll("Sprites", typeof(Sprite));
//then we need a list for each atlas
allSpriteAtlases = new List<Sprite[]>();
//now we need to put each sprite in the correct atlas entry
foreach (Object o in allSpriteObjects)
{
Debug.Log("Loaded " + o.name);
//HERE: How do I know what atlas this sprite was pulled from?
yield return new WaitForSeconds(0.1f);
}
}
My end goal is to have a List<List<Sprite>
, or a List<Sprite[]>
or a List<SpriteAtlas>
, so that I can find the [Limb Sprite] of [pine SpriteAtlas] from the manager.