Finally, I solved the problem by changing the direction of the file. You need to add “file: ///” at the beginning of the address when we want to access a local file using the WWW object.
To create the AssetBundle I used the system for Unity 4. The new system for Unity 5, I have not finished understand when you create a AssetBundle.
The code for Unity 4 to create a AssetBundle are here. I used this Editor class:
// C# Example
// Builds an asset bundle from the selected objects in the project view.
// Once compiled go to "Menu" -> "Assets" and select one of the choices
// to build the Asset Bundle
using UnityEngine;
using UnityEditor;
public class ExportAssetBundles {
[MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]
static void ExportResource () {
// Bring up save panel
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0) {
// Build the resource file from the active selection.
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, 0);
Selection.objects = selection;
}
}
[MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")]
static void ExportResourceNoTrack () {
// Bring up save panel
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0) {
// Build the resource file from the active selection.
BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path);
}
}
}
Although generates the message: Assets/Editor/ExportAssetBundles.cs(17,39): warning CS0618: UnityEditor.BuildPipeline.BuildAssetBundle(UnityEngine.Object, UnityEngine.Object[ ], string, UnityEditor.BuildAssetBundleOptions)' is obsolete:
BuildAssetBundle has been made obsolete. Please use the new AssetBundle build system introduced in 5.0 and check BuildAssetBundles documentation for details.’
It works. Select one or more assets, or a folder, you click with the right mouse button and select “Build AssetBundle From Selection - Track Dependencies”, this will create a bundle asset with assets included all subfolders.
This would be the code to load the AssetBundle:
using UnityEngine;
using System.Collections;
public class LoadAssetBundle : MonoBehaviour {
public IEnumerator LoadBundle(){
using(WWW www = WWW.LoadFromCacheOrDownload("file:///" + Application.dataPath + "/Languages/English.unity3d",0)) {
yield return www;
AssetBundle assetBundle = www.assetBundle;
Object[] objects = assetBundle.LoadAllAssets();
// Do stuff with objects
assetBundle.Unload(false);
}
}
void Start(){
StartCoroutine(LoadBundle());
}
}
2094884–137096–LoadSaveAssetBundle(Unity 4 system)(SOLVED).unitypackage (28.8 KB)