我要在这两个场景之间切换的两个场景都来自此代码使用的资源包。代码在编辑器中工作,但在构建中不起作用。我错过了什么?
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文件夹,并放置了我的资源包场景文件,但它不起作用。这一切都是徒劳的。
发布于 2015-12-02 13:14:53
你的道路似乎是错的。如果您要将资源包嵌入到游戏中,则应将它们放在StreamingAssets文件夹下,以便它们最终会出现在游戏构建中。根据the documentation的说法
项目中名为StreamingAssets的文件夹中的任何文件都将被逐字复制到目标计算机上的特定文件夹中。
因此,这样做并使用Application.streamingAssetsPath来形成您的路径,您应该能够使用WWW.LoadFromCacheOrDownload来获取它们。
发布于 2015-12-02 12:07:50
如果你想为一个独立的Unity应用加载一个资源包,我认为你最好使用AssetBundle.CreateFromFile() -它更简单更快。唯一的问题是资产包不能被压缩。
http://docs.unity3d.com/ScriptReference/AssetBundle.CreateFromFile.html
https://stackoverflow.com/questions/33493372
复制相似问题