EditorSimulateModeImpl.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace YooAsset
  5. {
  6. internal class EditorSimulateModeImpl : IPlayModeServices, IBundleServices
  7. {
  8. private PackageManifest _activeManifest;
  9. /// <summary>
  10. /// 异步初始化
  11. /// </summary>
  12. public InitializationOperation InitializeAsync(string simulateManifestFilePath)
  13. {
  14. var operation = new EditorSimulateModeInitializationOperation(this, simulateManifestFilePath);
  15. OperationSystem.StartOperation(operation);
  16. return operation;
  17. }
  18. #region IPlayModeServices接口
  19. public PackageManifest ActiveManifest
  20. {
  21. set
  22. {
  23. _activeManifest = value;
  24. }
  25. get
  26. {
  27. return _activeManifest;
  28. }
  29. }
  30. public void FlushManifestVersionFile()
  31. {
  32. }
  33. UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
  34. {
  35. var operation = new EditorPlayModeUpdatePackageVersionOperation();
  36. OperationSystem.StartOperation(operation);
  37. return operation;
  38. }
  39. UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout)
  40. {
  41. var operation = new EditorPlayModeUpdatePackageManifestOperation();
  42. OperationSystem.StartOperation(operation);
  43. return operation;
  44. }
  45. PreDownloadContentOperation IPlayModeServices.PreDownloadContentAsync(string packageVersion, int timeout)
  46. {
  47. var operation = new EditorPlayModePreDownloadContentOperation();
  48. OperationSystem.StartOperation(operation);
  49. return operation;
  50. }
  51. ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
  52. {
  53. return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
  54. }
  55. ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
  56. {
  57. return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
  58. }
  59. ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
  60. {
  61. return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
  62. }
  63. ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
  64. {
  65. return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout);
  66. }
  67. ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
  68. {
  69. return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout);
  70. }
  71. #endregion
  72. #region IBundleServices接口
  73. private BundleInfo CreateBundleInfo(PackageBundle packageBundle, AssetInfo assetInfo)
  74. {
  75. if (packageBundle == null)
  76. throw new Exception("Should never get here !");
  77. BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromEditor);
  78. bundleInfo.IncludeAssets = _activeManifest.GetBundleIncludeAssets(assetInfo.AssetPath);
  79. return bundleInfo;
  80. }
  81. BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
  82. {
  83. if (assetInfo.IsInvalid)
  84. throw new Exception("Should never get here !");
  85. // 注意:如果清单里未找到资源包会抛出异常!
  86. var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath);
  87. return CreateBundleInfo(packageBundle, assetInfo);
  88. }
  89. BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
  90. {
  91. if (assetInfo.IsInvalid)
  92. throw new Exception("Should never get here !");
  93. // 注意:如果清单里未找到资源包会抛出异常!
  94. var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
  95. List<BundleInfo> result = new List<BundleInfo>(depends.Length);
  96. foreach (var packageBundle in depends)
  97. {
  98. BundleInfo bundleInfo = CreateBundleInfo(packageBundle, assetInfo);
  99. result.Add(bundleInfo);
  100. }
  101. return result.ToArray();
  102. }
  103. string IBundleServices.GetBundleName(int bundleID)
  104. {
  105. return _activeManifest.GetBundleName(bundleID);
  106. }
  107. bool IBundleServices.IsServicesValid()
  108. {
  109. return _activeManifest != null;
  110. }
  111. #endregion
  112. }
  113. }