Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

106 строки
1.7 KiB

  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using UnityEngine;
  5. namespace Inno.DLC
  6. {
  7. public class DLCDownloadTask
  8. {
  9. public DLCDownloadTask(string url, string path)
  10. {
  11. this._path = path;
  12. this._www = new WWW(url);
  13. }
  14. private void FireDownloadFinishedEvent()
  15. {
  16. if (this.DownloadFinishedEvent != null)
  17. {
  18. this.DownloadFinishedEvent(this);
  19. }
  20. }
  21. public float WWWProgress
  22. {
  23. get
  24. {
  25. return (this._www == null) ? 0f : this._www.progress;
  26. }
  27. }
  28. public bool WWWIsDone
  29. {
  30. get
  31. {
  32. return this._www == null || this._www.isDone;
  33. }
  34. }
  35. public bool IsFinished
  36. {
  37. get
  38. {
  39. return this._finished;
  40. }
  41. }
  42. public bool IsSuccess
  43. {
  44. get
  45. {
  46. return this._success;
  47. }
  48. }
  49. public string ErrorMessage
  50. {
  51. get
  52. {
  53. return this._errorMessage;
  54. }
  55. }
  56. public IEnumerator WaitAndStore()
  57. {
  58. yield return this._www;
  59. if (string.IsNullOrEmpty(this._www.error))
  60. {
  61. try
  62. {
  63. File.WriteAllBytes(this._path, this._www.bytes);
  64. this._errorMessage = string.Empty;
  65. this._success = true;
  66. }
  67. catch (Exception ex)
  68. {
  69. UnityEngine.Debug.LogError(string.Format("Cannot save DLC file: {0}", ex.Message));
  70. this._errorMessage = ex.Message;
  71. this._success = false;
  72. }
  73. }
  74. else
  75. {
  76. this._errorMessage = this._www.error;
  77. this._success = false;
  78. }
  79. this._www = null;
  80. this._finished = true;
  81. this.FireDownloadFinishedEvent();
  82. yield break;
  83. }
  84. public Action<DLCDownloadTask> DownloadFinishedEvent;
  85. private string _path;
  86. private WWW _www;
  87. private bool _finished;
  88. private bool _success;
  89. private string _errorMessage;
  90. }
  91. }