首页 文章

Unity assetbundle场景卸载

提问于
浏览
0

我为我的项目创建了几个assetbundle场景 . 现在我正在下载assetsbundles并能够加载场景 . 这里的问题是,当我运行一个场景并从中退出并尝试再次重新加载同一场景时,它会给出一个像

“无法加载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);  
}

上面的代码完全适用于我的电脑中的统一引擎,但是当我构建apk并在手机上运行时,进度条不起作用但是捆绑正在下载并且场景正在打开 . 稍后当我退出场景时,进入我的应用程序主页并再次打开相同的场景,它显示错误为

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

我在下载的场景中使用Vuforia .

1 回答

  • 0

    退出场景时,您应该unload加载资产包 .

    也许你会发现这个正确asset bundle guide .

相关问题