Patching
How to know if I need a patch system
Your game might not require patches. If your bundles are quite small in size, and the user is expected to always have an internet access, you can just load your assets and let the system download the bundles if they are not present in the application cache.
But, if your bundles are quite large (more than 10mo each) or you expect your user to be able to play offline, you need to make sure that the user downloads all the bundles if they need to be updated after they start playing.
How to know if I need to do a patch
{
// Check all the bundles
if (AssetBundles.CheckIfBundlesOutdated()) {
// Patch required
}
// Check for specific bundles (and implicitly, their dependencies)
// This is usefull when you have paid or downloadable extra content
if (AssetBundles.CheckIfBundlesOutdated(new string[] {"bundle-1", "bundle-2"})) {
// Patch needed
}
}
Patching
Now that you know that you have to do a patch, here is how it is done:
try {
await AssetBundles.Patch(null,
// Start callback, it is called after the system determined the amount of octet that will be downloaded
(downloadSize) => {
// Use this to update your UI
Debug.Log("Starting a patch of : " + downloadSize + " octets");
},
// Progress callback (progress goes from 0 to 1)
(progress) => {
// Use this to update your UI
Debug.Log("Patch progress: " + Mathf.CeilToInt(progress * 100) + "%");
}
);
} catch (Exception e) {
// Something went wrong during the patch
Debug.Log("Patch error: " + e);
}
Clearing the cache
If there is any problem with the patching or the downloaded bundles, you can clear the cache by calling AssetBundles.ClearCache
and it will remove any bundles that are stored in the application cache.