// Unload the atlas, as well as our tracking of it void UnloadAtlas(ref LoadedAtlasInfo info) { _tagToInfo.Remove(info.Tag); Dictionary <string, Sprite> sprites; if (_tagToSprites.TryGetValue(info.Tag, out sprites)) { if (!string.IsNullOrEmpty(info.FirstSpriteName)) { Sprite sprite; if (sprites.TryGetValue(info.FirstSpriteName, out sprite)) { _textureToInfo.Remove(sprite.texture); Resources.UnloadAsset(sprite.texture); } sprites.Clear(); } _spriteDictPool.Put(sprites); } _tagToSprites.Remove(info.Tag); Resources.UnloadAsset(info.Atlas); info.Atlas = null; if (OnAtlasUnloaded != null) { OnAtlasUnloaded(); } _atlasInfoPool.Put(info); info = null; }
// Organize the information we need from a loaded atlas private Texture2D SetupAtlasContents(SpriteAtlasList.AtlasInfo config, string tag, SpriteAtlas atlas, LoadedAtlasInfo info) { int spriteCount = atlas.spriteCount; Texture2D texture = null; Dictionary <string, Sprite> spriteDict = _spriteDictPool.Get(); if (atlas.spriteCount > 0) { foreach (var spriteName in config.SpriteNames) { if (!string.IsNullOrEmpty(spriteName)) { Sprite sprite = atlas.GetSprite(spriteName); info.FirstSpriteName = spriteName; spriteDict[spriteName] = sprite; if (texture == null) { texture = sprite.texture; } } } } _tagToSprites[tag] = spriteDict; return(texture); }