123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using UnityEngine;
- namespace VEngine
- {
- internal class DownloadBundle : Bundle
- {
- private Download download;
- private AssetBundleCreateRequest request;
- protected override void OnLoad()
- {
- download = Download.DownloadAsync(pathOrURL, Versions.GetDownloadDataPath(info.nameWithAppendHash), null,
- info.size, info.crc);
- download.completed += OnDownloaded;
- }
- private void OnDownloaded(Download obj)
- {
- if (download.status == DownloadStatus.Failed)
- {
- Finish(download.error);
- return;
- }
- if (assetBundle != null) return;
- var encrpytData = EncryptHelper.GetDecryptData(obj.info.savePath, EncryptHelper.resKeyChars);
- request = AssetBundle.LoadFromMemoryAsync(encrpytData);
- Versions.SetBundlePathOrURl(info.nameWithAppendHash, obj.info.savePath);
- }
- protected override void OnUpdate()
- {
- if (status != LoadableStatus.Loading) return;
- if (!download.isDone)
- {
- progress = download.downloadedBytes * 1f / download.info.size * 0.5f;
- return;
- }
- if (request == null) return;
- progress = 0.5f + request.progress;
- if (!request.isDone) return;
- OnLoaded(request.assetBundle);
- request = null;
- }
- }
- }
|