Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Editor/AseFileAnimationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ public AseFileAnimationSettings()
{
}

public AseFileAnimationSettings(string name)
{
animationName = name;
}
// public AseFileAnimationSettings(string name, bool loop = true)
// {
// animationName = name;
// loopTime = loop;
// }

[SerializeField] public string animationName;
[SerializeField] public bool loopTime = true;
Expand Down
42 changes: 35 additions & 7 deletions Editor/AseFileImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public enum AseEditorBindType
UIImage
}

public static class Settings
{
public static string COMMENT_TAGS = "//"; // Used to mark layers and animation tags as do not import
public static string LOOP_TAG_START = "-"; // Use at the beginning of an animation tag to mark as Loop Once
}


[ScriptedImporter(1, new []{ "ase", "aseprite" })]
public class AseFileImporter : ScriptedImporter
{
Expand Down Expand Up @@ -166,16 +173,25 @@ private void GenerateAnimations(AssetImportContext ctx, AseFile aseFile, Sprite[
if (animationSettings != null)
RemoveUnusedAnimationSettings(animSettings, animations);

int index = 0;
// int index = 0;

foreach (var animation in animations)
for (int animationIndex = 0; animationIndex < animations.Length; animationIndex++)
{
AnimationClip animationClip = new AnimationClip();
animationClip.name = name + "_" + animation.TagName;
animationClip.frameRate = 25;
FrameTag animation = animations[animationIndex];

if(animation.TagName.Substring(0,2) == Settings.COMMENT_TAGS)
{
continue;
}

AnimationClip animationClip = new AnimationClip();

AseFileAnimationSettings importSettings = GetAnimationSettingFor(animSettings, animation);
importSettings.about = GetAnimationAbout(animation);


animationClip.name = name + "_" + animation.TagName;
animationClip.frameRate = 25;


EditorCurveBinding editorBinding = new EditorCurveBinding();
Expand Down Expand Up @@ -258,7 +274,7 @@ private void GenerateAnimations(AssetImportContext ctx, AseFile aseFile, Sprite[
AnimationUtility.SetAnimationClipSettings(animationClip, settings);
ctx.AddObjectToAsset(animation.TagName, animationClip);

index++;
// index++;
}

animationSettings = animSettings.ToArray();
Expand Down Expand Up @@ -299,7 +315,19 @@ public AseFileAnimationSettings GetAnimationSettingFor(List<AseFileAnimationSett
return animationSettings[i];
}

animationSettings.Add(new AseFileAnimationSettings(animation.TagName));
AseFileAnimationSettings aseFileAnimationSetting = new AseFileAnimationSettings();

Debug.Log("Before: " + animation.TagName);
Debug.Log("checking " + animation.TagName.Substring(0, 1));
if(animation.TagName.Substring(0,1) ==Settings.LOOP_TAG_START)
{
animation.TagName = animation.TagName.Substring(1,animation.TagName.Length-1);
aseFileAnimationSetting.loopTime = false;
}

Debug.Log("After: " + animation.TagName);
aseFileAnimationSetting.animationName = animation.TagName;
animationSettings.Add(aseFileAnimationSetting);
return animationSettings[animationSettings.Count - 1];
}

Expand Down
13 changes: 11 additions & 2 deletions Editor/Aseprite/AseFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public Texture2D[] GetLayersAsFrames()

for (int i = 0; i < layers.Count; i++)
{
if(layers[i].LayerName.Substring(0,2) == AsepriteImporter.Settings.COMMENT_TAGS)
{
continue;
}

List<Texture2D> layerFrames = GetLayerTexture(i, layers[i]);

if (layerFrames.Count > 0)
Expand Down Expand Up @@ -129,6 +134,8 @@ public List<Texture2D> GetLayerTexture(int layerIndex, LayerChunk layer)

for (int i = 0; i < cels.Count; i++)
{
bool commentedOut = layers[i].LayerName.Substring(0,2) == AsepriteImporter.Settings.COMMENT_TAGS;

if (cels[i].LayerIndex != layerIndex)
continue;

Expand All @@ -141,13 +148,13 @@ public List<Texture2D> GetLayerTexture(int layerIndex, LayerChunk layer)
while (parent != null)
{
visibility &= parent.Visible;
if (visibility == false)
if (visibility == false || commentedOut)
break;

parent = GetParentLayer(parent);
}

if (visibility == false || layer.LayerType == LayerType.Group)
if (visibility == false || layer.LayerType == LayerType.Group || commentedOut)
continue;

textures.Add(GetTextureFromCel(cels[i]));
Expand All @@ -172,6 +179,8 @@ public Texture2D GetFrame(int index)
for (int i = 0; i < cels.Count; i++)
{
LayerChunk layer = layers[cels[i].LayerIndex];
if(layers[i].LayerName.Substring(0,2) == AsepriteImporter.Settings.COMMENT_TAGS)
continue;

LayerBlendMode blendMode = layer.BlendMode;
float opacity = Mathf.Min(layer.Opacity / 255f, cels[i].Opacity / 255f);
Expand Down
2 changes: 1 addition & 1 deletion Editor/Aseprite/Chunks/FrameTagsChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FrameTag
private byte[] ForFuture { get; set; } // 8 Bytes
public Color TagColor { get; set; } // 3 Bytes
// 1 Extra Byte
public string TagName { get; private set; }
public string TagName { get; set; }

public FrameTag(BinaryReader reader)
{
Expand Down