I'm relatively new to programming in unity and I had never used assetbundles before. I'm using the example project which everyone can download from the unity website and adapting it to my needs, I already know how to use the load scenes function, which is what I'll need, but the load scenes script that I'm currently using doesn't downloads the asset bundles, but loads it from somewhere already in the computer. I'm working on an Android/IOS aplication, our objective is to create a simple menu scene and then DOWNLOAD the asset bundles from a server and load the scenes. All data needs to be stored at the phone once the user downloads it. I tried everything but I can't make it work, even the code at the unity documentation doesn't seems to work for me. Please, if anyone could help me, here's the code for the LoadScenes script. The only modification I've made on the original code that comes with the asset bundle manager of unity is that the name of the bundle, and the name of the scene is passed by a button. This script currently loads the bundles from a folder in the computer, which is not what I need, I need the bundles to be downloaded from a server AND THEN loaded from a folder in the device. Thanks!
using UnityEngine;
using System.Collections;
using AssetBundles;
using UnityEngine.UI;
public class LoadScenes : MonoBehaviour{
public string sceneAssetBundle;
public string sceneName;
public string sName;
public string bName;
// Use this for initialization
IEnumerator Start ()
{
yield return StartCoroutine(Initialize() );
// Load level.
yield return StartCoroutine(InitializeLevelAsync (sceneName, true) );
}
public void getScene(string sName){
sceneName = sName;
}
public void getBundle(string bName){
sceneAssetBundle = bName;
}
// Initialize the downloading url and AssetBundleManifest object.
public 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);
}
public 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" );
}
}