Unity Assetbundle场景卸载

时间:2018-10-10 11:22:29

标签: unity3d vuforia assetbundle

我为我的项目创建了几个Assetbundle场景。现在,我正在下载资产捆绑包并能够加载场景。这里的问题是,当我运行一个场景并退出该场景并尝试再次重新加载同一场景时,它给出了类似

的错误
  

“无法加载Assetbundle mywebsite.com/bundles/assetbundle.unity3d,因为已经加载了另一个具有相同文件的AssetBundle。

我无法第二次打开场景。谁能说出问题并帮助我解决?预先感谢。

我在此处添加代码:

IEnumerator sceneLoad()
{

    WWW www = WWW.LoadFromCacheOrDownload(myurl,version); 

    while (!www.isDone) 
    {

        msg.text = "Downloading...";

        float progress = Mathf.Clamp01 (www.progress / .9f);

        progressslide.value = progress;

        float val = progress * 100f;

        double value = System.Math.Round (val, 2);

        progresstext.text = value + "%";

        Debug.Log ("Progress " + progresstext.text);

        yield return null;

    }

    bundle = www.assetBundle;

    msg.text = "Opening Scene...";

    progressslide.gameObject.SetActive (false);

    progresstext.gameObject.SetActive (false);

    string[] scenepath = bundle.GetAllScenePaths ();

    Debug.Log (scenepath [0]);

    var async = SceneManager.LoadSceneAsync(System.IO.Path.GetFileNameWithoutExtension (scenepath [0])); 

    yield return null;

    bundle.Unload (false);  
}

以上代码在我的PC上的统一引擎上运行正常,但是当我构建apk并在手机上运行时,进度栏无法正常工作,但捆绑包正在下载,场景正在打开。稍后当我退出场景时,进入我的应用程序主页并再次打开同一场景,它显示为

  

“无法加载Assetbundle mywebsite.com/bundles/assetbundle.unity3d,因为已经加载了另一个具有相同文件的AssetBundle。”

我正在下载的场景中使用Vuforia。

1 个答案:

答案 0 :(得分:0)

退出场景时,您应该unload加载资产束。

也许您会找到合适的asset bundle guide

相关问题