Version: Unity 6 Beta (6000.0)
Language : English
Create a custom asset pack
Graphics for Android

Manage asset packs at runtime

Unity provides APIs to manage asset packs at runtime. They use Google’s PlayCore API, which means they have the same limitations as PlayCore, and can’t manage install-time asset packs. Using the PlayCore API also means your application requires the PlayCore plug-inA set of code created outside of Unity that creates functionality in Unity. There are two kinds of plug-ins you can use in Unity: Managed plug-ins (managed .NET assemblies created with tools like Visual Studio) and Native plug-ins (platform-specific native code libraries). More info
See in Glossary
. If your project has asset packs, either custom asset packs or Unity-generated asset packs, Unity automatically adds the PlayCore dependency to the application’s manifest.

The way you download asset packs and access their assets depends on the asset pack delivery mode. There are three asset pack delivery modes:

  • install-time: Google Play automatically downloads install-time asset packs when the device installs the application. Google Play considers these asset packs to be part of the base application, and an end user can’t uninstall them without uninstalling the entire application. The PlayCore API doesn’t handle install-time asset packs, which means that you can’t check the status, request to download, or remove install-time asset packs. You also can’t directly access assets inside of these asset packs, except streaming assets in Unity-generated install-time asset packs. To access streaming assets, use Application.streamingAssetsPath to get the path to streaming assets location, then use UnityWebRequest to access assets in that path. If you create a custom asset pack, you can’t access assets inside it using standard file APIs. Instead, use Android’s AssetManager APIs.
  • fast-follow: Google Play automatically starts to download fast-follow asset packs after it installs the application. However, it’s possible that not all fast-follow asset packs are available on the first time the application launches. To check the status and download fast-follow asset packs, refer to Download asset packs.
  • on-demand: Google Play doesn’t automatically download on-demand asset packs. You have to manually start the download. For information on how to do this, refer to Download asset packs.

For more information about delivery modes, refer to Delivery modes.

Download asset packs

If your application uses fast-follow or on-demand asset packs, the device must download these asset packs before the application can access assets inside of them. To check the status of asset packs and download them if they’re not on the device, you must first know the name of each asset pack. To get the names of Unity-generated asset packs, call AndroidAssetPacks.GetCoreUnityAssetPackNames. There is no runtime API to get the names of custom asset packs so you must keep track of them yourself. You set the name of custom asset packs at build time; it’s the name of the directory.

After you have the names of your asset packs, to check the status of each asset pack, call AndroidAssetPacks.GetAssetPackStateAsync, passing in the asset pack name. This returns the status of the asset pack you query, and you can use the result to determine whether you need to download the asset pack. If you want to quickly query the status of every Unity-generated asset pack, you can use AndroidAssetPacks.coreUnityAssetPacksDownloaded. This helps you to ensure that every Unity-generated asset pack is available before you load any sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary
other than the first one or try to access other resources that Unity handles.

For every asset pack you need to download, call AndroidAssetPacks.DownloadAssetPackAsync, passing in the asset pack name. While the asset pack downloads, monitor the download status because downloads can pause or fail. There are two ways to do this:

Additional resources

Create a custom asset pack
Graphics for Android
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961