DWRFSLoadBundleOperation.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 
  2. namespace YooAsset
  3. {
  4. internal class DWRFSLoadAssetBundleOperation : FSLoadBundleOperation
  5. {
  6. private enum ESteps
  7. {
  8. None,
  9. DownloadAssetBundle,
  10. Done,
  11. }
  12. private readonly DefaultWebRemoteFileSystem _fileSystem;
  13. private readonly PackageBundle _bundle;
  14. private DownloadAssetBundleOperation _downloadAssetBundleOp;
  15. private ESteps _steps = ESteps.None;
  16. internal DWRFSLoadAssetBundleOperation(DefaultWebRemoteFileSystem fileSystem, PackageBundle bundle)
  17. {
  18. _fileSystem = fileSystem;
  19. _bundle = bundle;
  20. }
  21. internal override void InternalStart()
  22. {
  23. _steps = ESteps.DownloadAssetBundle;
  24. }
  25. internal override void InternalUpdate()
  26. {
  27. if (_steps == ESteps.None || _steps == ESteps.Done)
  28. return;
  29. if (_steps == ESteps.DownloadAssetBundle)
  30. {
  31. if (_downloadAssetBundleOp == null)
  32. {
  33. DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
  34. downloadParam.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
  35. downloadParam.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
  36. if (_bundle.Encrypted)
  37. {
  38. _downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(true, _fileSystem.DecryptionServices, _bundle, downloadParam);
  39. _downloadAssetBundleOp.StartOperation();
  40. AddChildOperation(_downloadAssetBundleOp);
  41. }
  42. else
  43. {
  44. _downloadAssetBundleOp = new DownloadWebNormalAssetBundleOperation(_fileSystem.DisableUnityWebCache, _bundle, downloadParam);
  45. _downloadAssetBundleOp.StartOperation();
  46. AddChildOperation(_downloadAssetBundleOp);
  47. }
  48. }
  49. _downloadAssetBundleOp.UpdateOperation();
  50. DownloadProgress = _downloadAssetBundleOp.DownloadProgress;
  51. DownloadedBytes = _downloadAssetBundleOp.DownloadedBytes;
  52. Progress = _downloadAssetBundleOp.Progress;
  53. if (_downloadAssetBundleOp.IsDone == false)
  54. return;
  55. if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed)
  56. {
  57. var assetBundle = _downloadAssetBundleOp.Result;
  58. if (assetBundle == null)
  59. {
  60. _steps = ESteps.Done;
  61. Status = EOperationStatus.Failed;
  62. Error = $"{nameof(DownloadAssetBundleOperation)} loaded asset bundle is null !";
  63. }
  64. else
  65. {
  66. _steps = ESteps.Done;
  67. Result = new AssetBundleResult(_fileSystem, _bundle, assetBundle, null);
  68. Status = EOperationStatus.Succeed;
  69. }
  70. }
  71. else
  72. {
  73. _steps = ESteps.Done;
  74. Status = EOperationStatus.Failed;
  75. Error = _downloadAssetBundleOp.Error;
  76. }
  77. }
  78. }
  79. internal override void InternalWaitForAsyncComplete()
  80. {
  81. if (_steps != ESteps.Done)
  82. {
  83. _steps = ESteps.Done;
  84. Status = EOperationStatus.Failed;
  85. Error = "WebGL platform not support sync load method !";
  86. UnityEngine.Debug.LogError(Error);
  87. }
  88. }
  89. }
  90. }