In the following Unity Package, I attempt to load an Asset Bundle that contains a fairly complex particle system.
The asset bundle is loaded via www.
m_www =
new WWW(m_assetBundleURL);
assetBundle.LoadAll() loads all the Objects[ ] from the asset bundle.
I then iterate through each Object and attempts to save the asset to file with AssetDatabase.CreateAsset(obj, assetPath).
I get a bunch of errors like:
Couldn't create asset file because the Texture2D 'Fire 1' is already an asset at ''!
Couldn't create asset file because the MonoScript 'FractalTexture' is already an asset at ''!
Is there another way to do this?
To try this 3k package, simple import to an empty project. And then using the Unity Editor to access the menu item: “Assets/Save Asset Bundle As Assets”.
Yey! I got the material to save out of the asset bundle to a file by creating a simple Material and copying the serialized data into the simple Material.
I added logic to fix references to custom shaders and textures.
There are going to be some types that I can’t extract because Unity crashes:
MonoScript - cs or js files, the text and bytes fields are blank
ParticleEmitter - Any attempt to copy the particle emitters cause memory corruption and unity crashes
Shaders - Shaders lack a constructor and cannot be copied directly. Instead I can extract shaders from any material that uses the shader.
Prefabs - Prefabs don't appear to be in the asset bundle
I thought maybe if I exported a script as the main asset, the text in the MonoScript might be filled in.
@MenuItem("Assets/Build AssetBundle From Script")
static function ExportResourceScript () {
// Bring up save panel
var path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0)
{
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/UpdateGUITextScript.cs"), null, path);
}
}
In the script above I was trying to explicitly get a full copy of a script into the asset bundle. Unfortunately, as I found in another thread http://forum.unity3d.com/viewtopic.php?p=145095#145095, asset bundles only include script references. Still I had the source script in my project and the MonoScript.text property was still empty.