Compare commits

...

8 Commits

Author SHA1 Message Date
absences 0dd97e9004
Merge 008a3e1893 into d890ccd5e6 2024-12-11 10:43:24 +08:00
何冠峰 d890ccd5e6 feat : default editor file system support async simulate frame
编辑器文件系统支持异步模拟加载帧数
2024-12-11 10:43:13 +08:00
何冠峰 e76a782a80 Update ResourcePackage.cs 2024-12-11 10:04:33 +08:00
何冠峰 0f7c5b2564 Update ResourcePackage.cs 2024-12-10 18:41:09 +08:00
何冠峰 fcf0f34d5a update resource manager 2024-12-10 18:00:13 +08:00
何冠峰 acf2301028 refactor : wait for sync complete 2024-12-10 16:48:08 +08:00
absences 008a3e1893
Update AssetBundleCollector.cs 2024-11-21 18:49:17 +08:00
unknown fa572e6ae1 递归获取资源依赖列表 2024-11-18 14:59:30 +08:00
17 changed files with 226 additions and 39 deletions

View File

@ -272,19 +272,43 @@ namespace YooAsset.Editor
} }
private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath) private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath)
{ {
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true); List<AssetInfo> dependencies = new List<AssetInfo>();
List<AssetInfo> result = new List<AssetInfo>(depends.Length); HashSet<AssetStamp> m_AssetStamps = new HashSet<AssetStamp>();
foreach (string assetPath in depends) void GetDependRecursive(string assetPath)
{ {
// 注意:排除主资源对象 string[] depends = AssetDatabase.GetDependencies(assetPath, false);
if (assetPath == mainAssetPath)
foreach (string dependPath in depends)
{
// 注意:排除资源自身
if (dependPath == assetPath)
continue;
//排除主资源
if (dependPath == mainAssetPath)
continue; continue;
AssetInfo assetInfo = new AssetInfo(assetPath); var stamp = new AssetStamp(mainAssetPath, dependPath);
if (command.IgnoreRule.IsIgnore(assetInfo) == false)
result.Add(assetInfo); //主资源对于一个资源只有一个依赖
if (m_AssetStamps.Contains(stamp))
continue;
m_AssetStamps.Add(stamp);
AssetInfo assetInfo = new AssetInfo(dependPath);
//根据忽略规则排除
if (command.IgnoreRule.IsIgnore(assetInfo))
continue;
dependencies.Add(assetInfo);
GetDependRecursive(dependPath);
} }
return result; }
GetDependRecursive(mainAssetPath);
return dependencies;
} }
} }
} }

View File

@ -0,0 +1,33 @@
using System.Runtime.InteropServices;
namespace YooAsset.Editor
{
[StructLayout(LayoutKind.Auto)]
internal struct AssetStamp
{
private readonly string m_AssetName;
private readonly string m_DependAssetPath;
public AssetStamp(string assetName, string dependencyAssetName)
{
m_AssetName = assetName;
m_DependAssetPath = dependencyAssetName;
}
public string AssetName
{
get
{
return m_AssetName;
}
}
public string DependAssetPath
{
get
{
return m_DependAssetPath;
}
}
}
}

View File

