作者lovecold (小豬頭)
看板GameDesign
標題[程式] 關於Unity的AssetBundle
時間Thu Jun 13 09:41:23 2013
各位前輩好,小弟弟我目前正在學著使用Unity的AssetBundle來做android的obb檔
但碰到一個小問題,希望各位前輩能指點指點....
我照著Unity提供的GooglePlayDownloader的說明來產生obb檔
1) Create one or many AssetBundles with the application data
(enough to get the .apk below the 50MB limit).
2) Concatenate the generated AssetBundles into a single .obb
by ZIP'ing them, using STORE (not DEFLATE).
$> zip -0 main.obb assetbundles
3) Continue to use WWW.LoadFromCacheOrDownload()
as with regular asset bundle loading, but use the path
to the .obb instead, like this:
WWW.LoadFromCacheOrDownload("jar:file://" +
obbPath +
"!/" + originalAssetBundleName);
在第二步驟時,我把三個assetbundle壓縮成一個main.obb檔,
這三個assetbundle分別是
RedCube.assetbundles,
GreenCube.assetBundles,
BuleCube.assetBundles
但在第三步驟時出現問題,
當我在Editor測試時,使用
string obbPath = "jar:file://"+
Application.dataPath +
"/../_AssetBunldes/main.obb!/RedCube.assetBundles";
WWW bundle = WWW.LoadFromCacheOrDownload(obbPath, 0);
Debug.Log(bundle.assetBundle);
會出現下方的錯誤
You are trying to load data from a www stream
which had the following error when downloading.
Resolving host timed out: jar:file:
UnityEngine.WWW:get_assetBundle()
<loadBundle>c__Iterator0:MoveNext() (at Assets/DownloadObbExample.cs:62)
當我在機器上測試時,我把路徑改成,
string mainPath = GooglePlayDownloader.GetMainOBBPath(expPath);
string obbPath = "jar:file://"+ mainPath + "!/RedCube.assetBundles";
WWW bundle = WWW.LoadFromCacheOrDownload(obbPath, 0);
Debug.Log(bundle.assetBundle);
這樣不會有錯誤訊息,但也不會秀出log
想請教一下,是我那裡做錯了嗎??
謝謝各位的幫忙!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.230.84.190
※ 編輯: lovecold 來自: 125.230.84.190 (06/13 09:45)
推 holymars:Editor認不得jar:這種uri 有錯是正常的 06/13 21:34
原來如此,感謝提醒
→ holymars:在機器上要是沒跑到Debug那行一定是有錯誤訊息你漏了才對 06/13 21:35
推 holymars:另外WWW class你要檢查isDone 才能拿東西吧 就算在local 06/13 21:37
→ holymars:端的檔案也一樣.. 06/13 21:37
原來是要加,因為之前測試時有加一樣沒有印出LOG,以為是卡死在迴圈內
所以把isDone拿掉了..感謝你的幫忙!!!^^
※ 編輯: lovecold 來自: 114.38.96.63 (06/13 23:45)