| Parameter | Description |
|---|---|
| assetPackNames | The array of names of Android asset packs to download. |
DownloadAssetPackAsyncOperation Returns an object that represents the download operation. If you yield this object inside a coroutine, the coroutine pauses until the operation is complete.
Downloads Android asset packs.
This method directly wraps Google's PlayCore plugin API. If the PlayCore plugin is missing, calling this method throws an InvalidOperationException exception. Additional resources: DownloadAssetPackAsyncOperation, AndroidAssetPackInfo, AndroidAssetPacks.CancelAssetPackDownload, AndroidAssetPacks.GetAssetPackPath, AndroidAssetPacks.GetAssetPackStateAsync, AndroidAssetPacks.RemoveAssetPack, AndroidAssetPacks.RequestToUseMobileDataAsync.
using System.Collections; using UnityEngine; using UnityEngine.Android;
public class DownloadAssetPackAsyncExample : MonoBehaviour { IEnumerator Start() { var assetPackNames = new string[] { "MyAssetPack" };
var downloadOperation = AndroidAssetPacks.DownloadAssetPackAsync(assetPackNames);
// Yield until the download completes. yield return downloadOperation;
if (downloadOperation.downloadedAssetPacks.Length == 0) { Debug.LogWarning("No asset packs were downloaded."); }
foreach (var packName in downloadOperation.downloadedAssetPacks) { var path = AndroidAssetPacks.GetAssetPackPath(packName); Debug.Log($"Asset pack downloaded to: {path}"); }
foreach (var failedPack in downloadOperation.downloadFailedAssetPacks) { Debug.LogError($"Failed to download asset pack: {failedPack}"); } } }
| Parameter | Description |
|---|---|
| assetPackNames | The array of names of Android asset packs to download. |
| callback | The callback method to inform about download progress. It gets called multiple times for each asset pack during its download. The callback method must have a parameter of AndroidAssetPackInfo type. The default value is null. |
Downloads Android asset packs.
This method directly wraps Google's PlayCore plugin API. If the PlayCore plugin is missing, calling this method throws an InvalidOperationException exception. Additional resources: AndroidAssetPackInfo, AndroidAssetPacks.CancelAssetPackDownload, AndroidAssetPacks.GetAssetPackPath, AndroidAssetPacks.GetAssetPackStateAsync, AndroidAssetPacks.RemoveAssetPack, AndroidAssetPacks.RequestToUseMobileDataAsync.
using UnityEngine; using UnityEngine.Android;
public class DownloadAssetPackCallbackExample : MonoBehaviour { bool isShowingDialog = false;
void Start() { AndroidAssetPacks.DownloadAssetPackAsync( new string[] { "MyAssetPack" }, OnDownloadProgress ); }
void OnDownloadProgress(AndroidAssetPackInfo info) { switch (info.status) { case AndroidAssetPackStatus.Pending: Debug.Log($"{info.name}: Pending"); break; case AndroidAssetPackStatus.Downloading: float percentComplete = info.size > 0 ? (float)info.bytesDownloaded / info.size * 100f : 0f; Debug.Log($"{info.name}: Downloading {percentComplete:F1}%"); break; case AndroidAssetPackStatus.Transferring: Debug.Log($"{info.name}: Transferring {(info.transferProgress * 100f):F1}%"); break; case AndroidAssetPackStatus.Completed: var path = AndroidAssetPacks.GetAssetPackPath(info.name); Debug.Log($"{info.name}: Completed. Path: {path}"); break; case AndroidAssetPackStatus.Failed: Debug.LogError($"{info.name}: Failed with error {info.error}"); break; case AndroidAssetPackStatus.WaitingForWifi: case AndroidAssetPackStatus.RequiresUserConfirmation: if (!isShowingDialog) { isShowingDialog = true; Debug.Log(info.status == AndroidAssetPackStatus.WaitingForWifi ? $"{info.name}: Download paused until connected to Wi-Fi." : $"{info.name}: Download requires user confirmation."); AndroidAssetPacks.ShowConfirmationDialogAsync(result => { isShowingDialog = false; Debug.Log(result.consentGiven ? "User gave consent. Downloads will resume." : "User denied consent."); }); } break; case AndroidAssetPackStatus.Canceled: Debug.Log($"{info.name}: Download canceled."); break; case AndroidAssetPackStatus.NotInstalled: Debug.Log($"{info.name}: Android asset pack is not installed"); break; default: Debug.Log($"{info.name}: Status {info.status}"); break; } } }