IEnumerator DownloadProgress()
    {
        // Calculate progress and download speed.

        while (!downloadHandle.IsDone)
        {
            var status = downloadHandle.GetDownloadStatus();

            // Progress

            float progress = status.TotalBytes != 0 ? (float)status.DownloadedBytes / (float)status.TotalBytes : 0f;

            // Speed

            if (bytesAtTime.Count > 5)
            {
                bytesAtTime.RemoveAt(0);
                bytesTime.RemoveAt(0);
            }

            bytesAtTime.Add(status.DownloadedBytes);
            bytesTime.Add(Time.time);

            float timeSpan       = bytesTime[bytesTime.Count - 1] - bytesTime[0];
            float byteSpan       = bytesAtTime[bytesAtTime.Count - 1] - bytesAtTime[0];
            long  bytesPerSecond = !Mathf.Approximately(timeSpan, 0) ? (long)(byteSpan / timeSpan) : 0;

            dlProgressCallback(progress, "Progress: " + (progress * 100).ToString("F0") + "%, Speed: " + FormatSize(bytesPerSecond) + "/sec");
            yield return(new WaitForSeconds(.2f));
        }
    }
Beispiel #2
0
 private void Update()
 {
     if (textAssetDownloadStatus != null)
     {
         var downloadStatus = opHandle.GetDownloadStatus();
         if (!downloadStatus.IsDone)
         {
             textAssetDownloadStatus.text = $"Loading Asset ... {(downloadStatus.Percent * 100)}";
         }
     }
 }
Beispiel #3
0
        IEnumerator Start()
        {
            downloadHandle = Addressables.DownloadDependenciesAsync(preloadLabel, false);
            float progress = 0;

            while (downloadHandle.Status == AsyncOperationStatus.None)
            {
                float percentageComplete = downloadHandle.GetDownloadStatus().Percent;
                if (percentageComplete > progress * 1.1) // Report at most every 10% or so
                {
                    progress = percentageComplete;       // More accurate %
                    ProgressEvent.Invoke(progress);
                }
                yield return(null);
            }

            CompletionEvent.Invoke(downloadHandle.Status == AsyncOperationStatus.Succeeded);
            Addressables.Release(downloadHandle); //Release the operation handle
        }
        private static async UniTask DownloadContentAsyncInternal(Action <DownloadStatus> onDownloadProgressUpdate,
                                                                  AsyncOperationHandle handle)
        {
            try
            {
                do
                {
                    var downloadStatus = handle.GetDownloadStatus();
                    onDownloadProgressUpdate?.Invoke(downloadStatus);
                    await UniTask.WaitForEndOfFrame();
                } while (handle.IsDone == false);

                if (handle.Status == AsyncOperationStatus.Failed)
                {
                    throw handle.OperationException;
                }
            }
            finally
            {
                Addressables.Release(handle);
            }
        }