【问题标题】:Unity assetbundle scene unloadunity assetsbundle 场景卸载
【发布时间】:2018-10-11 14:15:27
【问题描述】:

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

的错误

“无法加载 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。

【问题讨论】:

  • 下次请自行格式化代码

标签: unity3d vuforia assetbundle


【解决方案1】:

您应该在退出场景时unload 加载的资产包。

也许你会找到这个合适的asset bundle guide

【讨论】:

  • 感谢您的回复。我试过 unload(false) 但没有运气
  • 提供一些代码并检查此support.unity3d.com/hc/en-us/articles/…
  • @gowthy 您是否阅读了此答案中提供的手册?在After loading prefab again 部分中,它说For most projects, this behavior is undesirable. Most projects should use AssetBundle.Unload(true) and adopt a method to ensure that Objects are not duplicated. 你尝试过吗?
  • @derHugo 我没试过这个。将尝试这样做,同时我添加了上面的代码。请检查并让我知道是否有任何更改或建议
  • 我通过像 SceneManager.LoadSceneAsync("scene name") 而不是 System.IO.... 直接写场景名称来解决它,并在下面的行中产生 return async。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多