我將場景保存至Assets檔案夾下,命名為“ABTest”,將其AssetBundle如圖更改:

用
BuildPipeline.BuildAssetBundles ("Assets/StreamingAssets", BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
函式進行打包。
打包完成后會在StreamingAssets檔案夾下出現四個檔案。
然后加載:
public string sceneAssetBundle = "test.assetbundle";
public string sceneName = "ABTest";
IEnumerator Start(){
string path = "file://" + Application.dataPath + "/StreamingAssets/" + sceneAssetBundle;
WWW www = www.LoadFromCacheOrDownload (path, 0);
yield return www;
if (www.error != null) {
AssetBundle ab = www.assetBundle;
AsyncOperation async = SceneManager.LoadSceneAsync (sceneName);
yield return async;
} else {
Debug.Log (www.error);
}
}
控制臺顯示NULL。意思是在包里沒有找到打包的場景檔案?為什么?我應如何解決?
然后,我用
BuildPipeline.BuildPlayer()
對場景進行打包。按照官方腳本API上的范例那樣。然后出錯,錯誤是
Source file `Assets/Scene_Data/Managed/Assembly-CSharp.dll' is a binary file and not a text file
官方腳本API也提示了腳本會產生有問題,但我看不懂。。。
這條路也死了。
我怕應該如何打包并加載場景呢?
謝謝幫助!
uj5u.com熱心網友回復:
打包自己百度吧使用的話 Resource.Load 還有一個方法,然后實體化一個,別忘了釋放
uj5u.com熱心網友回復:
Resource.Load能獲取Assetbundle的包嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/64397.html
標籤:Unity3D
