Set asset bundle name field in scene meta files

* Resolves #1709
This commit is contained in:
ds5678 2025-04-28 22:26:47 -07:00
parent 5ffc04cfa5
commit a47e7ea326
3 changed files with 29 additions and 1 deletions

View File

@ -49,6 +49,10 @@ namespace AssetRipper.Export.UnityProjects.Project
{ {
AssetExporter.Export(container, ExportableAssets, filePath, fileSystem); AssetExporter.Export(container, ExportableAssets, filePath, fileSystem);
IDefaultImporter sceneImporter = DefaultImporter.Create(container.File, container.ExportVersion); IDefaultImporter sceneImporter = DefaultImporter.Create(container.File, container.ExportVersion);
if (sceneImporter.Has_AssetBundleName_R() && Hierarchy.AssetBundleName is not null)
{
sceneImporter.AssetBundleName_R = Hierarchy.AssetBundleName;
}
Meta meta = new Meta(GUID, sceneImporter); Meta meta = new Meta(GUID, sceneImporter);
ExportMeta(container, meta, filePath, fileSystem); ExportMeta(container, meta, filePath, fileSystem);
return true; return true;

View File

@ -4,8 +4,10 @@ using AssetRipper.Import.Logging;
using AssetRipper.SourceGenerated; using AssetRipper.SourceGenerated;
using AssetRipper.SourceGenerated.Classes.ClassID_1; using AssetRipper.SourceGenerated.Classes.ClassID_1;
using AssetRipper.SourceGenerated.Classes.ClassID_1001; using AssetRipper.SourceGenerated.Classes.ClassID_1001;
using AssetRipper.SourceGenerated.Classes.ClassID_142;
using AssetRipper.SourceGenerated.Classes.ClassID_4; using AssetRipper.SourceGenerated.Classes.ClassID_4;
using AssetRipper.SourceGenerated.Extensions; using AssetRipper.SourceGenerated.Extensions;
using System.Diagnostics;
namespace AssetRipper.Processing.Prefabs; namespace AssetRipper.Processing.Prefabs;
@ -28,6 +30,21 @@ public sealed class PrefabProcessor : IAssetProcessor
ProcessedAssetCollection sceneCollection = GetOrCreateSceneCollection(gameData, processedBundle, sceneCollectionDictionary, scene); ProcessedAssetCollection sceneCollection = GetOrCreateSceneCollection(gameData, processedBundle, sceneCollectionDictionary, scene);
SceneHierarchyObject sceneHierarchy = SceneHierarchyObject.Create(sceneCollection, scene); SceneHierarchyObject sceneHierarchy = SceneHierarchyObject.Create(sceneCollection, scene);
gameObjectsAlreadyProcessed.AddRange(sceneHierarchy.GameObjects); gameObjectsAlreadyProcessed.AddRange(sceneHierarchy.GameObjects);
Bundle? bundle = scene.Collections.Select(c => c.Bundle).FirstOrDefault(b => b is SerializedBundle);
if (bundle is not null)
{
IAssetBundle? assetBundleAsset = bundle.FetchAssets().OfType<IAssetBundle>().FirstOrDefault();
if (assetBundleAsset is not null)
{
Debug.Assert(!assetBundleAsset.Has_IsStreamedSceneAssetBundle() || assetBundleAsset.IsStreamedSceneAssetBundle);
sceneHierarchy.AssetBundleName = assetBundleAsset.GetAssetBundleName();
}
else
{
sceneHierarchy.AssetBundleName = bundle.Name;
}
}
} }
//Create hierarchies for prefabs with an existing PrefabInstance //Create hierarchies for prefabs with an existing PrefabInstance

View File

@ -16,7 +16,14 @@ namespace AssetRipper.SourceGenerated.Extensions
public static string GetAssetBundleName(this IAssetBundle bundle) public static string GetAssetBundleName(this IAssetBundle bundle)
{ {
return bundle.Has_AssetBundleName_R() ? bundle.AssetBundleName_R : bundle.Collection.Bundle.Name; if (bundle.Has_AssetBundleName_R() && !bundle.AssetBundleName_R.IsEmpty)
{
return bundle.AssetBundleName_R;
}
else
{
return bundle.Collection.Bundle.Name;
}
} }
} }
} }