我遇到了同样的问题,统一抛出以下错误:
无法加载缓存的 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
已经成功了。