12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System.Threading.Tasks;
- using YooAsset;
- using System.Collections.Generic;
- namespace GFGGame
- {
- public class LoadManager : SingletonBase<LoadManager>
- {
- private Dictionary<string, bool> checkStatusDic = new Dictionary<string, bool>();
- public bool CheckResExsited(string location)
- {
- if (string.IsNullOrEmpty(location))
- {
- return false;
- }
- checkStatusDic.TryGetValue(location, out bool exsited);
- return exsited;
- }
- public async Task CheckResExsitedOrDownload(string location)
- {
- if(CheckResExsited(location))
- {
- return;
- }
- ResourceDownloaderOperation downloaderOperation = YooAssets.CreateBundleDownloader(new string[] { location}, 3, 3);
- if (downloaderOperation.TotalDownloadCount == 0)
- {
- //文件已在本地,不需要下载
- return;
- }
- ViewManager.Show<ModalStatusView>("加载中...");
- //下载
- downloaderOperation.BeginDownload();
- await downloaderOperation.Task;
- checkStatusDic[location] = true;
- ViewManager.Hide<ModalStatusView>();
- }
- public void SetResDownloaded(string location)
- {
- checkStatusDic[location] = true;
- }
- }
- }
|