public static UITextureAtlas GetSapphireAtlas() { if (atlas == null) { var atlasPacker = new AtlasPacker(); atlasPacker.AddSprite("SapphireIcon", GetTextureResource("SapphireIcon.png")); atlasPacker.AddSprite("SapphireIconHover", GetTextureResource("SapphireIconHover.png")); atlasPacker.AddSprite("SapphireIconPressed", GetTextureResource("SapphireIconPressed.png")); atlasPacker.AddSprite("DefaultPanelBackground", GetTextureResource("DefaultPanelBackground.png")); atlas = atlasPacker.GenerateAtlas("SapphireIconsAtlas"); } return(atlas); }
private void LoadSpritesInternal() { Debug.LogWarning("Loading sprites"); foreach (XmlNode childNode in root) { if (childNode.Name != "SpriteAtlas") { continue; } var atlasName = XmlUtil.GetStringAttribute(childNode, "name"); if (spriteAtlases.ContainsKey(atlasName)) { throw new ParseException(String.Format("Duplicate atlas name \"{0}\"", atlasName), childNode); } Debug.LogWarningFormat("Generating atlas \"{0}\"", atlasName); var atlasPacker = new AtlasPacker(); int count = 0; foreach (XmlNode spriteNode in childNode.ChildNodes) { var path = spriteNode.InnerText; if (fileWatcher != null) { fileWatcher.WatchFile(path); } var name = XmlUtil.GetStringAttribute(spriteNode, "name"); Debug.LogWarningFormat("Found definition for sprite \"{0}\" in atlas \"{1}\"", name, atlasName); var fullPath = Path.Combine(sapphirePath, path); if (!File.Exists(fullPath)) { throw new FileNotFoundException(String.Format("Sprite at path \"{0}\" not found!", fullPath), fullPath); } atlasPacker.AddSprite(name, fullPath); count++; } Debug.LogWarningFormat("Added {0} sprites to atlas \"{1}\"", count, atlasName); try { spriteAtlases[atlasName] = atlasPacker.GenerateAtlas(atlasName); } catch (AtlasPacker.TooManySprites) { ErrorLogger.LogError("Too many sprites in atlas \"" + atlasName + "\", move some sprites to a new atlas!"); break; } Debug.LogWarningFormat("Atlas \"{0}\" generated", atlasName); } }