public void AddAnimationsToContext(AseSheetData aseSheetData, Dictionary <string, AnimationOptions> animationOptionsByTagName = null ) { if (aseSheetData.meta.frameTags == null || aseSheetData.meta.frameTags.Length == 0) { return; } if (IndividualSprites == null) { GenerateIndividualSprites(aseSheetData, true); } foreach (var metaFrameTag in aseSheetData.meta.frameTags) { var anim = GenerateAnimation(metaFrameTag, aseSheetData.frames, IndividualSprites, animationOptionsByTagName?.ContainsKey(metaFrameTag.name) == true ? animationOptionsByTagName[metaFrameTag.name] : GetDefaultAnimationOptions); if (anim != null) { AseFileContext.AddObjectToAsset("anim_" + metaFrameTag.name, anim); } } }
/// <summary> /// Generates a 2D texture from an image file /// </summary> /// <param name="imagePath">The path to the png or jpg file</param> /// <param name="name">The name of the texture object. Defaults to the ase file name + Texture</param> /// <returns></returns> public Texture2D GenerateTexture(string imagePath, string name = null) { var texture = new Texture2D(2, 2, TextureFormat.ARGB32, false); if (!texture.LoadImage(File.ReadAllBytes(imagePath))) { AseFileContext.LogImportWarning("Texture loading not successful"); } ApplyTextureSettings(texture); texture.name = string.IsNullOrWhiteSpace(name) ? AseFileNoExt + "Texture" : name; return(texture); }
public Texture2D AddMainTextureToContext(string sheetFile) { GenerateMainTextureFromSheetFile(sheetFile); var objects = new List <Object>(); AseFileContext.GetObjects(objects); var found = objects.Find(o => o.name == "AseSheetMainTexture"); if (found) { Object.DestroyImmediate(found); } AseFileContext.AddObjectToAsset("AseSheetMainTexture", MainTexture, AseUtils.GetPixelArtIcon()); AseFileContext.SetMainObject(MainTexture); return(MainTexture); }
public void GenerateIndividualSprites(AseSheetData sheetData, bool addToContext = false) { if (SpriteImportOptions == null) { SpriteImportOptions = SpriteImportOptions.Default; } if (MainTexture == null) { GenerateMainTextureFromSheetFile(Path.Combine( Path.GetDirectoryName(sheetData.pathToSheetData) ?? throw new InvalidOperationException("Error while processing data path"), sheetData.meta.image)); } if (IndividualSprites != null) { foreach (var individualSprite in IndividualSprites) { Object.DestroyImmediate(individualSprite); } IndividualSprites.Clear(); } else { IndividualSprites = new List <Sprite>(); } var addedObjects = new Dictionary <string, int>(); if (!Config.IsLiteVersion && sheetData.meta.slices?.Length > 0 && (sheetData.meta.frameTags?.Length > 0)) { Debug.LogWarning( "It seems that you have enabled the 'Split slices' option and have animations. This is not well supported and is usually only for static images. No slices will be exported now"); } foreach (var sprite in EnumerateSprites(sheetData)) { //Make sure we prevent import of two assets with the same name if (addedObjects.ContainsKey(sprite.name)) { var newCount = addedObjects[sprite.name] + 1; addedObjects[sprite.name] = newCount; sprite.name = sprite.name + "_" + newCount; } else { addedObjects.Add(sprite.name, 1); } if (addToContext) { AseFileContext.AddObjectToAsset(sprite.name, sprite); } IndividualSprites.Add(sprite); } }