mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-25 02:00:16 +00:00
refactor the runtime code
重构了运行时代码,支持全新的文件系统。
This commit is contained in:
@@ -51,11 +51,11 @@ namespace YooAsset
|
||||
public abstract ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60);
|
||||
}
|
||||
|
||||
internal class EditorPlayModePreDownloadContentOperation : PreDownloadContentOperation
|
||||
internal class EditorSimulateModePreDownloadContentOperation : PreDownloadContentOperation
|
||||
{
|
||||
private readonly EditorSimulateModeImpl _impl;
|
||||
|
||||
public EditorPlayModePreDownloadContentOperation(EditorSimulateModeImpl impl)
|
||||
public EditorSimulateModePreDownloadContentOperation(EditorSimulateModeImpl impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
@@ -69,23 +69,23 @@ namespace YooAsset
|
||||
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
}
|
||||
internal class OfflinePlayModePreDownloadContentOperation : PreDownloadContentOperation
|
||||
@@ -106,23 +106,23 @@ namespace YooAsset
|
||||
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
}
|
||||
internal class HostPlayModePreDownloadContentOperation : PreDownloadContentOperation
|
||||
@@ -130,19 +130,16 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckParams,
|
||||
CheckActiveManifest,
|
||||
TryLoadCacheManifest,
|
||||
DownloadManifest,
|
||||
LoadCacheManifest,
|
||||
LoadPackageManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly HostPlayModeImpl _impl;
|
||||
private readonly string _packageVersion;
|
||||
private readonly int _timeout;
|
||||
private LoadCacheManifestOperation _tryLoadCacheManifestOp;
|
||||
private LoadCacheManifestOperation _loadCacheManifestOp;
|
||||
private DownloadManifestOperation _downloadManifestOp;
|
||||
private FSLoadPackageManifestOperation _loadPackageManifestOp;
|
||||
private PackageManifest _manifest;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
@@ -155,13 +152,26 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.CheckActiveManifest;
|
||||
_steps = ESteps.CheckParams;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckParams)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Package version is null or empty.";
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckActiveManifest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckActiveManifest)
|
||||
{
|
||||
// 检测当前激活的清单对象
|
||||
@@ -175,69 +185,22 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
}
|
||||
_steps = ESteps.TryLoadCacheManifest;
|
||||
_steps = ESteps.LoadPackageManifest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.TryLoadCacheManifest)
|
||||
if (_steps == ESteps.LoadPackageManifest)
|
||||
{
|
||||
if (_tryLoadCacheManifestOp == null)
|
||||
if (_loadPackageManifestOp == null)
|
||||
{
|
||||
_tryLoadCacheManifestOp = new LoadCacheManifestOperation(_impl.Persistent, _packageVersion);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _tryLoadCacheManifestOp);
|
||||
_loadPackageManifestOp = _impl.CacheFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout);
|
||||
}
|
||||
|
||||
if (_tryLoadCacheManifestOp.IsDone == false)
|
||||
if (_loadPackageManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_tryLoadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_manifest = _tryLoadCacheManifestOp.Manifest;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.DownloadManifest;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadManifest)
|
||||
{
|
||||
if (_downloadManifestOp == null)
|
||||
{
|
||||
_downloadManifestOp = new DownloadManifestOperation(_impl.Persistent, _impl.RemoteServices, _packageVersion, _timeout);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _downloadManifestOp);
|
||||
}
|
||||
|
||||
if (_downloadManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_downloadManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadCacheManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloadManifestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadCacheManifest)
|
||||
{
|
||||
if (_loadCacheManifestOp == null)
|
||||
{
|
||||
_loadCacheManifestOp = new LoadCacheManifestOperation(_impl.Persistent, _packageVersion);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _loadCacheManifestOp);
|
||||
}
|
||||
|
||||
if (_loadCacheManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_manifest = _loadCacheManifestOp.Manifest;
|
||||
_manifest = _loadPackageManifestOp.Result;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
@@ -245,7 +208,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadCacheManifestOp.Error;
|
||||
Error = _loadPackageManifestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,11 +218,11 @@ namespace YooAsset
|
||||
if (Status != EOperationStatus.Succeed)
|
||||
{
|
||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
List<BundleInfo> downloadList = _impl.GetDownloadListByAll(_manifest);
|
||||
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByAll(_manifest, _impl.BuildinFileSystem, _impl.DeliveryFileSystem, _impl.CacheFileSystem);
|
||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
@@ -267,11 +230,11 @@ namespace YooAsset
|
||||
if (Status != EOperationStatus.Succeed)
|
||||
{
|
||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag });
|
||||
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByTags(_manifest, new string[] { tag }, _impl.BuildinFileSystem, _impl.DeliveryFileSystem, _impl.CacheFileSystem);
|
||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
@@ -279,11 +242,11 @@ namespace YooAsset
|
||||
if (Status != EOperationStatus.Succeed)
|
||||
{
|
||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, tags);
|
||||
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByTags(_manifest, tags, _impl.BuildinFileSystem, _impl.DeliveryFileSystem, _impl.CacheFileSystem);
|
||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
@@ -291,15 +254,15 @@ namespace YooAsset
|
||||
if (Status != EOperationStatus.Succeed)
|
||||
{
|
||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
List<AssetInfo> assetInfos = new List<AssetInfo>();
|
||||
var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null);
|
||||
assetInfos.Add(assetInfo);
|
||||
|
||||
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray());
|
||||
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), _impl.BuildinFileSystem, _impl.DeliveryFileSystem, _impl.CacheFileSystem);
|
||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
@@ -307,7 +270,7 @@ namespace YooAsset
|
||||
if (Status != EOperationStatus.Succeed)
|
||||
{
|
||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
|
||||
@@ -317,8 +280,8 @@ namespace YooAsset
|
||||
assetInfos.Add(assetInfo);
|
||||
}
|
||||
|
||||
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray());
|
||||
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), _impl.BuildinFileSystem, _impl.DeliveryFileSystem, _impl.CacheFileSystem);
|
||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
@@ -340,23 +303,23 @@ namespace YooAsset
|
||||
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user