ManifestRequest.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. public class ManifestRequest : AssetRequest
  6. {
  7. private string assetName;
  8. private BundleRequest request;
  9. public int version { get; private set; }
  10. public override float progress
  11. {
  12. get
  13. {
  14. if (isDone)
  15. return 1;
  16. if (LoadState == AssetLoadState.Init)
  17. return 0;
  18. if (request == null)
  19. return 1;
  20. return request.progress;
  21. }
  22. }
  23. internal override void Load()
  24. {
  25. assetName = Path.GetFileName(name);
  26. if (LoadModule.runtimeMode)
  27. {
  28. var assetBundleName = assetName.Replace("", "").ToLower();
  29. request = LoadModule.LoadBundleAsync(assetBundleName);
  30. }
  31. else
  32. {
  33. LoadState = AssetLoadState.Loaded;
  34. }
  35. }
  36. internal override bool Update()
  37. {
  38. if (!base.Update())
  39. return false;
  40. if (LoadState == AssetLoadState.Init)
  41. return true;
  42. if(request == null)
  43. {
  44. LoadState = AssetLoadState.Loaded;
  45. error = "request == null";
  46. return false;
  47. }
  48. if (request.isDone)
  49. {
  50. if(request.assetBundle == null)
  51. {
  52. error = "assetBundle == null";
  53. }
  54. else
  55. {
  56. var manifest = request.assetBundle.LoadAsset<Manifest>(assetName);
  57. if (manifest == null)
  58. error = "manifest == null";
  59. else
  60. LoadModule.OnManifestLoaded(manifest);
  61. }
  62. LoadState = AssetLoadState.Loaded;
  63. return false;
  64. }
  65. return true;
  66. }
  67. }