LoadManager.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class LoadManager : Singleton<LoadManager>
  6. {
  7. public Dictionary<string, DownLoadItem> downList = new Dictionary<string, DownLoadItem>();
  8. public void load(ModelItem model, Action<float> onProgress, Action<GameObject> callback)
  9. {
  10. string dName = getLoadName(model.url, model.Version);
  11. if (!downList.ContainsKey(dName))
  12. {
  13. GameObject obj = new GameObject(dName);
  14. DownLoadItem dli = obj.AddComponent<DownLoadItem>();
  15. dli.Init(model.url, model.uid);
  16. }
  17. downList[dName].onProgress += (float f) => {
  18. onProgress.Invoke(f);
  19. };
  20. downList[dName].callback += (bool b) => {
  21. if(b)
  22. {
  23. if (!downList[dName].isAction)
  24. {
  25. //下载成功并无处理
  26. switch (model.modelType)
  27. {
  28. case ModelItem.ModelType.Image:
  29. break;
  30. case ModelItem.ModelType.Video:
  31. break;
  32. case ModelItem.ModelType.ABModel:
  33. break;
  34. }
  35. }
  36. }
  37. else
  38. {
  39. //下载失败
  40. }
  41. };
  42. }
  43. public string getLoadName(string url, string version)
  44. {
  45. return url + "_" + version;
  46. }
  47. }