mirror of
https://github.com/aelurum/AssetStudio.git
synced 2026-11-14 11:18:47 -05:00
Add option to keep original sprite sizes. Close #107
- Enabled by default - [GUI] Added "Keep original sprite sizes" option to the Export options - [CLI] Added "--sprite-cropping" option to the Advanced section
This commit is contained in:
@@ -78,6 +78,12 @@ namespace AssetStudioCLI.Options
|
||||
All,
|
||||
}
|
||||
|
||||
internal enum SpriteCroppingMode
|
||||
{
|
||||
SpriteRect,
|
||||
TextureRect,
|
||||
}
|
||||
|
||||
internal static class CLIOptions
|
||||
{
|
||||
public static bool isParsed;
|
||||
@@ -132,6 +138,7 @@ namespace AssetStudioCLI.Options
|
||||
public static Option<ExportListType> o_exportAssetList;
|
||||
public static Option<string> o_assemblyPath;
|
||||
public static Option<string> o_stripPathPrefix;
|
||||
public static Option<SpriteCroppingMode> o_spriteCroppingMode;
|
||||
public static Option<bool> f_notRestoreExtensionName;
|
||||
public static Option<bool> f_avoidLoadingViaTypetree;
|
||||
public static Option<bool> f_rawByteArrayFromMono;
|
||||
@@ -573,6 +580,17 @@ namespace AssetStudioCLI.Options
|
||||
optionExample: "Example: \"--strip-path-prefix assets/models/char/\"\n",
|
||||
optionHelpGroup: HelpGroups.Advanced
|
||||
);
|
||||
o_spriteCroppingMode = new GroupedOption<SpriteCroppingMode>
|
||||
(
|
||||
optionDefaultValue: SpriteCroppingMode.SpriteRect,
|
||||
optionName: "--sprite-cropping",
|
||||
optionDescription: "Specify the sprite cropping mode\n" +
|
||||
"<Value: spriteRect(default) | textureRect>\n" +
|
||||
"SpriteRect - Crop sprites keeping their own size and alignment\n" +
|
||||
"TextureRect - Crop sprites to their actual image size (aka trim)\n",
|
||||
optionExample: "Example: \"--sprite-cropping textureRect\"\n",
|
||||
optionHelpGroup: HelpGroups.Advanced
|
||||
);
|
||||
f_notRestoreExtensionName = new GroupedOption<bool>
|
||||
(
|
||||
optionDefaultValue: false,
|
||||
@@ -1277,6 +1295,21 @@ namespace AssetStudioCLI.Options
|
||||
o_stripPathPrefix.Value += Path.DirectorySeparatorChar;
|
||||
}
|
||||
break;
|
||||
case "--sprite-cropping":
|
||||
switch (value.ToLower())
|
||||
{
|
||||
case "spriterect":
|
||||
o_spriteCroppingMode.Value = SpriteCroppingMode.SpriteRect;
|
||||
break;
|
||||
case "texturerect":
|
||||
o_spriteCroppingMode.Value = SpriteCroppingMode.TextureRect;
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{option.Color(brightYellow)}] option. Unsupported sprite cropping mode: [{value.Color(brightRed)}].\n");
|
||||
ShowOptionDescription(o_spriteCroppingMode);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "--unity-version":
|
||||
try
|
||||
{
|
||||
@@ -1521,6 +1554,7 @@ namespace AssetStudioCLI.Options
|
||||
{
|
||||
sb.AppendLine($"# Export Image Format: {o_imageFormat}");
|
||||
sb.AppendLine($"# Export Audio Format: {o_audioFormat}");
|
||||
sb.AppendLine($"# Sprite Cropping Mode: {o_spriteCroppingMode}");
|
||||
sb.AppendLine($"# Restore TextAsset Extension: {!f_notRestoreExtensionName.Value}");
|
||||
sb.AppendLine($"# Max Parallel Export Tasks: {o_maxParallelExportTasks}");
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ namespace AssetStudioCLI
|
||||
{
|
||||
debugLog = "";
|
||||
var type = CLIOptions.o_imageFormat.Value;
|
||||
var converter = new SpriteConverter((Sprite)item.Asset);
|
||||
var keepSpriteSize = CLIOptions.o_spriteCroppingMode.Value == SpriteCroppingMode.SpriteRect;
|
||||
var converter = new SpriteConverter((Sprite)item.Asset, keepSpriteSize);
|
||||
if (CLIOptions.o_filenameFormat.Value == FilenameFormat.AssetName_Hash)
|
||||
item.Hash = converter.GetSpriteHash();
|
||||
if (!TryExportFile(exportPath, item, $".{type}", out var exportFullPath))
|
||||
|
||||
Reference in New Issue
Block a user