mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-07-18 03:24:15 -04:00
Add assembly folder support for Live2D export
This commit is contained in:
@ -9,8 +9,6 @@ namespace AssetStudioCLI
|
||||
{
|
||||
internal static class Exporter
|
||||
{
|
||||
public static AssemblyLoader assemblyLoader = new AssemblyLoader();
|
||||
|
||||
public static bool ExportTexture2D(AssetItem item, string exportPath, CLIOptions options)
|
||||
{
|
||||
var m_Texture2D = (Texture2D)item.Asset;
|
||||
@ -162,7 +160,7 @@ namespace AssetStudioCLI
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExportMonoBehaviour(AssetItem item, string exportPath, CLIOptions options)
|
||||
public static bool ExportMonoBehaviour(AssetItem item, string exportPath, AssemblyLoader assemblyLoader)
|
||||
{
|
||||
if (!TryExportFile(exportPath, item, ".json", out var exportFullPath))
|
||||
return false;
|
||||
@ -170,14 +168,18 @@ namespace AssetStudioCLI
|
||||
var type = m_MonoBehaviour.ToType();
|
||||
if (type == null)
|
||||
{
|
||||
var m_Type = MonoBehaviourToTypeTree(m_MonoBehaviour, options);
|
||||
var m_Type = m_MonoBehaviour.ConvertToTypeTree(assemblyLoader);
|
||||
type = m_MonoBehaviour.ToType(m_Type);
|
||||
}
|
||||
var str = JsonConvert.SerializeObject(type, Formatting.Indented);
|
||||
File.WriteAllText(exportFullPath, str);
|
||||
if (type != null)
|
||||
{
|
||||
var str = JsonConvert.SerializeObject(type, Formatting.Indented);
|
||||
File.WriteAllText(exportFullPath, str);
|
||||
|
||||
Logger.Debug($"{item.TypeString}: \"{item.Text}\" exported to \"{exportFullPath}\"");
|
||||
return true;
|
||||
Logger.Debug($"{item.TypeString}: \"{item.Text}\" exported to \"{exportFullPath}\"");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool ExportFont(AssetItem item, string exportPath)
|
||||
@ -232,14 +234,14 @@ namespace AssetStudioCLI
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExportDumpFile(AssetItem item, string exportPath, CLIOptions options)
|
||||
public static bool ExportDumpFile(AssetItem item, string exportPath, AssemblyLoader assemblyLoader)
|
||||
{
|
||||
if (!TryExportFile(exportPath, item, ".txt", out var exportFullPath))
|
||||
return false;
|
||||
var str = item.Asset.Dump();
|
||||
if (str == null && item.Asset is MonoBehaviour m_MonoBehaviour)
|
||||
{
|
||||
var m_Type = MonoBehaviourToTypeTree(m_MonoBehaviour, options);
|
||||
var m_Type = m_MonoBehaviour.ConvertToTypeTree(assemblyLoader);
|
||||
str = m_MonoBehaviour.Dump(m_Type);
|
||||
}
|
||||
if (str != null)
|
||||
@ -367,7 +369,7 @@ namespace AssetStudioCLI
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ExportConvertFile(AssetItem item, string exportPath, CLIOptions options)
|
||||
public static bool ExportConvertFile(AssetItem item, string exportPath, CLIOptions options, AssemblyLoader assemblyLoader)
|
||||
{
|
||||
switch (item.Type)
|
||||
{
|
||||
@ -384,7 +386,7 @@ namespace AssetStudioCLI
|
||||
case ClassIDType.TextAsset:
|
||||
return ExportTextAsset(item, exportPath, options);
|
||||
case ClassIDType.MonoBehaviour:
|
||||
return ExportMonoBehaviour(item, exportPath, options);
|
||||
return ExportMonoBehaviour(item, exportPath, assemblyLoader);
|
||||
case ClassIDType.Font:
|
||||
return ExportFont(item, exportPath);
|
||||
case ClassIDType.Sprite:
|
||||
@ -396,23 +398,6 @@ namespace AssetStudioCLI
|
||||
}
|
||||
}
|
||||
|
||||
public static TypeTree MonoBehaviourToTypeTree(MonoBehaviour m_MonoBehaviour, CLIOptions options)
|
||||
{
|
||||
if (!assemblyLoader.Loaded)
|
||||
{
|
||||
var assemblyFolder = options.o_assemblyPath.Value;
|
||||
if (assemblyFolder != "")
|
||||
{
|
||||
assemblyLoader.Load(assemblyFolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
assemblyLoader.Loaded = true;
|
||||
}
|
||||
}
|
||||
return m_MonoBehaviour.ConvertToTypeTree(assemblyLoader);
|
||||
}
|
||||
|
||||
public static string FixFileName(string str)
|
||||
{
|
||||
if (str.Length >= 260) return Path.GetRandomFileName();
|
||||
|
@ -806,6 +806,7 @@ namespace AssetStudioCLI.Options
|
||||
sb.AppendLine($"# Log Level: {o_logLevel}");
|
||||
sb.AppendLine($"# Log Output: {o_logOutput}");
|
||||
sb.AppendLine($"# Export Asset List: {o_exportAssetList}");
|
||||
sb.AppendLine($"# Assebmly Path: \"{o_assemblyPath}\"");
|
||||
sb.AppendLine($"# Unity Version: \"{o_unityVersion}\"");
|
||||
break;
|
||||
default:
|
||||
|
@ -16,12 +16,21 @@ namespace AssetStudioCLI
|
||||
public AssetsManager assetsManager = new AssetsManager();
|
||||
public List<AssetItem> parsedAssetsList = new List<AssetItem>();
|
||||
private static Dictionary<AssetStudio.Object, string> containers = new Dictionary<AssetStudio.Object, string>();
|
||||
private static AssemblyLoader assemblyLoader = new AssemblyLoader();
|
||||
private readonly CLIOptions options;
|
||||
|
||||
public Studio(CLIOptions cliOptions)
|
||||
public Studio(CLIOptions cliOptions)
|
||||
{
|
||||
Progress.Default = new Progress<int>(ShowCurProgressValue);
|
||||
options = cliOptions;
|
||||
if (options.o_assemblyPath.Value != "")
|
||||
{
|
||||
assemblyLoader.Load(options.o_assemblyPath.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
assemblyLoader.Loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowCurProgressValue(int value)
|
||||
@ -308,14 +317,14 @@ namespace AssetStudioCLI
|
||||
break;
|
||||
case WorkMode.Dump:
|
||||
Logger.Debug($"{options.o_workMode}: {asset.Type} : {asset.Container} : {asset.Text}");
|
||||
if (ExportDumpFile(asset, exportPath, options))
|
||||
if (ExportDumpFile(asset, exportPath, assemblyLoader))
|
||||
{
|
||||
exportedCount++;
|
||||
}
|
||||
break;
|
||||
case WorkMode.Export:
|
||||
Logger.Debug($"{options.o_workMode}: {asset.Type} : {asset.Container} : {asset.Text}");
|
||||
if (ExportConvertFile(asset, exportPath, options))
|
||||
if (ExportConvertFile(asset, exportPath, options, assemblyLoader))
|
||||
{
|
||||
exportedCount++;
|
||||
}
|
||||
@ -438,7 +447,7 @@ namespace AssetStudioCLI
|
||||
container = Path.HasExtension(container) ? container.Replace(Path.GetExtension(container), "") : container;
|
||||
var destPath = Path.Combine(baseDestPath, container) + Path.DirectorySeparatorChar;
|
||||
|
||||
ExtractLive2D(assets, destPath, modelName);
|
||||
ExtractLive2D(assets, destPath, modelName, assemblyLoader);
|
||||
modelCounter++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Reference in New Issue
Block a user