我将场景保存至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也提示了脚本会产生有问题,但我看不懂。。。
这条路也死了。
我怕应该如何打包并加载场景呢?
谢谢帮助!