PreloadManager.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using GFGGame.Launcher;
  2. using System.Collections.Generic;
  3. using YooAsset;
  4. namespace GFGGame
  5. {
  6. public class PreloadManager : SingletonMonoBase<PreloadManager>
  7. {
  8. private List<string> waitList = new List<string>();
  9. private ResourceDownloaderOperation downloaderOperation;
  10. private string[] locationsLoading;
  11. public void Add(string location)
  12. {
  13. waitList.Add(location);
  14. }
  15. private void Update()
  16. {
  17. if(downloaderOperation != null)
  18. {
  19. if(downloaderOperation.IsDone)
  20. {
  21. foreach(var t in locationsLoading)
  22. {
  23. LoadManager.Instance.SetResDownloaded(t);
  24. }
  25. downloaderOperation = null;
  26. locationsLoading = null;
  27. }
  28. }
  29. if(downloaderOperation == null)
  30. {
  31. waitList.Reverse();//看了yooasset源码,疑似他是从后往前加载,这里翻转一下
  32. locationsLoading = waitList.ToArray();
  33. downloaderOperation = YooAssets.CreateBundleDownloader(locationsLoading, 1, 3);
  34. downloaderOperation.BeginDownload();
  35. waitList.Clear();
  36. }
  37. }
  38. }
  39. }