DownloadBundle.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. namespace VEngine
  3. {
  4. internal class DownloadBundle : Bundle
  5. {
  6. private Download download;
  7. private AssetBundleCreateRequest request;
  8. protected override void OnLoad()
  9. {
  10. download = Download.DownloadAsync(pathOrURL, Versions.GetDownloadDataPath(info.nameWithAppendHash), null,
  11. info.size, info.crc);
  12. download.completed += OnDownloaded;
  13. }
  14. private void OnDownloaded(Download obj)
  15. {
  16. if (download.status == DownloadStatus.Failed)
  17. {
  18. Finish(download.error);
  19. return;
  20. }
  21. if (assetBundle != null) return;
  22. var encrpytData = EncryptHelper.GetDecryptData(obj.info.savePath, EncryptHelper.resKeyChars);
  23. request = AssetBundle.LoadFromMemoryAsync(encrpytData);
  24. Versions.SetBundlePathOrURl(info.nameWithAppendHash, obj.info.savePath);
  25. }
  26. protected override void OnUpdate()
  27. {
  28. if (status != LoadableStatus.Loading) return;
  29. if (!download.isDone)
  30. {
  31. progress = download.downloadedBytes * 1f / download.info.size * 0.5f;
  32. return;
  33. }
  34. if (request == null) return;
  35. progress = 0.5f + request.progress;
  36. if (!request.isDone) return;
  37. OnLoaded(request.assetBundle);
  38. request = null;
  39. }
  40. }
  41. }