- Home /
Editor Script: Get all assets in all AssetBundles
I'm doing an editor script, where I want to iterate over all assets in all assetbundles. My approach so far has been:
foreach( var assetBundleName in UnityEditor.AssetDatabase.GetAllAssetBundleNames() )
{
//GetAllAssetFromAssetBundle( assetBundleName ) <- doesn't exists as far as I know
}
But I'm stuck on getting an assetbundle by it's name. Is that possible?
Other approaches are also most welcome :-)
It should be said, that I'm using the AssetBundleManager in "Simulation Mode"... that's the factor, that complicates getting the assetbundles...
Answer by DustyScreen · May 10, 2016 at 12:58 PM
Okay - it was quite easy actually:
foreach( var assetBundleName in AssetDatabase.GetAllAssetBundleNames() )
{
foreach( var assetPathAndName in AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName) )
{
string nameWithoutPath = assetPathAndName.Substring( assetPathAndName.LastIndexOf( "/" ) + 1 );
string name = nameWithoutPath.Substring( 0, nameWithoutPath.LastIndexOf( "." ) );
Debug.Log( name );
}
}
Hello, just an alternative for the Substrings:
foreach( var assetBundleName in AssetDatabase.GetAllAssetBundleNames() )
{
foreach( var assetPathAndName in AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName) )
{
var name = Path.GetFileNameWithoutExtension(assetPathAndName );
Debug.Log( name );
}
}
Your answer
Follow this Question
Related Questions
Resource slicing to reduce iOS app size 1 Answer
Why does Unity fail to decompress my addressable assets when updating the bundles? 1 Answer
Unity does not recognise any assets. 0 Answers
How do you package/retrieve Asset Bundle Dependencies 0 Answers
Why my Assets not loaded twice from the asset Bundle? 1 Answer