I am migrating my project from Unity 2022.3.28f1 to Unity 6.0.36f1.
migrating Addressable 1.22.2 to 2.3.16
A wrong calculation started to occur in the function Addressables.GetDownloadSizeAsync
I use this function to get the download size of label “DownloadContent”
Using Old Unity and Old Addressables
Addressables.GetDownloadSizeAsync("DownloadContent"): this return 96586979 bytes
Addressables.DownloadDependenciesAsync(key): this return 96586979 bytes
var download = mDownloadHandle.GetDownloadStatus();
download.TotalBytes == 96586979 bytes
Using New Unity and New Addressables
Addressables.GetDownloadSizeAsync("DownloadContent"): this return 399943181 bytes
Addressables.DownloadDependenciesAsync(key): this return 96586979 bytes
var download = mDownloadHandle.GetDownloadStatus();
download.TotalBytes == 96586979 bytes
The new return from GetDownloadSizeAsync is 399943181 bytes instead of 96586979 bytes
My code in two versions is thus:
public async Task<DownloadSizeResponse> GetDownloadSize(string key)
{
mDownloadSizeHandle = Addressables.GetDownloadSizeAsync(key);
await mDownloadSizeHandle.Task;
return new DownloadSizeResponse()
{
Size = mDownloadSizeHandle.Result,
Success = mDownloadSizeHandle.Status == AsyncOperationStatus.Succeeded
};
}
public async Task<bool> DownloadAssetAsync(string key, System.Action<float, long, long> progressCallBack)
{
ReleaseDownloadHandle();
mDownloadHandle = Addressables.DownloadDependenciesAsync(key);
int step = 0;
int stepLimit = 2;
long oldDownloadBytes = 0;
while (mDownloadHandle.Status == AsyncOperationStatus.None && mDownloadHandle.IsValid())
{
if (!mIsAlive)
break;
var download = mDownloadHandle.GetDownloadStatus();
step++;
if (step > stepLimit && download.DownloadedBytes != oldDownloadBytes)
{
progressCallBack.Invoke(download.Percent, download.DownloadedBytes, download.TotalBytes);
step = 0;
oldDownloadBytes = download.DownloadedBytes;
}
await Task.Yield();
}
var result = mDownloadHandle.Status == AsyncOperationStatus.Succeeded;
ReleaseDownloadHandle();
return result;
}