Created
April 17, 2020 19:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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