I am using the AssetBundleManager
API in my unity 5.3 project.
My set-up: I have two scenes. One main scene and another scene that will be loaded as a multi scene into the main scene, which works fine in the editor right now. Now I wanted to built my main scene to my android device, but when I click on the load level button, nothing happens. I already made a built of my assetbundle which is placed in the AssetBundles
folder of my root. This is what I read in the documentations and what should be right?
What am I missing, do I need to put the assetbundle files anywhere else? I am using this script, which I got from the example of the AssetBundleManager
Plugin.
using UnityEngine;
using System.Collections;
using AssetBundles;
using UnityEngine.SceneManagement;
public class LoadScenes : MonoBehaviour
{
public string sceneAssetBundle;
public string sceneName;
public bool load;
public bool destroy;
string curLevel;
// Use this for initialization
IEnumerator Start ()
{
yield return StartCoroutine(Initialize() );
// Load level.
//yield return StartCoroutine(InitializeLevelAsync (sceneName, true) );
}
void Update(){
if (load) {
load = false;
// Load level.
StartCoroutine(InitializeLevelAsync (sceneName, true) );
}
if (destroy) {
destroy = false;
SceneManager.UnloadScene(sceneName);
}
}
public void loadLevel(string level){
curLevel = level;
StartCoroutine (InitializeLevelAsync (level, true));
}
public void unloadLevel(){
SceneManager.UnloadScene(curLevel);
}
// Initialize the downloading url and AssetBundleManifest object.
protected IEnumerator Initialize()
{
// Don't destroy this gameObject as we depend on it to run the loading script.
DontDestroyOnLoad(gameObject);
// With this code, when in-editor or using a development builds: Always use the AssetBundle Server
// (This is very dependent on the production workflow of the project.
// Another approach would be to make this configurable in the standalone player.)
#if DEVELOPMENT_BUILD || UNITY_EDITOR
AssetBundleManager.SetDevelopmentAssetBundleServer ();
#else
// Use the following code if AssetBundles are embedded in the project for example via StreamingAssets folder etc:
AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + "/");
// Or customize the URL based on your deployment or configuration
//AssetBundleManager.SetSourceAssetBundleURL("http://www.MyWebsite/MyAssetBundles");
#endif
// Initialize AssetBundleManifest which loads the AssetBundleManifest object.
var request = AssetBundleManager.Initialize();
if (request != null)
yield return StartCoroutine(request);
}
protected IEnumerator InitializeLevelAsync (string levelName, bool isAdditive)
{
// This is simply to get the elapsed time for this phase of AssetLoading.
float startTime = Time.realtimeSinceStartup;
// Load level from assetBundle.
AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, levelName, isAdditive);
if (request == null)
yield break;
yield return StartCoroutine(request);
// Calculate and display the elapsed time.
float elapsedTime = Time.realtimeSinceStartup - startTime;
Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds" );
}
}
Instead of using:
AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + "/");
Try using Application.persistentDataPath, hopefully that'll solve the problem. Link to the manual.
You will have to set the datapath to your folder where the assetbundle is, ie myassetbundle.unity3d
For example:-
AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + "file:////D:\\ptech-user\\Documents\\assetbundle3\\Assets\\Assets\\AssetBundle ");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.