【m】框架大更新

This commit is contained in:
2025-10-31 11:18:23 +08:00
parent ae6e7c804b
commit 8e1d52ddbf
1883 changed files with 213934 additions and 640 deletions

View File

@@ -0,0 +1,20 @@
namespace YooAsset
{
internal class DEFSInitializeOperation : FSInitializeFileSystemOperation
{
private readonly DefaultEditorFileSystem _fileSytem;
internal DEFSInitializeOperation(DefaultEditorFileSystem fileSystem)
{
_fileSytem = fileSystem;
}
internal override void InternalStart()
{
Status = EOperationStatus.Succeed;
}
internal override void InternalUpdate()
{
}
}
}

View File

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

View File

@@ -0,0 +1,126 @@
namespace YooAsset
{
internal class DEFSLoadBundleOperation : FSLoadBundleOperation
{
protected enum ESteps
{
None,
CheckExist,
DownloadFile,
LoadAssetBundle,
CheckResult,
Done,
}
private readonly DefaultEditorFileSystem _fileSystem;
private readonly PackageBundle _bundle;
protected FSDownloadFileOperation _downloadFileOp;
private int _asyncSimulateFrame;
private ESteps _steps = ESteps.None;
internal DEFSLoadBundleOperation(DefaultEditorFileSystem fileSystem, PackageBundle bundle)
{
_fileSystem = fileSystem;
_bundle = bundle;
}
internal override void InternalStart()
{
_steps = ESteps.CheckExist;
_asyncSimulateFrame = _fileSystem.GetAsyncSimulateFrame();
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CheckExist)
{
if (_fileSystem.Exists(_bundle))
{
DownloadProgress = 1f;
DownloadedBytes = _bundle.FileSize;
_steps = ESteps.LoadAssetBundle;
}
else
{
_steps = ESteps.DownloadFile;
}
}
if (_steps == ESteps.DownloadFile)
{
if (_downloadFileOp == null)
{
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
_downloadFileOp.StartOperation();
AddChildOperation(_downloadFileOp);
}
if (IsWaitForAsyncComplete)
_downloadFileOp.WaitForAsyncComplete();
_downloadFileOp.UpdateOperation();
DownloadProgress = _downloadFileOp.DownloadProgress;
DownloadedBytes = _downloadFileOp.DownloadedBytes;
if (_downloadFileOp.IsDone == false)
return;
if (_downloadFileOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadAssetBundle;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloadFileOp.Error;
}
}
if (_steps == ESteps.LoadAssetBundle)
{
if (IsWaitForAsyncComplete)
{
if (_fileSystem.VirtualWebGLMode)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Virtual WebGL Mode only support asyn load method !";
YooLogger.Error(Error);
}
else
{
_steps = ESteps.CheckResult;
}
}
else
{
if (_asyncSimulateFrame <= 0)
_steps = ESteps.CheckResult;
else
_asyncSimulateFrame--;
}
}
if (_steps == ESteps.CheckResult)
{
_steps = ESteps.Done;
Result = new VirtualBundleResult(_fileSystem, _bundle);
Status = EOperationStatus.Succeed;
}
}
internal override void InternalWaitForAsyncComplete()
{
while (true)
{
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,90 @@
namespace YooAsset
{
internal class DEFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
{
private enum ESteps
{
None,
LoadEditorPackageHash,
LoadEditorPackageManifest,
Done,
}
private readonly DefaultEditorFileSystem _fileSystem;
private readonly string _packageVersion;
private LoadEditorPackageHashOperation _loadEditorPackageHashOpe;
private LoadEditorPackageManifestOperation _loadEditorPackageManifestOp;
private ESteps _steps = ESteps.None;
internal DEFSLoadPackageManifestOperation(DefaultEditorFileSystem fileSystem, string packageVersion)
{
_fileSystem = fileSystem;
_packageVersion = packageVersion;
}
internal override void InternalStart()
{
_steps = ESteps.LoadEditorPackageHash;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadEditorPackageHash)
{
if (_loadEditorPackageHashOpe == null)
{
_loadEditorPackageHashOpe = new LoadEditorPackageHashOperation(_fileSystem, _packageVersion);
_loadEditorPackageHashOpe.StartOperation();
AddChildOperation(_loadEditorPackageHashOpe);
}
_loadEditorPackageHashOpe.UpdateOperation();
if (_loadEditorPackageHashOpe.IsDone == false)
return;
if (_loadEditorPackageHashOpe.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadEditorPackageManifest;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadEditorPackageHashOpe.Error;
}
}
if (_steps == ESteps.LoadEditorPackageManifest)
{
if (_loadEditorPackageManifestOp == null)
{
string packageHash = _loadEditorPackageHashOpe.PackageHash;
_loadEditorPackageManifestOp = new LoadEditorPackageManifestOperation(_fileSystem, _packageVersion, packageHash);
_loadEditorPackageManifestOp.StartOperation();
AddChildOperation(_loadEditorPackageManifestOp);
}
_loadEditorPackageManifestOp.UpdateOperation();
Progress = _loadEditorPackageManifestOp.Progress;
if (_loadEditorPackageManifestOp.IsDone == false)
return;
if (_loadEditorPackageManifestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Manifest = _loadEditorPackageManifestOp.Manifest;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadEditorPackageManifestOp.Error;
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,59 @@
namespace YooAsset
{
internal class DEFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
{
private enum ESteps
{
None,
LoadPackageVersion,
Done,
}
private readonly DefaultEditorFileSystem _fileSystem;
private LoadEditorPackageVersionOperation _loadEditorPackageVersionOp;
private ESteps _steps = ESteps.None;
internal DEFSRequestPackageVersionOperation(DefaultEditorFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalStart()
{
_steps = ESteps.LoadPackageVersion;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadPackageVersion)
{
if (_loadEditorPackageVersionOp == null)
{
_loadEditorPackageVersionOp = new LoadEditorPackageVersionOperation(_fileSystem);
_loadEditorPackageVersionOp.StartOperation();
AddChildOperation(_loadEditorPackageVersionOp);
}
_loadEditorPackageVersionOp.UpdateOperation();
if (_loadEditorPackageVersionOp.IsDone == false)
return;
if (_loadEditorPackageVersionOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
PackageVersion = _loadEditorPackageVersionOp.PackageVersion;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadEditorPackageVersionOp.Error;
}
}
}
}
}

View File

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

View File

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

View File

@@ -0,0 +1,156 @@
using UnityEngine;
namespace YooAsset
{
internal class DownloadVirtualBundleOperation : FSDownloadFileOperation
{
protected enum ESteps
{
None,
CheckExists,
CreateRequest,
CheckRequest,
TryAgain,
Done,
}
// 下载参数
protected readonly DefaultEditorFileSystem _fileSystem;
protected readonly DownloadFileOptions _options;
protected UnityVirtualBundleRequestOperation _unityDownloadFileOp;
protected int _requestCount = 0;
protected float _tryAgainTimer;
protected int _failedTryAgain;
private ESteps _steps = ESteps.None;
internal DownloadVirtualBundleOperation(DefaultEditorFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
{
_fileSystem = fileSystem;
_options = options;
_failedTryAgain = options.FailedTryAgain;
}
internal override void InternalStart()
{
_steps = ESteps.CheckExists;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
// 检测文件是否存在
if (_steps == ESteps.CheckExists)
{
if (_fileSystem.Exists(Bundle))
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.CreateRequest;
}
}
// 创建下载器
if (_steps == ESteps.CreateRequest)
{
if (_options.IsValid() == false)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Download file options is invalid !";
Debug.Log(Error);
return;
}
string url = GetRequestURL();
int speed = _fileSystem.VirtualDownloadSpeed;
_unityDownloadFileOp = new UnityVirtualBundleRequestOperation(Bundle, speed, url);
_unityDownloadFileOp.StartOperation();
_steps = ESteps.CheckRequest;
}
// 检测下载结果
if (_steps == ESteps.CheckRequest)
{
if (IsWaitForAsyncComplete)
_unityDownloadFileOp.WaitForAsyncComplete();
// 因为并发数量限制,下载器可能被挂起!
if (_unityDownloadFileOp.Status == EOperationStatus.None)
return;
_unityDownloadFileOp.UpdateOperation();
Progress = _unityDownloadFileOp.Progress;
DownloadedBytes = _unityDownloadFileOp.DownloadedBytes;
DownloadProgress = _unityDownloadFileOp.DownloadProgress;
if (_unityDownloadFileOp.IsDone == false)
return;
if (_unityDownloadFileOp.Status == EOperationStatus.Succeed)
{
_fileSystem.RecordDownloadFile(Bundle);
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
if (IsWaitForAsyncComplete == false && _failedTryAgain > 0)
{
_steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_unityDownloadFileOp.URL} Try again !");
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _unityDownloadFileOp.Error;
YooLogger.Error(Error);
}
}
}
// 重新尝试下载
if (_steps == ESteps.TryAgain)
{
_tryAgainTimer += Time.unscaledDeltaTime;
if (_tryAgainTimer > 1f)
{
_tryAgainTimer = 0f;
_failedTryAgain--;
Progress = 0f;
DownloadProgress = 0f;
DownloadedBytes = 0;
_steps = ESteps.CreateRequest;
}
}
}
internal override void InternalWaitForAsyncComplete()
{
while (true)
{
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
}
}
/// <summary>
/// 获取网络请求地址
/// </summary>
protected string GetRequestURL()
{
// 轮流返回请求地址
_requestCount++;
if (_requestCount % 2 == 0)
return _options.FallbackURL;
else
return _options.MainURL;
}
}
}

View File

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

View File

@@ -0,0 +1,56 @@
using System.IO;
namespace YooAsset
{
internal class LoadEditorPackageHashOperation : AsyncOperationBase
{
private enum ESteps
{
None,
LoadHash,
Done,
}
private readonly DefaultEditorFileSystem _fileSystem;
private readonly string _packageVersion;
private ESteps _steps = ESteps.None;
/// <summary>
/// 包裹哈希值
/// </summary>
public string PackageHash { private set; get; }
internal LoadEditorPackageHashOperation(DefaultEditorFileSystem fileSystem, string packageVersion)
{
_fileSystem = fileSystem;
_packageVersion = packageVersion;
}
internal override void InternalStart()
{
_steps = ESteps.LoadHash;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadHash)
{
string hashFilePath = _fileSystem.GetEditorPackageHashFilePath(_packageVersion);
if (File.Exists(hashFilePath))
{
_steps = ESteps.Done;
PackageHash = FileUtility.ReadAllText(hashFilePath);
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Can not found simulation package hash file : {hashFilePath}";
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,107 @@
using System.IO;
namespace YooAsset
{
internal class LoadEditorPackageManifestOperation : AsyncOperationBase
{
private enum ESteps
{
None,
LoadFileData,
VerifyFileData,
LoadManifest,
Done,
}
private readonly DefaultEditorFileSystem _fileSystem;
private readonly string _packageVersion;
private readonly string _packageHash;
private DeserializeManifestOperation _deserializer;
private byte[] _fileData;
private ESteps _steps = ESteps.None;
/// <summary>
/// 包裹清单
/// </summary>
public PackageManifest Manifest { private set; get; }
internal LoadEditorPackageManifestOperation(DefaultEditorFileSystem fileSystem, string packageVersion, string packageHash)
{
_fileSystem = fileSystem;
_packageVersion = packageVersion;
_packageHash = packageHash;
}
internal override void InternalStart()
{
_steps = ESteps.LoadFileData;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadFileData)
{
string manifestFilePath = _fileSystem.GetEditorPackageManifestFilePath(_packageVersion);
if (File.Exists(manifestFilePath))
{
_steps = ESteps.VerifyFileData;
_fileData = FileUtility.ReadAllBytes(manifestFilePath);
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Can not found simulation package manifest file : {manifestFilePath}";
}
}
if (_steps == ESteps.VerifyFileData)
{
if (ManifestTools.VerifyManifestData(_fileData, _packageHash))
{
_steps = ESteps.LoadManifest;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to verify simulation package manifest file !";
}
}
if (_steps == ESteps.LoadManifest)
{
if (_deserializer == null)
{
_deserializer = new DeserializeManifestOperation(null, _fileData);
_deserializer.StartOperation();
AddChildOperation(_deserializer);
}
_deserializer.UpdateOperation();
Progress = _deserializer.Progress;
if (_deserializer.IsDone == false)
return;
if (_deserializer.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Manifest = _deserializer.Manifest;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _deserializer.Error;
}
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
}
}
}

View File

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

View File

@@ -0,0 +1,54 @@
using System.IO;
namespace YooAsset
{
internal class LoadEditorPackageVersionOperation : AsyncOperationBase
{
private enum ESteps
{
None,
LoadVersion,
Done,
}
private readonly DefaultEditorFileSystem _fileSystem;
private ESteps _steps = ESteps.None;
/// <summary>
/// 包裹版本
/// </summary>
public string PackageVersion { private set; get; }
internal LoadEditorPackageVersionOperation(DefaultEditorFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalStart()
{
_steps = ESteps.LoadVersion;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadVersion)
{
string versionFilePath = _fileSystem.GetEditorPackageVersionFilePath();
if (File.Exists(versionFilePath))
{
_steps = ESteps.Done;
PackageVersion = FileUtility.ReadAllText(versionFilePath);
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Can not found simulation package version file : {versionFilePath}";
}
}
}
}
}

View File

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