LoadManager.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Threading.Tasks;
  2. using YooAsset;
  3. using System.Collections.Generic;
  4. namespace GFGGame
  5. {
  6. public class LoadManager : SingletonBase<LoadManager>
  7. {
  8. private Dictionary<string, bool> checkStatusDic = new Dictionary<string, bool>();
  9. public bool CheckResExsited(string location)
  10. {
  11. if (string.IsNullOrEmpty(location))
  12. {
  13. return false;
  14. }
  15. checkStatusDic.TryGetValue(location, out bool exsited);
  16. return exsited;
  17. }
  18. public async Task CheckResExsitedOrDownload(string location)
  19. {
  20. if(CheckResExsited(location))
  21. {
  22. return;
  23. }
  24. ResourceDownloaderOperation downloaderOperation = YooAssets.CreateBundleDownloader(new string[] { location}, 3, 3);
  25. if (downloaderOperation.TotalDownloadCount == 0)
  26. {
  27. //文件已在本地,不需要下载
  28. return;
  29. }
  30. ViewManager.Show<ModalStatusView>("加载中...");
  31. //下载
  32. downloaderOperation.BeginDownload();
  33. await downloaderOperation.Task;
  34. checkStatusDic[location] = true;
  35. ViewManager.Hide<ModalStatusView>();
  36. }
  37. public void SetResDownloaded(string location)
  38. {
  39. checkStatusDic[location] = true;
  40. }
  41. }
  42. }