2015-11-03 65 views
1

我在两者之间切换的两个场景来自此代码使用的资产包。代码在编辑器中工作,但不在构建中。我错过了什么?无法从独立资产包加载场景

public IEnumerator LoadSceneBundle(string assetBundleSceneName, string orignialName) { 

     //url = "file://" + Application.dataPath + "/AssetBundles/" + assetBundleSceneName + ".unity3d"; 
     Debug.Log(Application.dataPath); 
     //this code for build 
     newExtractedPath = Application.dataPath; 
     //this code for runtime 
     //newExtractedPath = Application.dataPath.Substring(0, Application.dataPath.Length - 7); 
     Debug.Log(newExtractedPath +" :: newExtractedPath"); 
     //url = "file://" + Application.dataPath + "/AssetBundles/" + assetBundleSceneName + ".unity3d"; 
     url = "file://" + newExtractedPath + "/AssetBundles/" + assetBundleSceneName + ".unity3d"; 
     Debug.Log("scene load url : " + url); 
     using (WWW www = WWW.LoadFromCacheOrDownload(url,1)){ 
      yield return www; 
      if (www.error != null) { 
       throw new Exception("WWW download had an error : " + url + " " + www.error); 
       //Debug.Log(""); 
      } 

      AssetBundle ab = www.assetBundle; 
      Debug.Log(www.assetBundle.mainAsset); 

      ab.LoadAll(); 
      Application.LoadLevel(originalName); 
      ab.Unload(false); 
     } 
    } 

部署后,我做了一个AssetsBundle文件夹,并放置我的assetbundle场景文件,但它不起作用。一切都是徒劳的。

回答

1

你的路径似乎是错误的。如果您将资产包嵌入到游戏中,则应将它们置于StreamingAssets文件夹下,以便它们在游戏构建中结束。据the documentation

放置在一个文件夹,名为StreamingAssets在统一项目的任何文件都会被逐字复制到目标计算机上的特定文件夹。

这样做,并使用Application.streamingAssetsPath形成你的路,你应该能够使用WWW.LoadFromCacheOrDownload得到它们。

+0

因此,标准的方式是将assetbundle放入streamingAsset文件夹中,并且该文件夹将在我们独立构建时自动部署?对? –

+0

是的。在_Assets_文件夹('Assets/StreamingAssets /') – Roberto

+0

+中创建文件夹感谢这个有价值的信息,但这不是问题! –