Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetAssetPackStateAsync

Queries the state of Android asset packs.
Read time 2 minutesLast updated 13 days ago

Definition

GetAssetPackStateAsync(string[], Action<ulong, AndroidAssetPackState[]>)

Queries the state of Android asset packs.
public static void GetAssetPackStateAsync(string[] assetPackNames, Action<ulong, AndroidAssetPackState[]> callback)

Parameters

assetPackNames

The array of names of the Android asset packs to query the state of.

The callback method to get the result. Unity raises this callback once when the query is complete and the callback receives the state of queried Android asset packs. The callback method must have two parameters:
  • A ulong type parameter which indicates the total size of the queried asset packs.
  • An array of AndroidAssetPackState which contains the state of each queried asset pack.

Remarks

This method directly wraps Google's PlayCore plug-in API. If the PlayCore plug-in is missing, calling this method throws an
InvalidOperationException
.

Examples

using UnityEngine;using UnityEngine.Android;public class GetAssetPackStateAsyncCallbackExample : MonoBehaviour{ void Start() { var assetPackNames = new string[] { "MyAssetPack" }; AndroidAssetPacks.GetAssetPackStateAsync(assetPackNames, OnStateQueryComplete); } void OnStateQueryComplete(ulong totalSize, AndroidAssetPackState[] states) { Debug.Log($"Total size: {totalSize} bytes"); if (states == null) { Debug.LogError("Failed to retrieve asset pack states."); return; } foreach (var state in states) { Debug.Log($"{state.name}: status={state.status}, error={state.error}"); } }}

GetAssetPackStateAsync(string[])

Queries the state of Android asset packs.
public static GetAssetPackStateAsyncOperation GetAssetPackStateAsync(string[] assetPackNames)

Parameters

assetPackNames

The array of names of the Android asset packs to query the state of.

Returns

Type

Description

GetAssetPackStateAsyncOperationAn object that represents the query operation. If you yield this object inside a coroutine, the coroutine pauses until the operation is complete.

Remarks

This method directly wraps Google's PlayCore plug-in API. If the PlayCore plug-in is missing, calling this method throws an
InvalidOperationException
.

Examples

using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.Android;public class GetAssetPackStateAsyncExample : MonoBehaviour{ IEnumerator Start() { var assetPackNames = new string[] { "MyAssetPack", "AnotherAssetPack" }; var stateOperation = AndroidAssetPacks.GetAssetPackStateAsync(assetPackNames); // Yield until the query completes. yield return stateOperation; Debug.Log($"Total size of queried packs: {stateOperation.size} bytes"); if (stateOperation.states == null) { Debug.LogError("Failed to retrieve asset pack states."); yield break; } var packsToDownload = new List<string>(); foreach (var state in stateOperation.states) { if (state.status == AndroidAssetPackStatus.NotInstalled) { packsToDownload.Add(state.name); } else if (state.status == AndroidAssetPackStatus.Completed) { Debug.Log($"{state.name} is already downloaded."); } else if (state.error != AndroidAssetPackError.NoError) { Debug.LogError($"{state.name} has error: {state.error}"); } } if (packsToDownload.Count > 0) { Debug.Log($"Downloading {packsToDownload.Count} asset pack(s): {string.Join(", ", packsToDownload)}"); yield return AndroidAssetPacks.DownloadAssetPackAsync(packsToDownload.ToArray()); } }}