Eonirr

Untitled

Mar 28th, 2025
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. private void InstallGameFiles(bool _isUpdate, Version _onlineVersion)
  2. {
  3. try
  4. {
  5. _downloadBar.gameObject.SetActive(true);
  6. _downloadBar.maxValue = 100f;
  7.  
  8. _downloadSpeed.gameObject.SetActive(true);
  9. _downloadSize.gameObject.SetActive(true);
  10. _executionText.gameObject.SetActive(true);
  11.  
  12. /////////////////////Stopwatch watch = new Stopwatch();
  13.  
  14. watch.Start();
  15. WebClient webClient = new();
  16. webClient.Proxy = null;
  17.  
  18. webClient.DownloadProgressChanged += (sender, e) =>
  19. {
  20. double index = (double)(e.BytesReceived);
  21. double total = (double)e.TotalBytesToReceive;
  22. double progressPercentage = (index / total);
  23. float iProgressPercentage = (float)(progressPercentage * 100);
  24.  
  25. if(_downloadBar != null)
  26. _downloadBar.value = iProgressPercentage;
  27.  
  28. double sec = watch.Elapsed.TotalSeconds;
  29. double speed = e.BytesReceived / sec;
  30. _downloadSpeed.text = SizeSuffix((long)speed) + "/s";
  31. _downloadSize.text = SizeSuffix(e.BytesReceived) + "/" + SizeSuffix(e.TotalBytesToReceive);
  32. };
  33.  
  34. webClient.DownloadFileCompleted += (sender, e) =>
  35. {
  36. DownloadGameCompleteCallback(sender, e);
  37. /////////////////watch.Stop();
  38. //////////////DEBUG
  39.  
  40. };
  41.  
  42. webClient.DownloadFileAsync(new Uri(gameBuildZipLink), gameZip, _onlineVersion);
  43. }
  44. catch (Exception ex)
  45. {
  46. MsgBox(0, $"Error downloading the game: {ex}", "Error", 0);
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment