DownloadBundle.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. request = AssetBundle.LoadFromFileAsync(obj.info.savePath);
  23. Versions.SetBundlePathOrURl(info.nameWithAppendHash, obj.info.savePath);
  24. }
  25. protected override void OnUpdate()
  26. {
  27. if (status != LoadableStatus.Loading) return;
  28. if (!download.isDone)
  29. {
  30. progress = download.downloadedBytes * 1f / download.info.size * 0.5f;
  31. return;
  32. }
  33. if (request == null) return;
  34. progress = 0.5f + request.progress;
  35. if (!request.isDone) return;
  36. OnLoaded(request.assetBundle);
  37. request = null;
  38. }
  39. }
  40. }