2015-11-03 64 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

+中創建文件夾感謝這個有價值的信息,但這不是問題! –