public static string[] GetListOfSprites(this SpriteAtlas spriteAtlas, string match = null) { var sprites = spriteAtlas.GetAllSprites().ToArray(); if (string.IsNullOrEmpty(match)) { return(sprites.Select(x => x.name).ToArray()); } var list = new List <string>(); for (int i = 0, imax = sprites.Length; i < imax; ++i) { var sprite = sprites[i]; if (sprite != null && !string.IsNullOrEmpty(sprite.name) && string.Equals(match, sprite.name, StringComparison.OrdinalIgnoreCase)) { list.Add(sprite.name); return(list.ToArray()); } } var keywords = match.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < keywords.Length; ++i) { keywords[i] = keywords[i].ToLower(); } for (int i = 0, imax = sprites.Length; i < imax; ++i) { var sprite = sprites[i]; if (sprite != null && !string.IsNullOrEmpty(sprite.name)) { string tl = sprite.name.ToLower(); int matches = 0; for (int b = 0; b < keywords.Length; ++b) { if (tl.Contains(keywords[b])) { ++matches; } } if (matches == keywords.Length) { list.Add(sprite.name); } } } return(list.ToArray()); }
private static void CacheSpriteAtlases() { string[] atlasGUIDs = AssetDatabase.FindAssets("t:SpriteAtlas"); for (int i = 0; i < atlasGUIDs.Length; i++) { SpriteAtlas atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(AssetDatabase.GUIDToAssetPath(atlasGUIDs[i])); Sprite[] sprites = atlas.GetAllSprites().Distinct().ToArray(); if (atlas.isVariant) { if (atlas.TryGetMasterAtlas(out SpriteAtlas masterAtlas)) { sprites = masterAtlas.GetAllSprites().Distinct().ToArray(); } } atlasToAllSprites.Add(atlas, sprites); } }
public static void CacheKnowAtlases() { atlasToAllSprites.Clear(); atlasToScale.Clear(); string[] atlasGUIDs = AssetDatabase.FindAssets("t:SpriteAtlas"); for (int i = 0; i < atlasGUIDs.Length; i++) { SpriteAtlas atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(AssetDatabase.GUIDToAssetPath(atlasGUIDs[i])); if (!atlas.IsIncludedInBuild()) { continue; } Sprite[] sprites = atlas.GetAllSprites().Distinct().ToArray(); float scale = 1.0f; if (atlas.isVariant) { if (atlas.TryGetMasterAtlas(out SpriteAtlas masterAtlas)) { sprites = masterAtlas.GetAllSprites().Distinct().ToArray(); } scale = atlas.GetVariantScale(); } atlasToAllSprites.Add(atlas, sprites); atlasToScale.Add(atlas, scale); } hasDataCached = true; }