Skip to content

Instantly share code, notes, and snippets.

@lawrence-laz
Created April 17, 2020 19:12
Show Gist options
  • Save lawrence-laz/845dd1d155801ae1b2f1bf1fba631823 to your computer and use it in GitHub Desktop.
Save lawrence-laz/845dd1d155801ae1b2f1bf1fba631823 to your computer and use it in GitHub Desktop.
AssetPostprocessor for Unity to save .aseprite files as .png sprites and import them.
using UnityEditor;
using UnityEngine;
public class AsepriteUnityImporter : AssetPostprocessor
{
static void OnPostprocessAllAssets(
string[] importedAssets,
string[] deletedAssets,
string[] movedAssets,
string[] movedFromAssetPaths)
{
var refresh = false;
foreach (string asset in importedAssets)
{
if (!asset.EndsWith(".aseprite"))
continue;
var startInfo = new System.Diagnostics.ProcessStartInfo
{
WorkingDirectory = $"{Application.dataPath}/Resources".Replace('/', '\\'),
WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal,
FileName = "aseprite.exe",
Arguments = "-b spritesheet.aseprite --save-as {slice}.png",
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
};
System.Diagnostics.Process.Start(startInfo).WaitForExit();
refresh = true;
}
if (refresh)
{
EditorApplication.delayCall += ImportSprites;
}
}
private static void ImportSprites()
{
EditorApplication.delayCall -= ImportSprites;
AssetDatabase.Refresh();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment