Improve support for legacy Unity versions (WIP). Close #103

This commit is contained in:
VaDiM
2026-04-20 03:03:51 +03:00
parent e92d96bb08
commit 36699541fa
39 changed files with 959 additions and 423 deletions
+14 -11
View File
@@ -1,5 +1,6 @@
using AssetStudio;
using AssetStudioCLI.Options;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -92,14 +93,17 @@ namespace AssetStudioCLI
private static bool ExportShader(AssetItem item, string exportPath)
{
if (!TryExportFile(exportPath, item, ".shader", out var exportFullPath))
return false;
var m_Shader = (Shader)item.Asset;
var str = m_Shader.Convert();
File.WriteAllText(exportFullPath, str);
Logger.Debug($"{item.TypeString} \"{item.Text}\" exported to \"{exportFullPath}\"");
return true;
if (item.Asset is Shader m_Shader)
{
if (!TryExportFile(exportPath, item, ".shader", out var exportFullPath))
return false;
var str = m_Shader.Convert();
File.WriteAllText(exportFullPath, str);
Logger.Debug($"{item.TypeString} \"{item.Text}\" exported to \"{exportFullPath}\"");
return true;
}
return false;
}
private static bool ExportTextAsset(AssetItem item, string exportPath)
@@ -153,11 +157,10 @@ namespace AssetStudioCLI
private static bool ExportFont(AssetItem item, string exportPath)
{
var m_Font = (Font)item.Asset;
if (m_Font.m_FontData != null)
if (item.Asset is Font m_Font && m_Font.m_FontData != null)
{
var extension = ".ttf";
if (m_Font.m_FontData[0] == 79 && m_Font.m_FontData[1] == 84 && m_Font.m_FontData[2] == 84 && m_Font.m_FontData[3] == 79)
if (BinaryPrimitives.ReadInt32LittleEndian(m_Font.m_FontData) == 0x4F54544F) //"OTTO"
{
extension = ".otf";
}
+3 -14
View File
@@ -365,19 +365,7 @@ namespace AssetStudioCLI
}
var log = $"Finished loading {assetsManager.AssetsFileList.Count} files with {parsedAssetsList.Count} exportable assets";
var unityVer = assetsManager.AssetsFileList[0].version;
long m_ObjectsCount;
if (unityVer > 2020)
{
m_ObjectsCount = assetsManager.AssetsFileList.Sum(x => x.m_Objects.LongCount(y =>
y.classID != (int)ClassIDType.Shader
&& CLIOptions.o_exportAssetTypes.Value.Any(k => (int)k == y.classID))
);
}
else
{
m_ObjectsCount = assetsManager.AssetsFileList.Sum(x => x.m_Objects.LongCount(y => CLIOptions.o_exportAssetTypes.Value.Any(k => (int)k == y.classID)));
}
var m_ObjectsCount = assetsManager.AssetsFileList.Sum(x => x.m_Objects.LongCount(y => CLIOptions.o_exportAssetTypes.Value.Any(k => (int)k == y.classID)));
var objectsCount = assetsManager.AssetsFileList.Sum(x => x.Objects.LongCount(y => CLIOptions.o_exportAssetTypes.Value.Any(k => k == y.type)));
if (m_ObjectsCount != objectsCount)
{
@@ -897,7 +885,8 @@ namespace AssetStudioCLI
var gameObjects = new List<GameObject>();
CollectNode(j, gameObjects);
if (gameObjects.All(x => x.m_SkinnedMeshRenderer == null && x.m_MeshFilter == null))
if ((j.gameObject.m_Transform == null && j.gameObject.m_Animator == null)
|| gameObjects.All(x => x.m_SkinnedMeshRenderer == null && x.m_MeshFilter == null))
{
Progress.Report(++k, count);
continue;