這些部分適用于**「fast-follow」和「on-demand」**資產包。
檢查狀態(tài)
每個資產包都存儲在應用程序內部存儲的單獨文件夾中。使用該 「isDownloaded()」 方法確定是否已下載資產包。
監(jiān)控下載
查詢PlayAssetBundleRequest 監(jiān)控請求狀態(tài)的 對象:
//?Download?progress?of?request,?between?0.0f?and?1.0f.?The?value?will?always?be
//?1.0?for?assets?delivered?as?install-time.
//?NOTE:?A?value?of?1.0?will?only?signify?the?download?is?complete.?It?will?still?need?to?be?loaded.
float?progress?=?bundleRequest.DownloadProgress;
//?Returns?true?if:
//???*?it?had?either?completed?the?download,?installing,?and?loading?of?the?AssetBundle,
//???*?OR?if?it?has?encountered?an?error.
bool?done?=?bundleRequest.IsDone;
//?Returns?status?of?retrieval?request.
AssetDeliveryStatus?status?=?bundleRequest.Status;
switch(status)?{
case?AssetDeliveryStatus.Pending:
//?Asset?pack?download?is?pending?-?N/A?for?install-time?assets.
case?AssetDeliveryStatus.Retrieving:
//?Asset?pack?is?being?downloaded?and?transferred?to?app?storage.
//?N/A?for?install-time?assets.
case?AssetDeliveryStatus.Available:
//?Asset?pack?is?downloaded?on?disk?but?NOT?loaded?into?memory.
//?For?PlayAssetPackRequest(),?this?indicates?that?the?request?is?complete.
case?AssetDeliveryStatus.Loading:
//?Asset?pack?is?being?loaded.
case?AssetDeliveryStatus.Loaded:
//?Asset?pack?has?finished?loading,?assets?can?now?be?loaded.
//?For?PlayAssetBundleRequest(),?this?indicates?that?the?request?is?complete.
case?AssetDeliveryStatus.Failed:
//?Asset?pack?retrieval?has?failed.
case?AssetDeliveryStatus.WaitingForWifi:
//?Asset?pack?retrieval?paused?until?either?the?device?connects?via?Wi-Fi,
//?or?the?user?accepts?the?PlayAssetDelivery.ShowCellularDataConfirmation?dialog.
default:
break;
}
大量下載
大于 150MB 的資產包可以自動下載,但只能通過 Wi-Fi 下載。如果用戶未連接到 Wi-Fi,則PlayAssetBundleRequest狀態(tài)設置為 AssetDeliveryStatus.WaitingForWifi 并暫停下載。在這種情況下,要么等待設備連接到 Wi-Fi,然后繼續(xù)下載,要么提示用戶批準通過蜂窩連接下載包。
if(bundleRequest.Status?==?AssetDeliveryStatus.WaitingForWifi)?{
var?userConfirmationOperation?=?PlayAssetDelivery.ShowCellularDataConfirmation();
yield?return?userConfirmationOperation;
switch(userConfirmationOperation.GetResult())?{
case?ConfirmationDialogResult.Unknown:
//?userConfirmationOperation?finished?with?an?error.?Something?went
//?wrong?when?displaying?the?prompt?to?the?user,?and?they?weren’t
//?able?to?interact?with?the?dialog.?In?this?case,?we?recommend
//?developers?wait?for?Wi-Fi?before?attempting?to?download?again.
//?You?can?get?more?info?by?calling?GetError()?on?the?operation.
case?ConfirmationDialogResult.Accepted:
//?User?accepted?the?confirmation?dialog?-?download?will?start
//?automatically?(no?action?needed).
case?ConfirmationDialogResult.Declined:
//?User?canceled?or?declined?the?dialog.?Await?Wi-Fi?connection,?or
//?re-prompt?the?user.
default:
break;
}
}
取消請求(僅限按需)
如果需要在 AssetBundles 加載到內存之前取消請求,請調用 對象AttemptCancel() 上的方法 PlayAssetBundleRequest:
//?Will?only?attempt?if?the?status?is?Pending,?Retrieving,?or?Available?-?otherwise
//?it?will?be?a?no-op.
bundleRequest.AttemptCancel();
//?Check?to?see?if?the?request?was?successful?by?checking?if?the?error?code?is?Canceled.
if(bundleRequest.Error?==?AssetDeliveryErrorCode.Canceled)?{
//?Request?was?successfully?canceled.
}
異步請求資產包
在大多數(shù)情況下,你應該使用 Coroutines異步請求資產包并監(jiān)控進度,如下所示:
private?IEnumerator?LoadAssetBundleCoroutine(string?assetBundleName)?{
PlayAssetBundleRequest?bundleRequest?=
PlayAssetDelivery.RetrieveAssetBundleAsync(assetBundleName);
while?(!bundleRequest.IsDone)?{
if(bundleRequest.Status?==?AssetDeliveryStatus.WaitingForWifi)?{
var?userConfirmationOperation?=?PlayAssetDelivery.ShowCellularDataConfirmation();
//?Wait?for?confirmation?dialog?action.
yield?return?userConfirmationOperation;
if((userConfirmationOperation.Error?!=?AssetDeliveryErrorCode.NoError)?||
(userConfirmationOperation.GetResult()?!=?ConfirmationDialogResult.Accepted))?{
//?The?user?did?not?accept?the?confirmation?-?handle?as?needed.
}
//?Wait?for?Wi-Fi?connection?OR?confirmation?dialog?acceptance?before?moving?on.
yield?return?new?WaitUntil(()?=>?bundleRequest.Status?!=?AssetDeliveryStatus.WaitingForWifi);
}
//?Use?bundleRequest.DownloadProgress?to?track?download?progress.
//?Use?bundleRequest.Status?to?track?the?status?of?request.
yield?return?null;
}
if?(bundleRequest.Error?!=?AssetDeliveryErrorCode.NoError)?{
//?There?was?an?error?retrieving?the?bundle.?For?error?codes?NetworkError
//?and?InsufficientStorage,?you?may?prompt?the?user?to?check?their
//?connection?settings?or?check?their?storage?space,?respectively,?then
//?try?again.
yield?return?null;
}
//?Request?was?successful.?Retrieve?AssetBundle?from?request.AssetBundle.
AssetBundle?assetBundle?=?bundleRequest.AssetBundle;
其他 Play Core API 方法
以下是你可能希望在應用中使用的一些其他 API 方法。
檢查下載大小
通過對 Google Play 進行異步調用并設置操作完成時的回調方法來檢查 AssetBundle 的大小:
public?IEnumerator?GetDownloadSize()?{
PlayAsyncOperation?getSizeOperation?=
PlayAssetDelivery.GetDownloadSize(assetPackName);
yield?return?getSizeOperation;
if(operation.Error?!=?AssetDeliveryErrorCode.NoError)?{
//?Error?while?retrieving?download?size.
}?else?{
//?Download?size?is?given?in?bytes.
long?downloadSize?=?operation.GetResult();
}
}
移除 AssetBundles
你可以刪除當前未加載到內存中的快速關注和按需 AssetBundle。進行以下異步調用并設置完成時的回調方法:
PlayAsyncOperation?removeOperation?=?PlayAssetDelivery.RemoveAssetPack(assetBundleName);
removeOperation.Completed?+=?(operation)?=>
{
if(operation.Error?!=?AssetDeliveryErrorCode.NoError)?{
//?Error?while?attempting?to?remove?AssetBundles.
}?else?{
//?Files?were?deleted?OR?files?did?not?exist?to?begin?with.
}
};
測試
==
在 Unity Editor 中,選擇Google > Build and Run。
行為
–
「install-time」 包將在應用程序安裝過程中安裝。
**「fast-follow」包的行為與「on-demand」**包一樣。也就是說,當游戲被側載時它們不會被自動獲取。開發(fā)者需要在游戲開始時手動請求;這不需要你的應用程序中的任何代碼更改。
限制
–
以下是本地測試的限制:
-
Packs 從外部存儲而不是 Play 中獲取,因此您無法測試您的代碼在出現(xiàn)網絡錯誤的情況下的行為。
-
本地測試不包括等待 Wi-Fi 場景。
-
不支持更新。在安裝新版本的構建之前,請手動卸載以前的版本。
使用內部應用共享進行測試
當你接近發(fā)布候選版本時,請使用盡可能真實的配置來測試你的游戲,以確保你的游戲在生產環(huán)境中為您的用戶提供良好的性能。 構建您的應用程序包。
自我介紹一下,小編13年上海交大畢業(yè),曾經在小公司待過,也去過華為、OPPO等大廠,18年進入阿里一直到現(xiàn)在。
深知大多數(shù)初中級安卓工程師,想要提升技能,往往是自己摸索成長,但自己不成體系的自學效果低效又漫長,而且極易碰到天花板技術停滯不前!
因此收集整理了一份《2024年最新Android移動開發(fā)全套學習資料》送給大家,初衷也很簡單,就是希望能夠幫助到想自學提升又不知道該從何學起的朋友,同時減輕大家的負擔。
由于文件比較大,這里只是將部分目錄截圖出來,每個節(jié)點里面都包含大廠面經、學習筆記、源碼講義、實戰(zhàn)項目、講解視頻
如果你覺得這些內容對你有幫助,可以添加下面V無償領?。。▊渥ndroid)
最后:學習總結——Android框架體系架構知識腦圖(純手繪xmind文檔)
學完之后,若是想驗收效果如何,其實最好的方法就是可自己去總結一下。比如我就會在學習完一個東西之后自己去手繪一份xmind文件的知識梳理大綱腦圖,這樣也可方便后續(xù)的復習,且都是自己的理解,相信隨便瞟幾眼就能迅速過完整個知識,腦補回來。
下方即為我手繪的Android框架體系架構知識腦圖,由于是xmind文件,不好上傳,所以小編將其以圖片形式導出來傳在此處,細節(jié)方面不是特別清晰。但可給感興趣的朋友提供完整的Android框架體系架構知識腦圖原件(包括上方的面試解析xmind文檔)
除此之外,前文所提及的Alibaba珍藏版 Android框架體系架構 手寫文檔以及一本 《大話數(shù)據(jù)結構》 書籍等等相關的學習筆記文檔,也皆可分享給認可的朋友!文章來源:http://www.zghlxwxcb.cn/news/detail-851004.html
——感謝大家伙的認可支持,F(xiàn)ree Download請注意:點贊+點贊+點贊!!!
——Android框架體系架構知識腦圖(純手繪xmind文檔)
學完之后,若是想驗收效果如何,其實最好的方法就是可自己去總結一下。比如我就會在學習完一個東西之后自己去手繪一份xmind文件的知識梳理大綱腦圖,這樣也可方便后續(xù)的復習,且都是自己的理解,相信隨便瞟幾眼就能迅速過完整個知識,腦補回來。
下方即為我手繪的Android框架體系架構知識腦圖,由于是xmind文件,不好上傳,所以小編將其以圖片形式導出來傳在此處,細節(jié)方面不是特別清晰。但可給感興趣的朋友提供完整的Android框架體系架構知識腦圖原件(包括上方的面試解析xmind文檔)
[外鏈圖片轉存中…(img-dkAuljdF-1710766894227)]
除此之外,前文所提及的Alibaba珍藏版 Android框架體系架構 手寫文檔以及一本 《大話數(shù)據(jù)結構》 書籍等等相關的學習筆記文檔,也皆可分享給認可的朋友!
——感謝大家伙的認可支持,F(xiàn)ree Download請注意:點贊+點贊+點贊?。?!
自行下載領取鏈接:【Git】文章來源地址http://www.zghlxwxcb.cn/news/detail-851004.html
到了這里,關于Android 打包AAB+PAD(Unity篇),Android開發(fā)基礎面試題的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!