mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
Export meta references on Unity 3 as type 1
* Reverts most of 70f21a0b7a3760b9ff41fcb3670e24d8a09ba7d9 * Resolves #1329 * Resolves #1827
This commit is contained in:
parent
e9db99e07e
commit
88f6700ccd
@ -8,7 +8,7 @@ public readonly record struct MetaPtr(long FileID, UnityGuid GUID, AssetType Ass
|
||||
{
|
||||
}
|
||||
|
||||
public YamlNode ExportYaml()
|
||||
public YamlNode ExportYaml(UnityVersion exportVersion)
|
||||
{
|
||||
YamlMappingNode node = new();
|
||||
node.Style = MappingStyle.Flow;
|
||||
@ -16,7 +16,20 @@ public readonly record struct MetaPtr(long FileID, UnityGuid GUID, AssetType Ass
|
||||
if (!GUID.IsZero)
|
||||
{
|
||||
node.Add(GuidName, GUID.ToString());
|
||||
node.Add(TypeName, (int)AssetType);
|
||||
if (exportVersion.GreaterThanOrEquals(4) || AssetType is not AssetType.Meta)
|
||||
{
|
||||
node.Add(TypeName, (int)AssetType);
|
||||
}
|
||||
else
|
||||
{
|
||||
// For Unity 3, type 3 (Meta) is only used for 3d models.
|
||||
// All other imported assets (eg images and audio) use type 1 (Cached).
|
||||
// Since we only export yaml meshes during Unity project export and have no plans to change that,
|
||||
// we can safely redirect all type 3 references to type 1.
|
||||
// https://github.com/AssetRipper/AssetRipper/issues/1827
|
||||
// https://github.com/AssetRipper/AssetRipper/issues/1329
|
||||
node.Add(TypeName, (int)AssetType.Cached);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -49,17 +49,17 @@ public sealed class ProjectYamlWalker(IExportContainer container) : YamlWalker
|
||||
{
|
||||
if (pptr.PathID == 0)
|
||||
{
|
||||
return MetaPtr.NullPtr.ExportYaml();
|
||||
return MetaPtr.NullPtr.ExportYaml(container.ExportVersion);
|
||||
}
|
||||
else if (CurrentAsset.Collection.TryGetAsset(pptr, out TAsset? asset))
|
||||
{
|
||||
return container.CreateExportPointer(asset).ExportYaml();
|
||||
return container.CreateExportPointer(asset).ExportYaml(container.ExportVersion);
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetType assetType = container.ToExportType(typeof(TAsset));
|
||||
MetaPtr pointer = MetaPtr.CreateMissingReference(GetClassID(typeof(TAsset)), assetType);
|
||||
return pointer.ExportYaml();
|
||||
return pointer.ExportYaml(container.ExportVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,6 @@ public class ScriptExporter : IAssetExporter
|
||||
};
|
||||
ExportMode = configuration.ExportSettings.ScriptExportMode;
|
||||
ReferenceAssemblyDictionary = ReferenceAssemblies.GetReferenceAssemblies(AssemblyManager, configuration.Version);
|
||||
ExportType = GetAssetType(configuration.Version);
|
||||
}
|
||||
|
||||
public IAssemblyManager AssemblyManager { get; }
|
||||
@ -28,7 +27,6 @@ public class ScriptExporter : IAssetExporter
|
||||
internal ScriptDecompiler Decompiler { get; }
|
||||
internal Dictionary<string, UnityGuid> ReferenceAssemblyDictionary { get; }
|
||||
private bool HasDecompiled { get; set; } = false;
|
||||
private AssetType ExportType { get; }
|
||||
private static long MonoScriptDecompiledFileID { get; } = ExportIdHandler.GetMainExportID((int)ClassIDType.MonoScript);
|
||||
|
||||
public bool TryCreateCollection(IUnityObjectBase asset, [NotNullWhen(true)] out IExportCollection? exportCollection)
|
||||
@ -69,9 +67,9 @@ public class ScriptExporter : IAssetExporter
|
||||
{
|
||||
return GetExportType(script) switch
|
||||
{
|
||||
AssemblyExportType.Decompile => new(MonoScriptDecompiledFileID, ScriptHashing.CalculateScriptGuid(script), ExportType),
|
||||
AssemblyExportType.Skip => new(ScriptHashing.CalculateScriptFileID(script), ReferenceAssemblyDictionary[script.GetAssemblyNameFixed()], ExportType),
|
||||
_ => new(ScriptHashing.CalculateScriptFileID(script), ScriptHashing.CalculateAssemblyGuid(script), ExportType),
|
||||
AssemblyExportType.Decompile => new(MonoScriptDecompiledFileID, ScriptHashing.CalculateScriptGuid(script), AssetType.Meta),
|
||||
AssemblyExportType.Skip => new(ScriptHashing.CalculateScriptFileID(script), ReferenceAssemblyDictionary[script.GetAssemblyNameFixed()], AssetType.Meta),
|
||||
_ => new(ScriptHashing.CalculateScriptFileID(script), ScriptHashing.CalculateAssemblyGuid(script), AssetType.Meta),
|
||||
};
|
||||
}
|
||||
|
||||
@ -101,19 +99,11 @@ public class ScriptExporter : IAssetExporter
|
||||
}
|
||||
}
|
||||
|
||||
AssetType IAssetExporter.ToExportType(IUnityObjectBase asset) => ExportType;
|
||||
AssetType IAssetExporter.ToExportType(IUnityObjectBase asset) => AssetType.Meta;
|
||||
|
||||
bool IAssetExporter.ToUnknownExportType(Type type, out AssetType assetType)
|
||||
{
|
||||
assetType = ExportType;
|
||||
assetType = AssetType.Meta;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static AssetType GetAssetType(UnityVersion version)
|
||||
{
|
||||
// https://github.com/AssetRipper/AssetRipper/issues/1329
|
||||
return version.GreaterThanOrEquals(4)
|
||||
? AssetType.Meta
|
||||
: AssetType.Cached;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,5 +18,8 @@ public enum AssetType
|
||||
/// <summary>
|
||||
/// Binary asset file. It contains all parameters inside meta file
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// On Unity 3, this is only used for 3D models. Images and audio use <see cref="Cached"/> instead.
|
||||
/// </remarks>
|
||||
Meta = 3,
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user