static void Main(string[] args) { FileParser lParser = new FileParser(); string packFile = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName + "\\Resources\\test2.json.atlas"; TextureAtlasFile textFile; textFile = TextureAtlasParserImporter.ImportFromFile(packFile); TextureAtlasParserImporter.TestExportToFile(textFile, "packOutTest.atlas"); }
public override TextureAtlasFile Import(string filename, ContentImporterContext context) { return(TextureAtlasParserImporter.ImportFromFile(filename)); }
public override void OnImportAsset(AssetImportContext ctx) { Dictionary <string, List <SpriteResourceData> > animations = new Dictionary <string, List <SpriteResourceData> >(); TextureAtlasFile textureAtlasFile = TextureAtlasParserImporter.ImportFromFile(ctx.assetPath); string currentDirectory = UnityStringUtilities.RemoveFileName(ctx.assetPath); string resourcePath = ""; Debug.Log("assetPath: " + ctx.assetPath); Debug.Log("currentDirectory: " + currentDirectory); foreach (var texture in textureAtlasFile.Textures) { //Update the texture based off of the atlas Debug.Log("texture.ImagePath: " + currentDirectory + texture.ImagePath); resourcePath = currentDirectory + texture.ImagePath; TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(resourcePath); textureImporter.textureType = TextureImporterType.Sprite; textureImporter.spriteImportMode = SpriteImportMode.Multiple; textureImporter.mipmapEnabled = false; textureImporter.filterMode = FilterMode.Point; //Remove Compression to maintain better quality textureImporter.textureCompression = TextureImporterCompression.Uncompressed; List <SpriteMetaData> metas = new List <SpriteMetaData>(); int yPos = 0; foreach (var subtexture in texture.Subtexture) { SpriteMetaData meta = new SpriteMetaData(); // Convert y from top to Unity's bottom yPos = texture.Height - subtexture.Height; yPos = yPos - subtexture.Y; meta.rect = new Rect(subtexture.X, yPos, subtexture.Width, subtexture.Height); if (subtexture.Index != -1) { //meta.name = subtexture.Name + "_" + subtexture.Index.ToString(); meta.name = SpriteResourceData.GenerateImageMetaName(subtexture.Name, subtexture.Index); if (animations.ContainsKey(subtexture.Name)) { animations[subtexture.Name].Add(new SpriteResourceData(subtexture.Index, subtexture.Name, resourcePath, subtexture.FPS, subtexture.Duration)); } else { animations.Add(subtexture.Name, new List <SpriteResourceData>() { new SpriteResourceData(subtexture.Index, subtexture.Name, resourcePath, subtexture.FPS, subtexture.Duration) }); } } else { meta.name = subtexture.Name; } metas.Add(meta); } textureImporter.spritesheet = metas.ToArray(); EditorUtility.SetDirty(textureImporter); textureImporter.SaveAndReimport(); } foreach (var animation in animations) { Debug.Log("animation[" + animation.Key + "]=" + animation.Value); animation.Value.Sort(); if (animation.Value.Count > 0) { MakeAnimation(ctx, animation.Key, animation.Value); animation.Value.Clear(); } } }