feat : default editor file system support async simulate frame

编辑器文件系统支持异步模拟加载帧数
pull/418/head
何冠峰 2024-12-11 10:43:13 +08:00
parent e76a782a80
commit d890ccd5e6
3 changed files with 88 additions and 7 deletions

View File

@ -36,6 +36,17 @@ namespace YooAsset
}
}
#region 自定义参数
/// <summary>
/// 异步模拟加载最小帧数
/// </summary>
public int _asyncSimulateMinFrame = 1;
/// <summary>
/// 异步模拟加载最大帧数
/// </summary>
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
}
}

View File

@ -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()
{

View File

@ -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";
}
}