diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/DefaultEditorFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/DefaultEditorFileSystem.cs index 33cf37c8..0e17481f 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/DefaultEditorFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/DefaultEditorFileSystem.cs @@ -36,6 +36,17 @@ namespace YooAsset } } + #region 自定义参数 + /// + /// 异步模拟加载最小帧数 + /// + public int _asyncSimulateMinFrame = 1; + + /// + /// 异步模拟加载最大帧数 + /// + public int _asyncSimulateMaxFrame = 1; + #endregion public DefaultEditorFileSystem() { @@ -86,7 +97,18 @@ namespace YooAsset public virtual void SetParameter(string name, object value) { - YooLogger.Warning($"Invalid parameter : {name}"); + if (name == FileSystemParametersDefine.ASYNC_SIMULATE_MIN_FRAME) + { + _asyncSimulateMinFrame = (int)value; + } + else if (name == FileSystemParametersDefine.ASYNC_SIMULATE_MAX_FRAME) + { + _asyncSimulateMaxFrame = (int)value; + } + else + { + YooLogger.Warning($"Invalid parameter : {name}"); + } } public virtual void OnCreate(string packageName, string rootDirectory) { @@ -131,7 +153,7 @@ namespace YooAsset { throw new System.NotImplementedException(); } - + #region 内部方法 public string GetEditorPackageVersionFilePath() { @@ -148,6 +170,15 @@ namespace YooAsset string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion); return PathUtility.Combine(FileRoot, fileName); } + public int GetAsyncSimulateFrame() + { + if (_asyncSimulateMinFrame > _asyncSimulateMaxFrame) + { + _asyncSimulateMinFrame = _asyncSimulateMaxFrame; + } + + return UnityEngine.Random.Range(_asyncSimulateMinFrame, _asyncSimulateMaxFrame + 1); + } #endregion } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/DEFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/DEFSLoadBundleOperation.cs index ffa76ab7..b408f669 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/DEFSLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/DEFSLoadBundleOperation.cs @@ -3,8 +3,19 @@ namespace YooAsset { internal class DEFSLoadBundleOperation : FSLoadBundleOperation { + protected enum ESteps + { + None, + DownloadFile, + LoadAssetBundle, + CheckResult, + Done, + } + private readonly DefaultEditorFileSystem _fileSystem; private readonly PackageBundle _bundle; + private int _asyncSimulateFrame; + private ESteps _steps = ESteps.None; internal DEFSLoadBundleOperation(DefaultEditorFileSystem fileSystem, PackageBundle bundle) { @@ -13,16 +24,53 @@ namespace YooAsset } internal override void InternalOnStart() { - DownloadProgress = 1f; - DownloadedBytes = _bundle.FileSize; - Status = EOperationStatus.Succeed; - Result = new VirtualBundle(_fileSystem, _bundle); + _steps = ESteps.DownloadFile; } internal override void InternalOnUpdate() { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.DownloadFile) + { + _asyncSimulateFrame = _fileSystem.GetAsyncSimulateFrame(); + DownloadProgress = 1f; + DownloadedBytes = _bundle.FileSize; + _steps = ESteps.LoadAssetBundle; + } + + if (_steps == ESteps.LoadAssetBundle) + { + if (IsWaitForAsyncComplete) + { + _steps = ESteps.CheckResult; + } + else + { + if (_asyncSimulateFrame <= 0) + _steps = ESteps.CheckResult; + else + _asyncSimulateFrame--; + } + } + + if (_steps == ESteps.CheckResult) + { + _steps = ESteps.Done; + Result = new VirtualBundle(_fileSystem, _bundle); + Status = EOperationStatus.Succeed; + } } internal override void InternalWaitForAsyncComplete() { + while (true) + { + if (ExecuteWhileDone()) + { + _steps = ESteps.Done; + break; + } + } } public override void AbortDownloadOperation() { diff --git a/Assets/YooAsset/Runtime/FileSystem/FileSystemParametersDefine.cs b/Assets/YooAsset/Runtime/FileSystem/FileSystemParametersDefine.cs index e197bc3a..17f88812 100644 --- a/Assets/YooAsset/Runtime/FileSystem/FileSystemParametersDefine.cs +++ b/Assets/YooAsset/Runtime/FileSystem/FileSystemParametersDefine.cs @@ -1,7 +1,7 @@  namespace YooAsset { - internal class FileSystemParametersDefine + public class FileSystemParametersDefine { public const string FILE_VERIFY_LEVEL = "FILE_VERIFY_LEVEL"; public const string REMOTE_SERVICES = "REMOTE_SERVICES"; @@ -11,5 +11,7 @@ namespace YooAsset public const string DISABLE_UNITY_WEB_CACHE = "DISABLE_UNITY_WEB_CACHE"; public const string RESUME_DOWNLOAD_MINMUM_SIZE = "RESUME_DOWNLOAD_MINMUM_SIZE"; public const string RESUME_DOWNLOAD_RESPONSE_CODES = "RESUME_DOWNLOAD_RESPONSE_CODES"; + public const string ASYNC_SIMULATE_MIN_FRAME = "ASYNC_SIMULATE_MIN_FRAME"; + public const string ASYNC_SIMULATE_MAX_FRAME = "ASYNC_SIMULATE_MAX_FRAME"; } } \ No newline at end of file