@ -94,6 +94,9 @@ namespace YooAsset
// 等待验证完成 // 等待验证完成
if (_steps == ESteps.CheckVerifyTempFile) if (_steps == ESteps.CheckVerifyTempFile)
{ {
if (IsWaitForAsyncComplete)
_verifyOperation.WaitForAsyncComplete();
if (_verifyOperation.IsDone == false) if (_verifyOperation.IsDone == false)
return; return;
@ -154,9 +157,6 @@ namespace YooAsset
while (true) while (true)
{ {
if (_verifyOperation != null)
_verifyOperation.WaitForAsyncComplete();
// 注意:如果是导入或解压本地文件,执行等待完毕 // 注意:如果是导入或解压本地文件,执行等待完毕
if (isReuqestLocalFile) if (isReuqestLocalFile)
{ {
@ -305,6 +305,9 @@ namespace YooAsset
// 等待验证完成 // 等待验证完成
if (_steps == ESteps.CheckVerifyTempFile) if (_steps == ESteps.CheckVerifyTempFile)
{ {
if (IsWaitForAsyncComplete)
_verifyOperation.WaitForAsyncComplete();
if (_verifyOperation.IsDone == false) if (_verifyOperation.IsDone == false)
return; return;
@ -364,9 +367,6 @@ namespace YooAsset
while (true) while (true)
{ {
if (_verifyOperation != null)
_verifyOperation.WaitForAsyncComplete();
// 注意:如果是导入或解压本地文件,执行等待完毕 // 注意:如果是导入或解压本地文件,执行等待完毕
if (isReuqestLocalFile) if (isReuqestLocalFile)
{ {

View File

@ -58,6 +58,9 @@ namespace YooAsset
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam); _downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
} }
if (IsWaitForAsyncComplete)
_downloadFileOp.WaitForAsyncComplete();
DownloadProgress = _downloadFileOp.DownloadProgress; DownloadProgress = _downloadFileOp.DownloadProgress;
DownloadedBytes = _downloadFileOp.DownloadedBytes; DownloadedBytes = _downloadFileOp.DownloadedBytes;
if (_downloadFileOp.IsDone == false) if (_downloadFileOp.IsDone == false)
@ -198,9 +201,6 @@ namespace YooAsset
{ {
while (true) while (true)
{ {
if (_downloadFileOp != null)
_downloadFileOp.WaitForAsyncComplete();
if (ExecuteWhileDone()) if (ExecuteWhileDone())
{ {
if (_downloadFileOp != null && _downloadFileOp.Status == EOperationStatus.Failed) if (_downloadFileOp != null && _downloadFileOp.Status == EOperationStatus.Failed)
@ -274,6 +274,9 @@ namespace YooAsset
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam); _downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
} }
if (IsWaitForAsyncComplete)
_downloadFileOp.WaitForAsyncComplete();
DownloadProgress = _downloadFileOp.DownloadProgress; DownloadProgress = _downloadFileOp.DownloadProgress;
DownloadedBytes = _downloadFileOp.DownloadedBytes; DownloadedBytes = _downloadFileOp.DownloadedBytes;
if (_downloadFileOp.IsDone == false) if (_downloadFileOp.IsDone == false)
@ -313,9 +316,6 @@ namespace YooAsset
{ {
while (true) while (true)
{ {
if (_downloadFileOp != null)
_downloadFileOp.WaitForAsyncComplete();
if (ExecuteWhileDone()) if (ExecuteWhileDone())
{ {
if (_downloadFileOp != null && _downloadFileOp.Status == EOperationStatus.Failed) if (_downloadFileOp != null && _downloadFileOp.Status == EOperationStatus.Failed)

View File

@ -36,6 +36,17 @@ namespace YooAsset
} }
} }
#region 自定义参数
/// <summary>
/// 异步模拟加载最小帧数
/// </summary>
public int _asyncSimulateMinFrame = 1;
/// <summary>
/// 异步模拟加载最大帧数
/// </summary>
public int _asyncSimulateMaxFrame = 1;
#endregion
public DefaultEditorFileSystem() public DefaultEditorFileSystem()
{ {
@ -85,9 +96,20 @@ namespace YooAsset
} }
public virtual void SetParameter(string name, object value) public virtual void SetParameter(string name, object value)
{
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}"); YooLogger.Warning($"Invalid parameter : {name}");
} }
}
public virtual void OnCreate(string packageName, string rootDirectory) public virtual void OnCreate(string packageName, string rootDirectory)
{ {
PackageName = packageName; PackageName = packageName;
@ -148,6 +170,15 @@ namespace YooAsset
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion); string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
return PathUtility.Combine(FileRoot, fileName); return PathUtility.Combine(FileRoot, fileName);
} }
public int GetAsyncSimulateFrame()
{
if (_asyncSimulateMinFrame > _asyncSimulateMaxFrame)
{
_asyncSimulateMinFrame = _asyncSimulateMaxFrame;
}
return UnityEngine.Random.Range(_asyncSimulateMinFrame, _asyncSimulateMaxFrame + 1);
}
#endregion #endregion
} }
} }

View File

@ -3,8 +3,19 @@ namespace YooAsset
{ {
internal class DEFSLoadBundleOperation : FSLoadBundleOperation internal class DEFSLoadBundleOperation : FSLoadBundleOperation
{ {
protected enum ESteps
{
None,
DownloadFile,
LoadAssetBundle,
CheckResult,
Done,
}
private readonly DefaultEditorFileSystem _fileSystem; private readonly DefaultEditorFileSystem _fileSystem;
private readonly PackageBundle _bundle; private readonly PackageBundle _bundle;
private int _asyncSimulateFrame;
private ESteps _steps = ESteps.None;
internal DEFSLoadBundleOperation(DefaultEditorFileSystem fileSystem, PackageBundle bundle) internal DEFSLoadBundleOperation(DefaultEditorFileSystem fileSystem, PackageBundle bundle)
{ {
@ -13,15 +24,53 @@ namespace YooAsset
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
DownloadProgress = 1f; _steps = ESteps.DownloadFile;
DownloadedBytes = _bundle.FileSize;
Status = EOperationStatus.Succeed;
} }
internal override void InternalOnUpdate() 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() internal override void InternalWaitForAsyncComplete()
{ {
while (true)
{
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
}
} }
public override void AbortDownloadOperation() public override void AbortDownloadOperation()
{ {

View File

@ -1,7 +1,7 @@
 
namespace YooAsset namespace YooAsset
{ {
internal class FileSystemParametersDefine public class FileSystemParametersDefine
{ {
public const string FILE_VERIFY_LEVEL = "FILE_VERIFY_LEVEL"; public const string FILE_VERIFY_LEVEL = "FILE_VERIFY_LEVEL";
public const string REMOTE_SERVICES = "REMOTE_SERVICES"; 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 DISABLE_UNITY_WEB_CACHE = "DISABLE_UNITY_WEB_CACHE";
public const string RESUME_DOWNLOAD_MINMUM_SIZE = "RESUME_DOWNLOAD_MINMUM_SIZE"; 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 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";
} }
} }

View File

@ -147,7 +147,7 @@ namespace YooAsset
// 当执行次数用完时 // 当执行次数用完时
_whileFrame--; _whileFrame--;
if (_whileFrame == 0) if (_whileFrame <= 0)
{ {
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Operation {this.GetType().Name} failed to wait for async complete !"; Error = $"Operation {this.GetType().Name} failed to wait for async complete !";

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a9ca0d0d29eb5294b9c6926c6a09e76b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@

namespace YooAsset
{
internal class VirtualBundle
{
private readonly IFileSystem _fileSystem;
private readonly PackageBundle _packageBundle;
internal VirtualBundle(IFileSystem fileSystem, PackageBundle packageBundle)
{
_fileSystem = fileSystem;
_packageBundle = packageBundle;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 822bb85f05144d842977dda341174db2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -69,6 +69,9 @@ namespace YooAsset
if (_loadBundleOp == null) if (_loadBundleOp == null)
_loadBundleOp = BundleFileInfo.LoadBundleFile(); _loadBundleOp = BundleFileInfo.LoadBundleFile();
if (IsWaitForAsyncComplete)
_loadBundleOp.WaitForAsyncComplete();
DownloadProgress = _loadBundleOp.DownloadProgress; DownloadProgress = _loadBundleOp.DownloadProgress;
DownloadedBytes = _loadBundleOp.DownloadedBytes; DownloadedBytes = _loadBundleOp.DownloadedBytes;
if (_loadBundleOp.IsDone == false) if (_loadBundleOp.IsDone == false)
@ -101,9 +104,6 @@ namespace YooAsset
{ {
while (true) while (true)
{ {
if (_loadBundleOp != null)
_loadBundleOp.WaitForAsyncComplete();
if (ExecuteWhileDone()) if (ExecuteWhileDone())
{ {
_steps = ESteps.Done; _steps = ESteps.Done;

View File

@ -36,6 +36,14 @@ namespace YooAsset
if (_steps == ESteps.CheckDepend) if (_steps == ESteps.CheckDepend)
{ {
if (IsWaitForAsyncComplete)
{
foreach (var loader in Depends)
{
loader.WaitForAsyncComplete();
}
}
foreach (var loader in Depends) foreach (var loader in Depends)
{ {
if (loader.IsDone == false) if (loader.IsDone == false)
@ -73,11 +81,6 @@ namespace YooAsset
{ {
while (true) while (true)
{ {
foreach (var loader in Depends)
{
loader.WaitForAsyncComplete();
}
if (ExecuteWhileDone()) if (ExecuteWhileDone())
{ {
_steps = ESteps.Done; _steps = ESteps.Done;

View File

@ -96,6 +96,7 @@ namespace YooAsset
{ {
if (LoadDependBundleFileOp != null) if (LoadDependBundleFileOp != null)
LoadDependBundleFileOp.WaitForAsyncComplete(); LoadDependBundleFileOp.WaitForAsyncComplete();
if (LoadBundleFileOp != null) if (LoadBundleFileOp != null)
LoadBundleFileOp.WaitForAsyncComplete(); LoadBundleFileOp.WaitForAsyncComplete();

View File

@ -176,6 +176,16 @@ namespace YooAsset
} }
#endif #endif
} }
// 检测文件系统参数
if (_playMode == EPlayMode.WebPlayMode)
{
var webPlayModeParams = parameters as WebPlayModeParameters;
var fileSystemClassName = webPlayModeParams.WebFileSystemParameters.FileSystemClass;
if (fileSystemClassName == typeof(DefaultCacheFileSystem).FullName
|| fileSystemClassName == typeof(DefaultBuildinFileSystem).FullName)
throw new Exception($"{fileSystemClassName} not support {nameof(EPlayMode.WebPlayMode)}");
}
} }
private void InitializeOperation_Completed(AsyncOperationBase op) private void InitializeOperation_Completed(AsyncOperationBase op)
{ {