how to download all assets and safe it to cache at login screen ?
Something like this:
async void InitializeAndDownloadAllAssets(System.Action onContinue)
{
var locator = await Addressables.InitializeAsync().Task;
IList<object> keys = new List<object>(locator.Keys);
long downloadSize = await Addressables.GetDownloadSizeAsync(keys).Task;
if (downloadSize > 0)
{
var downloadHandle = Addressables.DownloadDependenciesAsync(keys, Addressables.MergeMode.Union);
StartCoroutine(Progress(downloadHandle));
}
else
{
onContinue();
}
IEnumerator Progress(AsyncOperationHandle asyncOperation)
{
while (!asyncOperation.IsDone)
{
yield return null;
long currentDownloaded = (long) System.Math.Floor((double) asyncOperation.PercentComplete * downloadSize);
// Display progress: currentDownloaded / downloadSize
}
onContinue();
}
}
what is the metric of the return downloadsize?
is it bit or byte?
and does it download all assets if we only add 1 new assets?
because we only check the size of all assets
btw thanks for the response @ProtoTerminator
after i download the asset, the i close the application then open it again, the downloadsize is not zero,
i thought that it will be zero after we download the asset and safe it to cache?
@ProtoTerminator
According to the docs it’s in bytes. (Btw, apparently there’s a bug in 1.11 that GetDownloadSizeAsync
always returns the full size, so this is not reliable in that version. Until they fix that, this should work in 1.10.)
It should only download new or changed assets.
@ProtoTerminator yeah you are right it work after i change the version,
last question, what if we erase some assets, will it remove the asset from cache automatically?
Currently, no, cached assets are not removed, and there is no existing useful API for that case (though there are less useful APIs, like Caching.ClearCache
that will clear all cached bundles). The Addressables team needs to expand on that functionality.
@ProtoTerminator ok thanks sir