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 plugin. 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.
您下载资源包并访问其资源的方式取决于资源包的交付方式。有三种资源包交付模式:
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 is 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, see 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, see below.有关交付模式的更多信息,请参阅交付模式。
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 are 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.
获得资源包的名称后,要检查每个资源包的状态,请传入资源包名称调用 AndroidAssetPacks.GetAssetPackStateAsync。这将返回您查询的资源包的状态,您可以根据结果确定是否需要下载资源包。如果您想快速查询每个 Unity 生成的资源包的状态,您可以使用 AndroidAssetPacks.coreUnityAssetPacksDownloaded。这很有用,因为在加载第一个场景以外的任何场景或尝试访问 Unity 处理的其他资源之前,您必须确保每个 Unity 生成的资源包都可用。
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:
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.