public static void CreateAtlas() { SpriteNames.Clear(); SpriteTextures.Clear(); foreach (MapThemeMetaData meta in ThemeManager.Instance.Themes.Values) { if (meta == null) { continue; } for (var i = 0; i < AssetNames.Length; i++) { string assetName = i < 2 ? string.Concat(meta.name, "_", AssetNames[i]) : AssetNames[i]; string spriteName = string.Concat(meta.assetRef.fullName, assetName); spriteName = Regex.Replace(spriteName, @"(\s+|@|&|'|\(|\)|<|>|#|"")", ""); var tex = meta.assetRef.package.Find(assetName)?.Instantiate <Texture2D>(); if (tex == null) { continue; } Texture2D spriteTex = tex.ScaledCopy(64.0f / tex.height); Object.Destroy(tex); spriteTex.Apply(); SpriteNames.Add(spriteName); SpriteTextures.Add(spriteTex); } } Atlas = ResourceUtils.CreateAtlas("ThemesAtlas", SpriteNames.ToArray(), SpriteTextures.ToArray()); }
public void MapNamedSprite(string name, int index) { if (_sprite_map == null) { _sprite_map = new Dictionary <string, int>(); SpriteNames = new List <string>(); } if (!_sprite_map.TryGetValue(name, out _)) { SpriteNames.Add(name); _sprite_map.Add(name, index); } }