Hi All,
I have been using the plugin “Bundle Manager” by BAxe Games until recently after upgrading Unity to v5.3.2, I am exploring the Unity AssetBundle Manager and have downloaded and played with it along with the tutorial.
However, I can download the Tank and asset cube using the tutorial scripts, but when I copied it and made my own script, it worked ONCE, but now not anymore, and I have no idea what happened and what went wrong.
Below is my script:
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using AssetBundles;
public class DLCEngine : MonoBehaviour
{
public const string AssetBundlesOutputPath = “/AssetBundles/”;
public AssetBundleLoadAssetOperation request;
private string assetBundleName = “icon_chairs”;
private string assetName = “icon_chair_239_979_g_x”;
//InitializethedownloadingurlandAssetBundleManifestobject.
protected IEnumerator Initialize()
{
//Don’tdestroythisgameObjectaswedependonittoruntheloadingscript.
DontDestroyOnLoad(gameObject);
//Withthiscode,whenin-editororusingadevelopmentbuilds:AlwaysusetheAssetBundle Server
//(Thisisverydependentontheproductionworkflowoftheproject.
//Anotherapproachwouldbetomakethisconfigurableinthestandaloneplayer.)
#if DEVELOPMENT_BUILD || UNITY_EDITOR
AssetBundleManager.SetDevelopmentAssetBundleServer ();
#else
//UsethefollowingcodeifAssetBundlesareembeddedintheprojectforexampleviaStreamingAssetsfolderetc:
AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + “/”);
//OrcustomizetheURLbasedonyourdeploymentor configuration
//AssetBundleManager.SetSourceAssetBundleURL(“http://homey-cms.cloudapp.net/test/DLC/vRay”);
#endif
//InitializeAssetBundleManifestwhichloadstheAssetBundleManifestobject.
var request = AssetBundleManager.Initialize();
if (request != null)
yield return StartCoroutine(request);
}
protected IEnumerator DownloadBundleDLC (string _bundle_name, string _asset_name, Action _action = null) where T : UnityEngine.Object
{
Debug.Log (“DLCEngine.InstantiateGameObjectAsync”);
//ThisissimplytogettheelapsedtimeforthisphaseofAssetLoading.
float _startTime = Time.realtimeSinceStartup;
//LoadassetfromassetBundle.
request = AssetBundleManager.LoadAssetAsync(_bundle_name, _asset_name, typeof(T) );
if (request == null)
yield break;
while(!request.IsDone())
yield return StartCoroutine(request);
//Gettheasset.
T _prefab = request.GetAsset ();
//Calculateanddisplaytheelapsedtime.
float _elapsedTime = Time.realtimeSinceStartup - _startTime;
Debug.Log(_asset_name + (_prefab == null ? “wasnot” : “was”)+ “loadedsuccessfullyin” + _elapsedTime + “seconds” );
if (_prefab != null) {
Debug.Log (“AssetDownloadOK”);
_action ();
} else
Debug.Log (“AssetDownloadFAIL”);
}
public IEnumerator LoadDLC(string _bundle_name, string _asset_name, Action _action = null) where T : UnityEngine.Object
{
Debug.Log (“DLCEngine.LoadDLC”);
yield return StartCoroutine(Initialize() );
//Loadasset.
yield return StartCoroutine(DownloadBundleDLC(_bundle_name, _asset_name, _action) );
}
}
I am calling the LoadDLC<T>
from other scripts, but when it reaches the line if (_prefab != null)
, it seems the prefab cannot be retrieved and I keep getting “AssetDownloadFAIL” in log; but there is no other error being displayed, so I really don’t have a clue what’s wrong.
Thanks in advance for helping me here!