2

我在下载资产包时遇到问题。

我得到错误:

The asset bundle 'url/levelpackIphone-Copy.unity3d' can't be loaded because
another asset bundle with the same files are already loaded

我需要检查资产包是否已经下载。我的问题是我不能只存储 URL,因为您下载的文件可以有不同的名称,但仍然包含相同的内容。

因此,我需要以某种方式检查资产包是否已经下载。我真的不喜欢使用类似的东西

bundle.Unload(false);
4

1 回答 1

2

我遇到了同样的问题,统一抛出以下错误:

无法加载缓存的 AssetBundle。已从另一个 AssetBundle 加载了同名文件

我在关卡的不同阶段加载资产包,但是当我尝试重新启动关卡并尝试再次加载资产包时,我遇到了上述相同的错误。然后我尝试将资产包保存在列表中并尝试在级别重新启动时清除列表,但这并没有解决问题。我什至试图Caching.CleanCache()从内存中删除任何数据但没有用。在下载并在关卡加载后再次从磁盘加载它们之后,我将资产包保存在磁盘上。

解决方案:

private IEnumerator LoadAssetFromFile(string _name) 
{ 
    print("Came inside LoadAssetFromFile :" + _name); 
    WWW www= new WWW(string.Concat("file:///", Application.dataPath, "/", _name +".unity3d"));//(m_savePath + _name); 
    //WWW www= new WWW(string.Concat(Application.dataPath, "/", _name));//(m_savePath + _name);

    yield return www;

    if(www.error == null)
    {
        //m_bundle =  www.assetBundle;
        AssetBundle bundle =  www.assetBundle;
        www.Dispose();
        www = null;
        string path = m_savePath + _name;
        //object [] obj = m_bundle.LoadAll();
        //for(int i=0; i< obj.Length; i++)
        //{
            //print ("Obj :"+ i +" " + obj[i].ToString());
        //}
        bundle.LoadAll();
        print ("AssetBundle is :" + bundle.mainAsset);
        print("============> " + path);
        GameObject _go =  (GameObject)Instantiate(bundle.mainAsset);
        bundle.Unload(false);
    }
    else
    {
        return false;
    }   
}

bundle.Unload(false)在实例化之后使用gameObject已经成功了。

于 2014-05-22T06:58:04.967 回答