mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-25 10:11:51 +00:00
Compare commits
19 Commits
yoo3
...
0a1c81faf1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a1c81faf1 | ||
|
|
e10888de93 | ||
|
|
da222c6179 | ||
|
|
3e3661ad95 | ||
|
|
611ac886b3 | ||
|
|
b0e85017d2 | ||
|
|
2b6e7856e7 | ||
|
|
8d461056e4 | ||
|
|
f188cc715a | ||
|
|
329cae1441 | ||
|
|
c8c74b8c20 | ||
|
|
b3d024743c | ||
|
|
246a62a675 | ||
|
|
354ca5197f | ||
|
|
ce4d6911db | ||
|
|
b796b1a44e | ||
|
|
7198e639d9 | ||
|
|
294fa18fec | ||
|
|
a3f689d815 |
@@ -19,7 +19,7 @@ namespace YooAsset.Editor
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = EBuildPipeline.EditorSimulateBuildPipeline.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBuildBundleType.VirtualBundle;
|
||||
buildParameters.BuildBundleType = (int)EBundleType.VirtualBundle;
|
||||
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
buildParameters.PackageName = packageName;
|
||||
buildParameters.PackageVersion = "Simulate";
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 资源包加密服务类
|
||||
/// </summary>
|
||||
public IEncryptionServices EncryptionServices;
|
||||
public IBundleEncryptionServices EncryptionServices;
|
||||
|
||||
/// <summary>
|
||||
/// 资源清单加密服务类
|
||||
@@ -146,7 +146,7 @@ namespace YooAsset.Editor
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineIsNullOrEmpty, "Build pipeline is null or empty !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
if (BuildBundleType == (int)EBuildBundleType.Unknown)
|
||||
if (BuildBundleType == (int)EBundleType.Unknown)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildBundleTypeIsUnknown, $"Build bundle type is unknown {BuildBundleType} !");
|
||||
throw new Exception(message);
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace YooAsset.Editor
|
||||
string buildinRootDirectory = buildParametersContext.GetBuildinRootDirectory();
|
||||
string buildPackageName = buildParametersContext.Parameters.PackageName;
|
||||
var manifestServices = buildParametersContext.Parameters.ManifestRestoreServices;
|
||||
CatalogTools.CreateCatalogFile(manifestServices, buildPackageName, buildinRootDirectory);
|
||||
CatalogFileHelper.CreateFile(manifestServices, buildPackageName, buildinRootDirectory);
|
||||
|
||||
// 刷新目录
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 创建新补丁清单
|
||||
PackageManifest manifest = new PackageManifest();
|
||||
manifest.FileVersion = ManifestDefine.FileVersion;
|
||||
manifest.FileVersion = PackageManifestDefine.FileVersion;
|
||||
manifest.EnableAddressable = buildMapContext.Command.EnableAddressable;
|
||||
manifest.SupportExtensionless = buildMapContext.Command.SupportExtensionless;
|
||||
manifest.LocationToLower = buildMapContext.Command.LocationToLower;
|
||||
@@ -71,7 +71,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestJsonFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
ManifestTools.SerializeToJson(filePath, manifest);
|
||||
PackageManifestTools.SerializeToJson(filePath, manifest);
|
||||
BuildLogger.Log($"Create package manifest file: {filePath}");
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
packagePath = $"{packageOutputDirectory}/{fileName}";
|
||||
ManifestTools.SerializeToBinary(packagePath, manifest, buildParameters.ManifestProcessServices);
|
||||
PackageManifestTools.SerializeToBinary(packagePath, manifest, buildParameters.ManifestProcessServices);
|
||||
packageHash = HashUtility.FileCRC32(packagePath);
|
||||
BuildLogger.Log($"Create package manifest file: {packagePath}");
|
||||
}
|
||||
@@ -106,7 +106,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
ManifestContext manifestContext = new ManifestContext();
|
||||
byte[] bytesData = FileUtility.ReadAllBytes(packagePath);
|
||||
manifestContext.Manifest = ManifestTools.DeserializeFromBinary(bytesData, buildParameters.ManifestRestoreServices);
|
||||
manifestContext.Manifest = PackageManifestTools.DeserializeFromBinary(bytesData, buildParameters.ManifestRestoreServices);
|
||||
context.SetContextObject(manifestContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace YooAsset.Editor
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
foreach (var bundleInfo in buildMapContext.Collection)
|
||||
{
|
||||
EncryptFileInfo fileInfo = new EncryptFileInfo();
|
||||
EncryptBundleInfo fileInfo = new EncryptBundleInfo();
|
||||
fileInfo.BundleName = bundleInfo.BundleName;
|
||||
fileInfo.FileLoadPath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
var encryptResult = encryptionServices.Encrypt(fileInfo);
|
||||
|
||||
@@ -54,8 +54,8 @@ namespace YooAsset.Editor
|
||||
{
|
||||
string bundleName = bundleInfo.BundleName;
|
||||
string fileHash = bundleInfo.PackageFileHash;
|
||||
string fileExtension = ManifestTools.GetRemoteBundleFileExtension(bundleName);
|
||||
string fileName = ManifestTools.GetRemoteBundleFileName(outputNameStyle, bundleName, fileExtension, fileHash);
|
||||
string fileExtension = PackageManifestTools.GetRemoteBundleFileExtension(bundleName);
|
||||
string fileName = PackageManifestTools.GetRemoteBundleFileName(outputNameStyle, bundleName, fileExtension, fileHash);
|
||||
bundleInfo.PackageDestFilePath = $"{packageOutputDirectory}/{fileName}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class EncryptionNone : IEncryptionServices
|
||||
public class EncryptionNone : IBundleEncryptionServices
|
||||
{
|
||||
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||||
public EncryptResult Encrypt(EncryptBundleInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -46,13 +46,13 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 创建资源包加密服务类实例
|
||||
/// </summary>
|
||||
protected IEncryptionServices CreateEncryptionServicesInstance()
|
||||
protected IBundleEncryptionServices CreateEncryptionServicesInstance()
|
||||
{
|
||||
var className = AssetBundleBuilderSetting.GetPackageEncyptionServicesClassName(PackageName, PipelineName);
|
||||
var classTypes = EditorTools.GetAssignableTypes(typeof(IEncryptionServices));
|
||||
var classTypes = EditorTools.GetAssignableTypes(typeof(IBundleEncryptionServices));
|
||||
var classType = classTypes.Find(x => x.FullName.Equals(className));
|
||||
if (classType != null)
|
||||
return (IEncryptionServices)Activator.CreateInstance(classType);
|
||||
return (IBundleEncryptionServices)Activator.CreateInstance(classType);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
@@ -184,7 +184,7 @@ namespace YooAsset.Editor
|
||||
protected PopupField<Type> CreateEncryptionServicesField(VisualElement container)
|
||||
{
|
||||
// 资源包加密服务类
|
||||
var classTypes = EditorTools.GetAssignableTypes(typeof(IEncryptionServices));
|
||||
var classTypes = EditorTools.GetAssignableTypes(typeof(IBundleEncryptionServices));
|
||||
if (classTypes.Count > 0)
|
||||
{
|
||||
var className = AssetBundleBuilderSetting.GetPackageEncyptionServicesClassName(PackageName, PipelineName);
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace YooAsset.Editor
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = PipelineName.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle;
|
||||
buildParameters.BuildBundleType = (int)EBundleType.AssetBundle;
|
||||
buildParameters.BuildTarget = BuildTarget;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = _buildVersionField.value;
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace YooAsset.Editor
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = PipelineName.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBuildBundleType.VirtualBundle;
|
||||
buildParameters.BuildBundleType = (int)EBundleType.VirtualBundle;
|
||||
buildParameters.BuildTarget = BuildTarget;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = _buildVersionField.value;
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace YooAsset.Editor
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = PipelineName.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBuildBundleType.RawBundle;
|
||||
buildParameters.BuildBundleType = (int)EBundleType.RawBundle;
|
||||
buildParameters.BuildTarget = BuildTarget;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = _buildVersionField.value;
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace YooAsset.Editor
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = PipelineName.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle;
|
||||
buildParameters.BuildBundleType = (int)EBundleType.AssetBundle;
|
||||
buildParameters.BuildTarget = BuildTarget;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = _buildVersionField.value;
|
||||
|
||||
@@ -277,7 +277,7 @@ namespace YooAsset.Editor
|
||||
if (dependTableData.BundleInfo.Encrypted)
|
||||
return;
|
||||
|
||||
if (_buildReport.Summary.BuildBundleType == (int)EBuildBundleType.AssetBundle)
|
||||
if (_buildReport.Summary.BuildBundleType == (int)EBundleType.AssetBundle)
|
||||
{
|
||||
string rootDirectory = Path.GetDirectoryName(_reportFilePath);
|
||||
string filePath = $"{rootDirectory}/{dependTableData.BundleInfo.FileName}";
|
||||
|
||||
@@ -348,7 +348,7 @@ namespace YooAsset.Editor
|
||||
if (bundleTableData.BundleInfo.Encrypted)
|
||||
return;
|
||||
|
||||
if (_buildReport.Summary.BuildBundleType == (int)EBuildBundleType.AssetBundle)
|
||||
if (_buildReport.Summary.BuildBundleType == (int)EBundleType.AssetBundle)
|
||||
{
|
||||
string rootDirectory = Path.GetDirectoryName(_reportFilePath);
|
||||
string filePath = $"{rootDirectory}/{bundleTableData.BundleInfo.FileName}";
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace YooAsset
|
||||
public void Register(Guid messageID, UnityAction<MessageEventArgs> callback)
|
||||
{
|
||||
if (messageID == Guid.Empty)
|
||||
throw new ArgumentException("messageID is empty !");
|
||||
throw new ArgumentException("messageID is empty.");
|
||||
|
||||
if (_messageCallbacks.ContainsKey(messageID) == false)
|
||||
_messageCallbacks.Add(messageID, callback);
|
||||
@@ -49,7 +49,7 @@ namespace YooAsset
|
||||
public void Send(Guid messageID, byte[] data)
|
||||
{
|
||||
if (messageID == Guid.Empty)
|
||||
throw new ArgumentException("messageID is empty !");
|
||||
throw new ArgumentException("messageID is empty.");
|
||||
|
||||
// 接收对方的消息
|
||||
RemotePlayerConnection.Instance.HandleEditorMessage(messageID, data);
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace YooAsset
|
||||
public void Register(Guid messageID, UnityAction<MessageEventArgs> callback)
|
||||
{
|
||||
if (messageID == Guid.Empty)
|
||||
throw new ArgumentException("messageID is empty !");
|
||||
throw new ArgumentException("messageID is empty.");
|
||||
|
||||
if (_messageCallbacks.ContainsKey(messageID) == false)
|
||||
_messageCallbacks.Add(messageID, callback);
|
||||
@@ -49,7 +49,7 @@ namespace YooAsset
|
||||
public void Send(Guid messageID, byte[] data)
|
||||
{
|
||||
if (messageID == Guid.Empty)
|
||||
throw new ArgumentException("messageID is empty !");
|
||||
throw new ArgumentException("messageID is empty.");
|
||||
|
||||
// 接收对方的消息
|
||||
RemoteEditorConnection.Instance.HandlePlayerMessage(messageID, data);
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace YooAsset
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(_args.FileHash))
|
||||
throw new YooInternalException("File hash is null or empty !");
|
||||
throw new YooInternalException("File hash is null or empty.");
|
||||
|
||||
// 使用 Unity 缓存
|
||||
// 说明:The file hash defining the version of the asset bundle.
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace YooAsset
|
||||
catch (Exception ex)
|
||||
{
|
||||
Status = EDownloadRequestStatus.Failed;
|
||||
Error = $"[{GetType().Name}] Failed to create web request : {ex.Message}";
|
||||
Error = $"[{GetType().Name}] Failed to create web request: {ex.Message}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ namespace YooAsset
|
||||
else
|
||||
{
|
||||
Status = EDownloadRequestStatus.Failed;
|
||||
Error = $"[{GetType().Name}] URL: {URL} - 错误: {_webRequest.error}";
|
||||
Error = $"[{GetType().Name}] URL: {URL} - Error: {_webRequest.error}";
|
||||
OnRequestFailed();
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ namespace YooAsset
|
||||
protected void ApplyRequestOptions(int timeout, int watchdogTime, Dictionary<string, string> headers)
|
||||
{
|
||||
if (_webRequest == null)
|
||||
throw new YooInternalException("Web request is null !");
|
||||
throw new YooInternalException("Web request is null.");
|
||||
|
||||
// 设置看门狗超时时间
|
||||
_watchdogTime = watchdogTime;
|
||||
@@ -255,12 +255,7 @@ namespace YooAsset
|
||||
if (_watchdogAborted)
|
||||
return;
|
||||
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
double realtimeSinceStartup = UnityEngine.Time.realtimeSinceStartupAsDouble;
|
||||
#else
|
||||
double realtimeSinceStartup = UnityEngine.Time.realtimeSinceStartup;
|
||||
#endif
|
||||
|
||||
double realtimeSinceStartup = TimeUtility.RealtimeSinceStartup;
|
||||
if (DownloadedBytes != _lastDownloadBytes)
|
||||
{
|
||||
_lastDownloadBytes = DownloadedBytes;
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace YooAsset
|
||||
if (Status == EDownloadRequestStatus.None)
|
||||
{
|
||||
Status = EDownloadRequestStatus.Running;
|
||||
_lastUpdateTime = GetUnityEngineRealtime();
|
||||
_lastUpdateTime = TimeUtility.RealtimeSinceStartup;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace YooAsset
|
||||
if (Status != EDownloadRequestStatus.Running)
|
||||
return;
|
||||
|
||||
double currentTime = GetUnityEngineRealtime();
|
||||
double currentTime = TimeUtility.RealtimeSinceStartup;
|
||||
double deltaTime = currentTime - _lastUpdateTime;
|
||||
_lastUpdateTime = currentTime;
|
||||
|
||||
@@ -137,14 +137,5 @@ namespace YooAsset
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
private double GetUnityEngineRealtime()
|
||||
{
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
return UnityEngine.Time.realtimeSinceStartupAsDouble;
|
||||
#else
|
||||
return UnityEngine.Time.realtimeSinceStartup;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,103 +3,9 @@ using System.Collections.Generic;
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载器结束
|
||||
/// 导入的资源包信息
|
||||
/// </summary>
|
||||
public struct DownloaderFinishData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 是否成功
|
||||
/// </summary>
|
||||
public bool Succeed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载器相关的更新数据
|
||||
/// </summary>
|
||||
public struct DownloadUpdateData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度 (0-1f)
|
||||
/// </summary>
|
||||
public float Progress;
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件总数
|
||||
/// </summary>
|
||||
public int TotalDownloadCount;
|
||||
|
||||
/// <summary>
|
||||
/// 当前完成的下载文件数量
|
||||
/// </summary>
|
||||
public int CurrentDownloadCount;
|
||||
|
||||
/// <summary>
|
||||
/// 下载数据总大小(单位:字节)
|
||||
/// </summary>
|
||||
public long TotalDownloadBytes;
|
||||
|
||||
/// <summary>
|
||||
/// 当前完成的下载数据大小(单位:字节)
|
||||
/// </summary>
|
||||
public long CurrentDownloadBytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载器相关的错误数据
|
||||
/// </summary>
|
||||
public struct DownloadErrorData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载失败的文件名称
|
||||
/// </summary>
|
||||
public string FileName;
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
public string ErrorInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载器相关的文件数据
|
||||
/// </summary>
|
||||
public struct DownloadFileData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载的文件名称
|
||||
/// </summary>
|
||||
public string FileName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载的文件大小
|
||||
/// </summary>
|
||||
public long FileSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入文件的信息
|
||||
/// </summary>
|
||||
public struct ImportFileInfo
|
||||
public struct ImportBundleInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 本地文件路径
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace YooAsset
|
||||
#elif UNITY_STANDALONE_LINUX
|
||||
url = StringUtility.Format("file:///root/{0}", path);
|
||||
#else
|
||||
throw new System.NotSupportedException($"[{nameof(DownloadSystemHelper.ConvertToWWWPath)}] not implemented platform: {UnityEngine.Application.platform}");
|
||||
throw new System.NotSupportedException($"[{nameof(DownloadSystemHelper.ConvertToWWWPath)}] Platform '{UnityEngine.Application.platform}' is not supported.");
|
||||
#endif
|
||||
|
||||
// For some special cases when users have special characters in their devices, url paths can not be identified correctly.
|
||||
|
||||
@@ -41,20 +41,20 @@ DownloadSystem 的职责是提供“可替换后端 + 统一请求接口 + 轮
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ 上层调用者 │
|
||||
│ (FileSystem / ResourceManager) │
|
||||
│ 上层调用者 │
|
||||
│ (FileSystem / ResourceManager) │
|
||||
└─────────────────────────┬───────────────────────────────┘
|
||||
│
|
||||
┌─────────────────────────▼───────────────────────────────┐
|
||||
│ IDownloadBackend │
|
||||
│ IDownloadBackend │
|
||||
│ (后端接口) │
|
||||
│ 定义网络库合约,工厂模式创建请求 │
|
||||
│ 定义网络库合约,工厂模式创建请求 │
|
||||
└─────────────────────────┬───────────────────────────────┘
|
||||
│
|
||||
┌─────────────────────────▼───────────────────────────────┐
|
||||
│ IDownloadRequest │
|
||||
│ IDownloadRequest │
|
||||
│ (请求接口) │
|
||||
│ 轮询式生命周期管理,状态机驱动 │
|
||||
│ 轮询式生命周期管理,状态机驱动 │
|
||||
└─────────────────────────┬───────────────────────────────┘
|
||||
│
|
||||
┌─────────────────────────▼───────────────────────────────┐
|
||||
@@ -244,16 +244,6 @@ public struct DownloadSimulateRequestArgs
|
||||
}
|
||||
```
|
||||
|
||||
### 回调数据结构体
|
||||
|
||||
| 结构体 | 用途 | 关键字段 |
|
||||
|--------|------|----------|
|
||||
| `DownloaderFinishData` | 下载完成回调 | `PackageName`, `Succeed` |
|
||||
| `DownloadUpdateData` | 进度更新回调 | `Progress`, `TotalDownloadBytes`, `CurrentDownloadBytes` |
|
||||
| `DownloadErrorData` | 下载错误回调 | `FileName`, `ErrorInfo` |
|
||||
| `DownloadFileData` | 文件完成回调 | `FileName`, `FileSize` |
|
||||
| `ImportFileInfo` | 导入文件元数据 | `FilePath`, `BundleName`, `BundleGUID` |
|
||||
|
||||
---
|
||||
|
||||
## 核心类说明
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace YooAsset
|
||||
if (_assetBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Error = $"The bundle {_packageBundle.BundleName} has been destroyed due to unity engine bugs !";
|
||||
Error = $"The bundle {_packageBundle.BundleName} has been destroyed due to unity engine bugs.";
|
||||
Status = EOperationStatus.Failed;
|
||||
return;
|
||||
}
|
||||
@@ -108,14 +108,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RunBatchExecution();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ namespace YooAsset
|
||||
if (_assetBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Error = $"The bundle {_packageBundle.BundleName} has been destroyed due to unity engine bugs !";
|
||||
Error = $"The bundle {_packageBundle.BundleName} has been destroyed due to unity engine bugs.";
|
||||
Status = EOperationStatus.Failed;
|
||||
return;
|
||||
}
|
||||
@@ -108,14 +108,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RunBatchExecution();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ namespace YooAsset
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
//注意:场景加载无法强制异步转同步
|
||||
YooLogger.Error("The scene is loading asyn !");
|
||||
YooLogger.Error("The scene is loading asyn.");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -107,7 +107,7 @@ namespace YooAsset
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
//注意:场景加载不支持异步转同步,为了支持同步加载方法需要实现该方法!
|
||||
InternalUpdate();
|
||||
RunOnceExecution();
|
||||
}
|
||||
public override void UnSuspendLoad()
|
||||
{
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace YooAsset
|
||||
if (_assetBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Error = $"The bundle {_packageBundle.BundleName} has been destroyed due to unity engine bugs !";
|
||||
Error = $"The bundle {_packageBundle.BundleName} has been destroyed due to unity engine bugs.";
|
||||
Status = EOperationStatus.Failed;
|
||||
return;
|
||||
}
|
||||
@@ -108,14 +108,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RunBatchExecution();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace YooAsset
|
||||
{
|
||||
internal override void InternalStart()
|
||||
{
|
||||
Error = $"{nameof(RawBundleLoadAllAssetsOperation)} not support load all assets !";
|
||||
Error = $"{nameof(RawBundleLoadAllAssetsOperation)} not support load all assets.";
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace YooAsset
|
||||
{
|
||||
internal override void InternalStart()
|
||||
{
|
||||
Error = $"{nameof(RawBundleLoadAssetOperation)} not support load asset !";
|
||||
Error = $"{nameof(RawBundleLoadAssetOperation)} not support load asset.";
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace YooAsset
|
||||
{
|
||||
internal override void InternalStart()
|
||||
{
|
||||
Error = $"{nameof(RawBundleLoadSceneOperation)} not support load scene !";
|
||||
Error = $"{nameof(RawBundleLoadSceneOperation)} not support load scene.";
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace YooAsset
|
||||
{
|
||||
internal override void InternalStart()
|
||||
{
|
||||
Error = $"{nameof(RawBundleLoadSubAssetsOperation)} not support load sub assets !";
|
||||
Error = $"{nameof(RawBundleLoadSubAssetsOperation)} not support load sub assets.";
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace YooAsset
|
||||
_steps = ESteps.CheckBundle;
|
||||
#else
|
||||
_steps = ESteps.Done;
|
||||
Error = $"{nameof(VirtualBundleLoadAllAssetsOperation)} only support unity editor platform !";
|
||||
Error = $"{nameof(VirtualBundleLoadAllAssetsOperation)} only support unity editor platform.";
|
||||
Status = EOperationStatus.Failed;
|
||||
#endif
|
||||
}
|
||||
@@ -109,14 +109,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RunBatchExecution();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace YooAsset
|
||||
_steps = ESteps.CheckBundle;
|
||||
#else
|
||||
_steps = ESteps.Done;
|
||||
Error = $"{nameof(VirtualBundleLoadAssetOperation)} only support unity editor platform !";
|
||||
Error = $"{nameof(VirtualBundleLoadAssetOperation)} only support unity editor platform.";
|
||||
Status = EOperationStatus.Failed;
|
||||
#endif
|
||||
}
|
||||
@@ -88,14 +88,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RunBatchExecution();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace YooAsset
|
||||
_steps = ESteps.LoadScene;
|
||||
#else
|
||||
_steps = ESteps.Done;
|
||||
Error = $"{nameof(VirtualBundleLoadSceneOperation)} only support unity editor platform !";
|
||||
Error = $"{nameof(VirtualBundleLoadSceneOperation)} only support unity editor platform.";
|
||||
Status = EOperationStatus.Failed;
|
||||
#endif
|
||||
}
|
||||
@@ -77,7 +77,7 @@ namespace YooAsset
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
// 注意:场景加载无法强制异步转同步
|
||||
YooLogger.Error("The scene is loading asyn !");
|
||||
YooLogger.Error("The scene is loading asyn.");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -113,7 +113,7 @@ namespace YooAsset
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
//注意:场景加载不支持异步转同步,为了支持同步加载方法需要实现该方法!
|
||||
InternalUpdate();
|
||||
RunOnceExecution();
|
||||
}
|
||||
public override void UnSuspendLoad()
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace YooAsset
|
||||
_steps = ESteps.CheckBundle;
|
||||
#else
|
||||
_steps = ESteps.Done;
|
||||
Error = $"{nameof(VirtualBundleLoadSubAssetsOperation)} only support unity editor platform !";
|
||||
Error = $"{nameof(VirtualBundleLoadSubAssetsOperation)} only support unity editor platform.";
|
||||
Status = EOperationStatus.Failed;
|
||||
#endif
|
||||
}
|
||||
@@ -100,14 +100,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RunBatchExecution();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class CatalogDefine
|
||||
internal class CatalogFileDefine
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件极限大小(100MB)
|
||||
@@ -5,14 +5,14 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal static class CatalogTools
|
||||
internal static class CatalogFileHelper
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// 生成包裹的内置资源目录文件
|
||||
/// 说明:根据指定目录下的文件生成清单文件。
|
||||
/// </summary>
|
||||
public static bool CreateCatalogFile(IManifestRestoreServices services, string packageName, string packageDirectory)
|
||||
public static bool CreateFile(IManifestRestoreServices services, string packageName, string packageDirectory)
|
||||
{
|
||||
// 获取资源清单版本
|
||||
string packageVersion;
|
||||
@@ -40,7 +40,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
var binaryData = FileUtility.ReadAllBytes(manifestFilePath);
|
||||
packageManifest = ManifestTools.DeserializeFromBinary(binaryData, services);
|
||||
packageManifest = PackageManifestTools.DeserializeFromBinary(binaryData, services);
|
||||
}
|
||||
|
||||
// 获取文件名映射关系
|
||||
@@ -54,7 +54,7 @@ namespace YooAsset
|
||||
|
||||
// 创建内置清单实例
|
||||
var buildinFileCatalog = new DefaultBuildinFileCatalog();
|
||||
buildinFileCatalog.FileVersion = CatalogDefine.FileVersion;
|
||||
buildinFileCatalog.FileVersion = CatalogFileDefine.FileVersion;
|
||||
buildinFileCatalog.PackageName = packageName;
|
||||
buildinFileCatalog.PackageVersion = packageVersion;
|
||||
|
||||
@@ -122,11 +122,11 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 生成空的包裹内置资源目录文件
|
||||
/// </summary>
|
||||
public static bool CreateEmptyCatalogFile(string packageName, string packageVersion, string outputPath)
|
||||
public static bool CreateEmptyFile(string packageName, string packageVersion, string outputPath)
|
||||
{
|
||||
// 创建内置清单实例
|
||||
var buildinFileCatalog = new DefaultBuildinFileCatalog();
|
||||
buildinFileCatalog.FileVersion = CatalogDefine.FileVersion;
|
||||
buildinFileCatalog.FileVersion = CatalogFileDefine.FileVersion;
|
||||
buildinFileCatalog.PackageName = packageName;
|
||||
buildinFileCatalog.PackageVersion = packageVersion;
|
||||
|
||||
@@ -173,13 +173,13 @@ namespace YooAsset
|
||||
using (FileStream fs = new FileStream(savePath, FileMode.Create))
|
||||
{
|
||||
// 创建缓存器
|
||||
BufferWriter buffer = new BufferWriter(CatalogDefine.FileMaxSize);
|
||||
BufferWriter buffer = new BufferWriter(CatalogFileDefine.FileMaxSize);
|
||||
|
||||
// 写入文件标记
|
||||
buffer.WriteUInt32(CatalogDefine.FileSign);
|
||||
buffer.WriteUInt32(CatalogFileDefine.FileSign);
|
||||
|
||||
// 写入文件版本
|
||||
buffer.WriteUTF8(CatalogDefine.FileVersion);
|
||||
buffer.WriteUTF8(CatalogFileDefine.FileVersion);
|
||||
|
||||
// 写入文件头信息
|
||||
buffer.WriteUTF8(catalog.PackageName);
|
||||
@@ -206,20 +206,20 @@ namespace YooAsset
|
||||
public static DefaultBuildinFileCatalog DeserializeFromBinary(byte[] binaryData)
|
||||
{
|
||||
if (binaryData == null || binaryData.Length == 0)
|
||||
throw new Exception("Catalog file data is null or empty !");
|
||||
throw new Exception("Catalog file data is null or empty.");
|
||||
|
||||
// 创建缓存器
|
||||
BufferReader buffer = new BufferReader(binaryData);
|
||||
|
||||
// 读取文件标记
|
||||
uint fileSign = buffer.ReadUInt32();
|
||||
if (fileSign != CatalogDefine.FileSign)
|
||||
throw new Exception("Invalid catalog file !");
|
||||
if (fileSign != CatalogFileDefine.FileSign)
|
||||
throw new Exception("Invalid catalog file.");
|
||||
|
||||
// 读取文件版本
|
||||
string fileVersion = buffer.ReadUTF8();
|
||||
if (fileVersion != CatalogDefine.FileVersion)
|
||||
throw new Exception($"The catalog file version are not compatible : {fileVersion} != {CatalogDefine.FileVersion}");
|
||||
if (fileVersion != CatalogFileDefine.FileVersion)
|
||||
throw new Exception($"The catalog file version are not compatible : {fileVersion} != {CatalogFileDefine.FileVersion}");
|
||||
|
||||
DefaultBuildinFileCatalog catalog = new DefaultBuildinFileCatalog();
|
||||
{
|
||||
@@ -107,12 +107,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IDecryptionServices DecryptionServices { private set; get; }
|
||||
public IBundleDecryptionServices BundleDecryptionServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:资源清单服务类
|
||||
/// </summary>
|
||||
public IManifestRestoreServices ManifestServices { private set; get; }
|
||||
public IManifestRestoreServices ManifestRestoreServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:拷贝内置文件接口的实例类
|
||||
@@ -129,39 +129,40 @@ namespace YooAsset
|
||||
var operation = new DBFSInitializeOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new DBFSLoadPackageManifestOperation(this, packageVersion);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
|
||||
{
|
||||
var operation = new DBFSRequestPackageVersionOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options)
|
||||
{
|
||||
return _unpackFileSystem.ClearCacheFilesAsync(manifest, options);
|
||||
var operation = new DBFSLoadPackageManifestOperation(this, options.PackageVersion);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
|
||||
{
|
||||
return _unpackFileSystem.ClearCacheFilesAsync(options);
|
||||
}
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
|
||||
{
|
||||
// 注意:业务层的解压器会依赖该方法
|
||||
options.ImportFilePath = GetBuildinFileLoadPath(bundle);
|
||||
return _unpackFileSystem.DownloadFileAsync(bundle, options);
|
||||
options.ImportFilePath = GetBuildinFileLoadPath(options.Bundle);
|
||||
return _unpackFileSystem.DownloadFileAsync(options);
|
||||
}
|
||||
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||
public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
|
||||
{
|
||||
PackageBundle bundle = options.Bundle;
|
||||
if (IsUnpackBundleFile(bundle))
|
||||
{
|
||||
return _unpackFileSystem.LoadBundleFile(bundle);
|
||||
return _unpackFileSystem.LoadBundleAsync(options);
|
||||
}
|
||||
|
||||
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
|
||||
if (bundle.BundleType == (int)EBundleType.AssetBundle)
|
||||
{
|
||||
var operation = new DBFSLoadAssetBundleOperation(this, bundle);
|
||||
return operation;
|
||||
}
|
||||
else if (bundle.BundleType == (int)EBuildBundleType.RawBundle)
|
||||
else if (bundle.BundleType == (int)EBundleType.RawBundle)
|
||||
{
|
||||
var operation = new DBFSLoadRawBundleOperation(this, bundle);
|
||||
return operation;
|
||||
@@ -224,13 +225,13 @@ namespace YooAsset
|
||||
{
|
||||
UnpackFileSystemRoot = (string)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
|
||||
else if (name == FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES)
|
||||
{
|
||||
DecryptionServices = (IDecryptionServices)value;
|
||||
BundleDecryptionServices = (IBundleDecryptionServices)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.MANIFEST_SERVICES)
|
||||
else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES)
|
||||
{
|
||||
ManifestServices = (IManifestRestoreServices)value;
|
||||
ManifestRestoreServices = (IManifestRestoreServices)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.COPY_LOCAL_FILE_SERVICES)
|
||||
{
|
||||
@@ -264,7 +265,7 @@ namespace YooAsset
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, FileVerifyLevel);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_MAX_CONCURRENCY, FileVerifyMaxConcurrency);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, AppendFileExtension);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, DecryptionServices);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES, BundleDecryptionServices);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.COPY_LOCAL_FILE_SERVICES, CopyLocalFileServices);
|
||||
_unpackFileSystem.OnCreate(packageName, UnpackFileSystemRoot);
|
||||
}
|
||||
@@ -332,14 +333,14 @@ namespace YooAsset
|
||||
|
||||
#if UNITY_ANDROID
|
||||
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
|
||||
YooLogger.Error($"Android platform not support read buildin bundle file data !");
|
||||
YooLogger.Error($"Android platform not support read buildin bundle file data.");
|
||||
return null;
|
||||
#else
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !");
|
||||
YooLogger.Error($"The {nameof(IDecryptionServices)} is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -369,14 +370,14 @@ namespace YooAsset
|
||||
|
||||
#if UNITY_ANDROID
|
||||
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
|
||||
YooLogger.Error($"Android platform not support read buildin bundle file text !");
|
||||
YooLogger.Error($"Android platform not support read buildin bundle file text.");
|
||||
return null;
|
||||
#else
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !");
|
||||
YooLogger.Error($"The {nameof(IDecryptionServices)} is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -409,7 +410,7 @@ namespace YooAsset
|
||||
if (bundle.Encrypted)
|
||||
return true;
|
||||
|
||||
if (bundle.BundleType == (int)EBuildBundleType.RawBundle)
|
||||
if (bundle.BundleType == (int)EBundleType.RawBundle)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@@ -479,31 +480,31 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 加载加密的资源文件
|
||||
/// </summary>
|
||||
public DecryptResult LoadEncryptedAssetBundle(PackageBundle bundle)
|
||||
public DecryptSyncResult LoadEncryptedBundleSync(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
var bundleInfo = new DecryptBundleInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.LoadAssetBundle(fileInfo);
|
||||
return BundleDecryptionServices.LoadAssetBundleSync(bundleInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载加密的资源文件
|
||||
/// </summary>
|
||||
public DecryptResult LoadEncryptedAssetBundleAsync(PackageBundle bundle)
|
||||
public DecryptAsyncResult LoadEncryptedBundleAsync(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
var bundleInfo = new DecryptBundleInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.LoadAssetBundleAsync(fileInfo);
|
||||
return BundleDecryptionServices.LoadAssetBundleAsync(bundleInfo);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace YooAsset
|
||||
#if UNITY_WEBGL
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(DefaultBuildinFileSystem)} is not support WEBGL platform !";
|
||||
Error = $"{nameof(DefaultBuildinFileSystem)} is not support WEBGL platform.";
|
||||
#else
|
||||
if (_fileSystem.CopyBuildinPackageManifest)
|
||||
_steps = ESteps.LoadBuildinPackageVersion;
|
||||
@@ -181,7 +181,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Fatal error : catalog is null !";
|
||||
Error = "Fatal error : catalog is null.";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,205 @@ namespace YooAsset
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadAssetBundle)
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
if (_fileSystem.BundleDecryptionServices == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"The {nameof(IBundleDecryptionServices)} is null.";
|
||||
YooLogger.Error(Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
var decryptResult = _fileSystem.LoadEncryptedBundleSync(_bundle);
|
||||
_assetBundle = decryptResult.Result;
|
||||
_managedStream = decryptResult.ManagedStream;
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||
_assetBundle = AssetBundle.LoadFromFile(filePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
var decryptResult = _fileSystem.LoadEncryptedBundleAsync(_bundle);
|
||||
_createRequest = decryptResult.CreateRequest;
|
||||
_managedStream = decryptResult.ManagedStream;
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (_createRequest != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
// 强制挂起主线程(注意:该操作会很耗时)
|
||||
YooLogger.Warning("Suspend the main thread to load unity bundle.");
|
||||
_assetBundle = _createRequest.assetBundle;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_createRequest.isDone == false)
|
||||
return;
|
||||
_assetBundle = _createRequest.assetBundle;
|
||||
}
|
||||
}
|
||||
|
||||
if (_assetBundle == null)
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load encrypted buildin asset bundle file : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load buildin asset bundle file : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Result = new AssetBundleResult(_fileSystem, _bundle, _assetBundle, _managedStream);
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
RunBatchExecution();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载原生文件
|
||||
/// </summary>
|
||||
internal class DBFSLoadRawBundleOperation : FSLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadBuildinRawBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private readonly PackageBundle _bundle;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal DBFSLoadRawBundleOperation(DefaultBuildinFileSystem fileSystem, PackageBundle bundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_bundle = bundle;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadBuildinRawBundle;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadBuildinRawBundle)
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||
|
||||
#if UNITY_ANDROID
|
||||
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Can not load android buildin raw bundle file : {filePath}";
|
||||
YooLogger.Error(Error);
|
||||
#else
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Result = new RawBundleResult(_fileSystem, _bundle);
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Can not found buildin raw bundle file : {filePath}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
RunBatchExecution();
|
||||
}
|
||||
}
|
||||
|
||||
#if TUANJIE_1_7_OR_NEWER
|
||||
/// <summary>
|
||||
/// 加载团结文件
|
||||
/// </summary>
|
||||
internal class DBFSLoadInstantBundleOperation : FSLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadInstantBundle,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private readonly PackageBundle _bundle;
|
||||
private AssetBundleCreateRequest _createRequest;
|
||||
private AssetBundle _assetBundle;
|
||||
private Stream _managedStream;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal DBFSLoadInstantBundleOperation(DefaultBuildinFileSystem fileSystem, PackageBundle bundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_bundle = bundle;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadInstantBundle;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadInstantBundle)
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
@@ -48,7 +247,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"The {nameof(IDecryptionServices)} is null !";
|
||||
Error = $"The {nameof(IDecryptionServices)} is null.";
|
||||
YooLogger.Error(Error);
|
||||
return;
|
||||
}
|
||||
@@ -131,87 +330,8 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RunBatchExecution();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载原生文件
|
||||
/// </summary>
|
||||
internal class DBFSLoadRawBundleOperation : FSLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadBuildinRawBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private readonly PackageBundle _bundle;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal DBFSLoadRawBundleOperation(DefaultBuildinFileSystem fileSystem, PackageBundle bundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_bundle = bundle;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadBuildinRawBundle;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadBuildinRawBundle)
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||
|
||||
#if UNITY_ANDROID
|
||||
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Can not load android buildin raw bundle file : {filePath}";
|
||||
YooLogger.Error(Error);
|
||||
#else
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Result = new RawBundleResult(_fileSystem, _bundle);
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Can not found buildin raw bundle file : {filePath}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ namespace YooAsset
|
||||
{
|
||||
try
|
||||
{
|
||||
Catalog = CatalogTools.DeserializeFromBinary(_fileData);
|
||||
Catalog = CatalogFileHelper.DeserializeFromBinary(_fileData);
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.VerifyFileData)
|
||||
{
|
||||
if (ManifestTools.VerifyManifestData(_fileData, _packageHash))
|
||||
if (PackageManifestTools.VerifyManifestData(_fileData, _packageHash))
|
||||
{
|
||||
_steps = ESteps.LoadManifest;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to verify buildin package manifest file !";
|
||||
Error = "Failed to verify buildin package manifest file.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_deserializer == null)
|
||||
{
|
||||
_deserializer = new DeserializeManifestOperation(_fileSystem.ManifestServices, _fileData);
|
||||
_deserializer = new DeserializeManifestOperation(_fileSystem.ManifestRestoreServices, _fileData);
|
||||
_deserializer.StartOperation();
|
||||
AddChildOperation(_deserializer);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Buildin package hash file content is empty !";
|
||||
Error = $"Buildin package hash file content is empty.";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Buildin package version file content is empty !";
|
||||
Error = $"Buildin package version file content is empty.";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -129,12 +129,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IDecryptionServices DecryptionServices { private set; get; }
|
||||
public IBundleDecryptionServices BundleDecryptionServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:资源清单服务类
|
||||
/// </summary>
|
||||
public IManifestRestoreServices ManifestServices { private set; get; }
|
||||
public IManifestRestoreServices ManifestRestoreServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:拷贝内置文件接口的实例类
|
||||
@@ -151,17 +151,17 @@ namespace YooAsset
|
||||
var operation = new DCFSInitializeOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
|
||||
{
|
||||
var operation = new DCFSLoadPackageManifestOperation(this, packageVersion, timeout);
|
||||
var operation = new DCFSRequestPackageVersionOperation(this, options.AppendTimeTicks, options.Timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options)
|
||||
{
|
||||
var operation = new DCFSRequestPackageVersionOperation(this, appendTimeTicks, timeout);
|
||||
var operation = new DCFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
|
||||
{
|
||||
if (options.ClearMode == EFileClearMode.ClearAllBundleFiles.ToString())
|
||||
{
|
||||
@@ -170,17 +170,17 @@ namespace YooAsset
|
||||
}
|
||||
else if (options.ClearMode == EFileClearMode.ClearUnusedBundleFiles.ToString())
|
||||
{
|
||||
var operation = new ClearUnusedCacheBundleFilesOperation(this, manifest);
|
||||
var operation = new ClearUnusedCacheBundleFilesOperation(this, options.Manifest);
|
||||
return operation;
|
||||
}
|
||||
else if (options.ClearMode == EFileClearMode.ClearBundleFilesByLocations.ToString())
|
||||
{
|
||||
var operation = new ClearCacheBundleFilesByLocationsOperaiton(this, manifest, options.ClearParam);
|
||||
var operation = new ClearCacheBundleFilesByLocationsOperaiton(this, options.Manifest, options.ClearParam);
|
||||
return operation;
|
||||
}
|
||||
else if (options.ClearMode == EFileClearMode.ClearBundleFilesByTags.ToString())
|
||||
{
|
||||
var operation = new ClearCacheBundleFilesByTagsOperaiton(this, manifest, options.ClearParam);
|
||||
var operation = new ClearCacheBundleFilesByTagsOperaiton(this, options.Manifest, options.ClearParam);
|
||||
return operation;
|
||||
}
|
||||
else if (options.ClearMode == EFileClearMode.ClearAllManifestFiles.ToString())
|
||||
@@ -190,7 +190,7 @@ namespace YooAsset
|
||||
}
|
||||
else if (options.ClearMode == EFileClearMode.ClearUnusedManifestFiles.ToString())
|
||||
{
|
||||
var operation = new ClearUnusedCacheManifestFilesOperation(this, manifest);
|
||||
var operation = new ClearUnusedCacheManifestFilesOperation(this, options.Manifest);
|
||||
return operation;
|
||||
}
|
||||
else
|
||||
@@ -200,9 +200,10 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
|
||||
{
|
||||
// 获取下载地址
|
||||
PackageBundle bundle = options.Bundle;
|
||||
if (string.IsNullOrEmpty(options.ImportFilePath))
|
||||
{
|
||||
// 注意:如果是解压文件系统类,这里会返回本地内置文件的下载路径
|
||||
@@ -217,17 +218,18 @@ namespace YooAsset
|
||||
options.SetURL(mainURL, mainURL);
|
||||
}
|
||||
|
||||
var downloader = new DownloadPackageBundleOperation(this, bundle, options);
|
||||
var downloader = new DownloadPackageBundleOperation(this, options);
|
||||
return downloader;
|
||||
}
|
||||
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||
public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
|
||||
{
|
||||
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
|
||||
PackageBundle bundle = options.Bundle;
|
||||
if (bundle.BundleType == (int)EBundleType.AssetBundle)
|
||||
{
|
||||
var operation = new DCFSLoadAssetBundleOperation(this, bundle);
|
||||
return operation;
|
||||
}
|
||||
else if (bundle.BundleType == (int)EBuildBundleType.RawBundle)
|
||||
else if (bundle.BundleType == (int)EBundleType.RawBundle)
|
||||
{
|
||||
var operation = new DCFSLoadRawBundleOperation(this, bundle);
|
||||
return operation;
|
||||
@@ -315,13 +317,13 @@ namespace YooAsset
|
||||
{
|
||||
ResumeDownloadResponseCodes = (List<long>)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
|
||||
else if (name == FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES)
|
||||
{
|
||||
DecryptionServices = (IDecryptionServices)value;
|
||||
BundleDecryptionServices = (IBundleDecryptionServices)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.MANIFEST_SERVICES)
|
||||
else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES)
|
||||
{
|
||||
ManifestServices = (IManifestRestoreServices)value;
|
||||
ManifestRestoreServices = (IManifestRestoreServices)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.COPY_LOCAL_FILE_SERVICES)
|
||||
{
|
||||
@@ -403,20 +405,20 @@ namespace YooAsset
|
||||
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
if (BundleDecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !");
|
||||
YooLogger.Error($"The {nameof(IBundleDecryptionServices)} is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
string filePath = GetCacheBundleFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
var bundleInfo = new DecryptBundleInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.ReadFileData(fileInfo);
|
||||
return BundleDecryptionServices.ReadFileData(bundleInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -431,20 +433,20 @@ namespace YooAsset
|
||||
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
if (BundleDecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !");
|
||||
YooLogger.Error($"The {nameof(IBundleDecryptionServices)} is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
string filePath = GetCacheBundleFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
var bundleInfo = new DecryptBundleInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.ReadFileText(fileInfo);
|
||||
return BundleDecryptionServices.ReadFileText(bundleInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -550,7 +552,7 @@ namespace YooAsset
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
YooLogger.Error($"Failed to write cache file ! {ex.Message}");
|
||||
YooLogger.Error($"Failed to write cache file. Error: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -649,46 +651,46 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 加载加密资源文件
|
||||
/// </summary>
|
||||
public DecryptResult LoadEncryptedAssetBundle(PackageBundle bundle)
|
||||
public DecryptSyncResult LoadEncryptedBundleSync(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetCacheBundleFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
var bundleInfo = new DecryptBundleInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.LoadAssetBundle(fileInfo);
|
||||
return BundleDecryptionServices.LoadAssetBundleSync(bundleInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载加密资源文件
|
||||
/// </summary>
|
||||
public DecryptResult LoadEncryptedAssetBundleAsync(PackageBundle bundle)
|
||||
public DecryptAsyncResult LoadEncryptedBundleAsync(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetCacheBundleFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
var bundleInfo = new DecryptBundleInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.LoadAssetBundleAsync(fileInfo);
|
||||
return BundleDecryptionServices.LoadAssetBundleAsync(bundleInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载加密资源文件
|
||||
/// </summary>
|
||||
public DecryptResult LoadEncryptedAssetBundleFallback(PackageBundle bundle)
|
||||
public DecryptSyncResult LoadEncryptedBundleFallback(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetCacheBundleFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
var bundleInfo = new DecryptBundleInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.LoadAssetBundleFallback(fileInfo);
|
||||
return BundleDecryptionServices.LoadAssetBundleFallback(bundleInfo);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace YooAsset
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
YooLogger.Error($"Failed to delete cache file ! {ex.Message}");
|
||||
YooLogger.Error($"Failed to delete cache file. Error: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace YooAsset
|
||||
#if UNITY_WEBGL
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(DefaultCacheFileSystem)} is not support WEBGL platform !";
|
||||
Error = $"{nameof(DefaultCacheFileSystem)} is not support WEBGL platform.";
|
||||
#else
|
||||
_steps = ESteps.CheckAppFootPrint;
|
||||
#endif
|
||||
@@ -48,23 +48,23 @@ namespace YooAsset
|
||||
{
|
||||
if (_fileSystem.InstallClearMode == EOverwriteInstallClearMode.None)
|
||||
{
|
||||
YooLogger.Warning("Do nothing when overwrite install application !");
|
||||
YooLogger.Warning("Do nothing when overwrite install application.");
|
||||
}
|
||||
else if (_fileSystem.InstallClearMode == EOverwriteInstallClearMode.ClearAllCacheFiles)
|
||||
{
|
||||
_fileSystem.DeleteAllBundleFiles();
|
||||
_fileSystem.DeleteAllManifestFiles();
|
||||
YooLogger.Warning("Delete all cache files when overwrite install application !");
|
||||
YooLogger.Warning("Delete all cache files when overwrite install application.");
|
||||
}
|
||||
else if (_fileSystem.InstallClearMode == EOverwriteInstallClearMode.ClearAllBundleFiles)
|
||||
{
|
||||
_fileSystem.DeleteAllBundleFiles();
|
||||
YooLogger.Warning("Delete all bundle files when overwrite install application !");
|
||||
YooLogger.Warning("Delete all bundle files when overwrite install application.");
|
||||
}
|
||||
else if (_fileSystem.InstallClearMode == EOverwriteInstallClearMode.ClearAllManifestFiles)
|
||||
{
|
||||
_fileSystem.DeleteAllManifestFiles();
|
||||
YooLogger.Warning("Delete all manifest files when overwrite install application !");
|
||||
YooLogger.Warning("Delete all manifest files when overwrite install application.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -79,8 +79,8 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloadFileOp == null)
|
||||
{
|
||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
|
||||
DownloadFileOptions options = new DownloadFileOptions(_bundle, int.MaxValue);
|
||||
_downloadFileOp = _fileSystem.DownloadFileAsync(options);
|
||||
_downloadFileOp.StartOperation();
|
||||
AddChildOperation(_downloadFileOp);
|
||||
}
|
||||
@@ -120,18 +120,18 @@ namespace YooAsset
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Abort download file !";
|
||||
Error = "Abort download file.";
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadAssetBundle)
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
if (_fileSystem.DecryptionServices == null)
|
||||
if (_fileSystem.BundleDecryptionServices == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"The {nameof(IDecryptionServices)} is null !";
|
||||
Error = $"The {nameof(IBundleDecryptionServices)} is null.";
|
||||
YooLogger.Error(Error);
|
||||
return;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
var decryptResult = _fileSystem.LoadEncryptedAssetBundle(_bundle);
|
||||
var decryptResult = _fileSystem.LoadEncryptedBundleSync(_bundle);
|
||||
_assetBundle = decryptResult.Result;
|
||||
_managedStream = decryptResult.ManagedStream;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
var decryptResult = _fileSystem.LoadEncryptedAssetBundleAsync(_bundle);
|
||||
var decryptResult = _fileSystem.LoadEncryptedBundleAsync(_bundle);
|
||||
_createRequest = decryptResult.CreateRequest;
|
||||
_managedStream = decryptResult.ManagedStream;
|
||||
}
|
||||
@@ -202,7 +202,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
var decryptResult = _fileSystem.LoadEncryptedAssetBundleFallback(_bundle);
|
||||
var decryptResult = _fileSystem.LoadEncryptedBundleFallback(_bundle);
|
||||
_assetBundle = decryptResult.Result;
|
||||
if (_assetBundle != null)
|
||||
{
|
||||
@@ -262,14 +262,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RunBatchExecution();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,8 +348,8 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloadFileOp == null)
|
||||
{
|
||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
|
||||
DownloadFileOptions options = new DownloadFileOptions(_bundle, int.MaxValue);
|
||||
_downloadFileOp = _fileSystem.DownloadFileAsync(options);
|
||||
_downloadFileOp.StartOperation();
|
||||
AddChildOperation(_downloadFileOp);
|
||||
}
|
||||
@@ -396,7 +389,7 @@ namespace YooAsset
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Abort download file !";
|
||||
Error = "Abort download file.";
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadCacheRawBundle)
|
||||
@@ -419,14 +412,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RunBatchExecution();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Can not found active package manifest !";
|
||||
Error = "Can not found active package manifest.";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -59,7 +59,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Clear param is null !";
|
||||
Error = "Clear param is null.";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Can not found active package manifest !";
|
||||
Error = "Can not found active package manifest.";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -57,7 +57,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Clear param is null !";
|
||||
Error = "Clear param is null.";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Can not found active package manifest !";
|
||||
Error = "Can not found active package manifest.";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Can not found active package manifest !";
|
||||
Error = "Can not found active package manifest.";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace YooAsset
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal DownloadPackageBundleOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
|
||||
internal DownloadPackageBundleOperation(DefaultCacheFileSystem fileSystem, DownloadFileOptions options) : base(options.Bundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_options = options;
|
||||
@@ -62,7 +62,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Download file options is invalid !";
|
||||
Error = "Download file options is invalid.";
|
||||
Debug.Log(Error);
|
||||
return;
|
||||
}
|
||||
@@ -95,7 +95,7 @@ namespace YooAsset
|
||||
if (IsWaitForAsyncComplete == false && _failedTryAgain > 0)
|
||||
{
|
||||
_steps = ESteps.TryAgain;
|
||||
YooLogger.Warning($"Failed download : {_downloadFileOp.URL} Try again !");
|
||||
YooLogger.Warning($"Failed download : {_downloadFileOp.URL} Try again.");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -124,14 +124,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RunBatchExecution();
|
||||
}
|
||||
internal override void InternalAbort()
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Cache package hash file content is empty !";
|
||||
Error = $"Cache package hash file content is empty.";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.VerifyFileData)
|
||||
{
|
||||
if (ManifestTools.VerifyManifestData(_fileData, _packageHash))
|
||||
if (PackageManifestTools.VerifyManifestData(_fileData, _packageHash))
|
||||
{
|
||||
_steps = ESteps.LoadManifest;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to verify cache package manifest file!";
|
||||
Error = "Failed to verify cache package manifest file.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_deserializer == null)
|
||||
{
|
||||
_deserializer = new DeserializeManifestOperation(_fileSystem.ManifestServices, _fileData);
|
||||
_deserializer = new DeserializeManifestOperation(_fileSystem.ManifestRestoreServices, _fileData);
|
||||
_deserializer.StartOperation();
|
||||
AddChildOperation(_deserializer);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Remote package version file content is empty !";
|
||||
Error = $"Remote package version file content is empty.";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -98,6 +98,10 @@ namespace YooAsset
|
||||
// 检测下载结果
|
||||
if (_steps == ESteps.CheckRequest)
|
||||
{
|
||||
//TODO 更新下载后台,防止无限挂起
|
||||
if (IsWaitForAsyncComplete)
|
||||
_fileSystem.DownloadBackend.Update();
|
||||
|
||||
DownloadProgress = _request.DownloadProgress;
|
||||
DownloadedBytes = _request.DownloadedBytes;
|
||||
Progress = DownloadProgress;
|
||||
@@ -166,7 +170,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{_fileSystem.GetType().FullName} failed to write file !";
|
||||
Error = $"{_fileSystem.GetType().FullName} failed to write file.";
|
||||
}
|
||||
|
||||
// 注意:缓存完成后直接删除临时文件
|
||||
@@ -177,23 +181,12 @@ namespace YooAsset
|
||||
internal override void InternalAbort()
|
||||
{
|
||||
if (_request != null)
|
||||
_request.AbortRequest();
|
||||
_request.Dispose();
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
//TODO 更新下载后台,防止无限挂起
|
||||
_fileSystem.DownloadBackend.Update();
|
||||
|
||||
//TODO 等待导入或解压本地文件完毕,该操作会挂起主线程!
|
||||
InternalUpdate();
|
||||
if (IsDone)
|
||||
break;
|
||||
|
||||
//TODO 短暂休眠避免完全卡死
|
||||
System.Threading.Thread.Sleep(1);
|
||||
}
|
||||
//TODO 等待导入或解压本地文件完毕,该操作会挂起主线程!
|
||||
RunUntilCompletion();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{_fileSystem.GetType().FullName} failed to write file !";
|
||||
Error = $"{_fileSystem.GetType().FullName} failed to write file.";
|
||||
}
|
||||
|
||||
// 注意:缓存完成后直接删除临时文件
|
||||
@@ -144,14 +144,14 @@ namespace YooAsset
|
||||
internal override void InternalAbort()
|
||||
{
|
||||
if (_request != null)
|
||||
_request.AbortRequest();
|
||||
_request.Dispose();
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
if (_steps != ESteps.Done)
|
||||
{
|
||||
// 注意:不中断下载任务,保持后台继续下载
|
||||
YooLogger.Error($"Try load bundle {_bundle.BundleName} from remote : {URL} !");
|
||||
YooLogger.Error($"Try load bundle {_bundle.BundleName} from remote : {URL}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,23 +119,16 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 中止所有下载任务
|
||||
/// </summary>
|
||||
public void AbortAll()
|
||||
{
|
||||
foreach (var valuePair in _downloaders)
|
||||
{
|
||||
valuePair.Value.AbortOperation();
|
||||
}
|
||||
_downloaders.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源
|
||||
/// 释放下载资源
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
AbortAll();
|
||||
foreach (var valuePair in _downloaders)
|
||||
{
|
||||
var operation = valuePair.Value;
|
||||
operation.AbortOperation();
|
||||
}
|
||||
_downloaders.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace YooAsset
|
||||
|
||||
private readonly DefaultCacheFileSystem _fileSystem;
|
||||
private IEnumerator<string> _filesEnumerator = null;
|
||||
private float _verifyStartTime;
|
||||
private double _verifyStartTime;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
@@ -33,7 +33,7 @@ namespace YooAsset
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.Prepare;
|
||||
_verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
|
||||
_verifyStartTime = TimeUtility.RealtimeSinceStartup;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
@@ -58,7 +58,7 @@ namespace YooAsset
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||
double costTime = TimeUtility.RealtimeSinceStartup - _verifyStartTime;
|
||||
YooLogger.Log($"Search cache files elapsed time {costTime:f1} seconds");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace YooAsset
|
||||
private List<VerifyFileElement> _verifyingList;
|
||||
private int _verifyMaxNum;
|
||||
private int _verifyTotalCount;
|
||||
private float _verifyStartTime;
|
||||
private double _verifyStartTime;
|
||||
private int _succeedCount;
|
||||
private int _failedCount;
|
||||
private ESteps _steps = ESteps.None;
|
||||
@@ -40,7 +40,7 @@ namespace YooAsset
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.InitVerify;
|
||||
_verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
|
||||
_verifyStartTime = TimeUtility.RealtimeSinceStartup;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
@@ -84,7 +84,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||
double costTime = TimeUtility.RealtimeSinceStartup - _verifyStartTime;
|
||||
YooLogger.Log($"Verify cache files elapsed time {costTime:f1} seconds");
|
||||
}
|
||||
|
||||
|
||||
@@ -63,22 +63,14 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to verify file : {_element.TempFilePath} ! ErrorCode : {VerifyResult}";
|
||||
Error = $"Failed to verify file : {_element.TempFilePath} ErrorCode : {VerifyResult}";
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
//TODO 等待子线程验证文件完毕,该操作会挂起主线程!
|
||||
InternalUpdate();
|
||||
if (IsDone)
|
||||
break;
|
||||
|
||||
//TODO 短暂休眠避免完全卡死
|
||||
System.Threading.Thread.Sleep(1);
|
||||
}
|
||||
//TODO 等待子线程验证文件完毕,该操作会挂起主线程!
|
||||
RunUntilCompletion();
|
||||
}
|
||||
|
||||
private void VerifyInThread(object obj)
|
||||
|
||||
@@ -83,31 +83,32 @@ namespace YooAsset
|
||||
var operation = new DEFSInitializeOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new DEFSLoadPackageManifestOperation(this, packageVersion);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
|
||||
{
|
||||
var operation = new DEFSRequestPackageVersionOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options)
|
||||
{
|
||||
var operation = new DEFSLoadPackageManifestOperation(this, options.PackageVersion);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
|
||||
{
|
||||
var operation = new FSClearCacheFilesCompleteOperation();
|
||||
return operation;
|
||||
}
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
|
||||
{
|
||||
string mainURL = bundle.BundleName;
|
||||
string mainURL = options.Bundle.BundleName;
|
||||
options.SetURL(mainURL, mainURL);
|
||||
var downloader = new DownloadVirtualBundleOperation(this, bundle, options);
|
||||
var downloader = new DownloadVirtualBundleOperation(this, options);
|
||||
return downloader;
|
||||
}
|
||||
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||
public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
|
||||
{
|
||||
if (bundle.BundleType == (int)EBuildBundleType.VirtualBundle)
|
||||
PackageBundle bundle = options.Bundle;
|
||||
if (bundle.BundleType == (int)EBundleType.VirtualBundle)
|
||||
{
|
||||
var operation = new DEFSLoadBundleOperation(this, bundle);
|
||||
return operation;
|
||||
@@ -160,7 +161,7 @@ namespace YooAsset
|
||||
PackageName = packageName;
|
||||
|
||||
if (string.IsNullOrEmpty(packageRoot))
|
||||
throw new YooFileSystemException($"{nameof(DefaultEditorFileSystem)} package root is null or empty !");
|
||||
throw new YooFileSystemException($"{nameof(DefaultEditorFileSystem)} package root is null or empty.");
|
||||
|
||||
_packageRoot = packageRoot;
|
||||
|
||||
|
||||
@@ -64,8 +64,8 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloadFileOp == null)
|
||||
{
|
||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
|
||||
DownloadFileOptions options = new DownloadFileOptions(_bundle, int.MaxValue);
|
||||
_downloadFileOp = _fileSystem.DownloadFileAsync(options);
|
||||
_downloadFileOp.StartOperation();
|
||||
AddChildOperation(_downloadFileOp);
|
||||
}
|
||||
@@ -105,7 +105,7 @@ namespace YooAsset
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Abort download file !";
|
||||
Error = "Abort download file.";
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadAssetBundle)
|
||||
@@ -116,7 +116,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Virtual WebGL Mode only support asyn load method !";
|
||||
Error = "Virtual WebGL Mode only support asyn load method.";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
else
|
||||
@@ -142,14 +142,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RunBatchExecution();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace YooAsset
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal DownloadVirtualBundleOperation(DefaultEditorFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
|
||||
internal DownloadVirtualBundleOperation(DefaultEditorFileSystem fileSystem, DownloadFileOptions options) : base(options.Bundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_options = options;
|
||||
@@ -61,7 +61,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Download file options is invalid !";
|
||||
Error = "Download file options is invalid.";
|
||||
Debug.Log(Error);
|
||||
return;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ namespace YooAsset
|
||||
if (IsWaitForAsyncComplete == false && _failedTryAgain > 0)
|
||||
{
|
||||
_steps = ESteps.TryAgain;
|
||||
YooLogger.Warning($"Failed download : {_downloadFileOp.URL} Try again !");
|
||||
YooLogger.Warning($"Failed download : {_downloadFileOp.URL} Try again.");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -127,7 +127,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Try load bundle {Bundle.BundleName} from remote !";
|
||||
Error = $"Try load bundle {Bundle.BundleName} from remote.";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.VerifyFileData)
|
||||
{
|
||||
if (ManifestTools.VerifyManifestData(_fileData, _packageHash))
|
||||
if (PackageManifestTools.VerifyManifestData(_fileData, _packageHash))
|
||||
{
|
||||
_steps = ESteps.LoadManifest;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to verify simulation package manifest file !";
|
||||
Error = "Failed to verify simulation package manifest file.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,12 +61,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IWebDecryptionServices DecryptionServices { private set; get; }
|
||||
public IWebBundleDecryptionServices BundleDecryptionServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:资源清单服务类
|
||||
/// </summary>
|
||||
public IManifestRestoreServices ManifestServices { private set; get; }
|
||||
public IManifestRestoreServices ManifestRestoreServices { private set; get; }
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -78,28 +78,29 @@ namespace YooAsset
|
||||
var operation = new DWRFSInitializeOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
|
||||
{
|
||||
var operation = new DWRFSLoadPackageManifestOperation(this, packageVersion, timeout);
|
||||
var operation = new DWRFSRequestPackageVersionOperation(this, options.AppendTimeTicks, options.Timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options)
|
||||
{
|
||||
var operation = new DWRFSRequestPackageVersionOperation(this, appendTimeTicks, timeout);
|
||||
var operation = new DWRFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
|
||||
{
|
||||
var operation = new FSClearCacheFilesCompleteOperation();
|
||||
return operation;
|
||||
}
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||
public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
|
||||
{
|
||||
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
|
||||
PackageBundle bundle = options.Bundle;
|
||||
if (bundle.BundleType == (int)EBundleType.AssetBundle)
|
||||
{
|
||||
var operation = new DWRFSLoadAssetBundleOperation(this, bundle);
|
||||
return operation;
|
||||
@@ -130,13 +131,13 @@ namespace YooAsset
|
||||
{
|
||||
RemoteServices = (IRemoteServices)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
|
||||
else if (name == FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES)
|
||||
{
|
||||
DecryptionServices = (IWebDecryptionServices)value;
|
||||
BundleDecryptionServices = (IWebBundleDecryptionServices)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.MANIFEST_SERVICES)
|
||||
else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES)
|
||||
{
|
||||
ManifestServices = (IManifestRestoreServices)value;
|
||||
ManifestRestoreServices = (IManifestRestoreServices)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -36,18 +36,18 @@ namespace YooAsset
|
||||
{
|
||||
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
||||
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||
DownloadFileOptions options = new DownloadFileOptions(_bundle, int.MaxValue);
|
||||
options.SetURL(mainURL, fallbackURL);
|
||||
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices, _fileSystem.DownloadBackend);
|
||||
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(options, _fileSystem.BundleDecryptionServices, _fileSystem.DownloadBackend);
|
||||
_loadWebAssetBundleOp.StartOperation();
|
||||
AddChildOperation(_loadWebAssetBundleOp);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache, _fileSystem.DownloadBackend);
|
||||
_loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(options, _fileSystem.DisableUnityWebCache, _fileSystem.DownloadBackend);
|
||||
_loadWebAssetBundleOp.StartOperation();
|
||||
AddChildOperation(_loadWebAssetBundleOp);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(DWRFSLoadAssetBundleOperation)} loaded asset bundle is null !";
|
||||
Error = $"{nameof(DWRFSLoadAssetBundleOperation)} loaded asset bundle is null.";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -90,8 +90,8 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "WebGL platform not support sync load method !";
|
||||
UnityEngine.Debug.LogError(Error);
|
||||
Error = "WebGL platform not support sync load method.";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace YooAsset
|
||||
{
|
||||
string packageHash = _requestWebPackageHashOp.PackageHash;
|
||||
string packageName = _fileSystem.PackageName;
|
||||
var manifestServices = _fileSystem.ManifestServices;
|
||||
var manifestServices = _fileSystem.ManifestRestoreServices;
|
||||
var remoteServices = _fileSystem.RemoteServices;
|
||||
var downloadBackend = _fileSystem.DownloadBackend;
|
||||
_loadWebPackageManifestOp = new LoadWebPackageManifestOperation(manifestServices, remoteServices, downloadBackend, packageName, _packageVersion, packageHash, _timeout);
|
||||
|
||||
@@ -70,12 +70,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IWebDecryptionServices DecryptionServices { private set; get; }
|
||||
public IWebBundleDecryptionServices BundleDecryptionServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:资源清单服务类
|
||||
/// </summary>
|
||||
public IManifestRestoreServices ManifestServices { private set; get; }
|
||||
public IManifestRestoreServices ManifestRestoreServices { private set; get; }
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -87,28 +87,29 @@ namespace YooAsset
|
||||
var operation = new DWSFSInitializeOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
|
||||
{
|
||||
var operation = new DWSFSLoadPackageManifestOperation(this, packageVersion, timeout);
|
||||
var operation = new DWSFSRequestPackageVersionOperation(this, options.Timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options)
|
||||
{
|
||||
var operation = new DWSFSRequestPackageVersionOperation(this, timeout);
|
||||
var operation = new DWSFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
|
||||
{
|
||||
var operation = new FSClearCacheFilesCompleteOperation();
|
||||
return operation;
|
||||
}
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||
public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
|
||||
{
|
||||
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
|
||||
PackageBundle bundle = options.Bundle;
|
||||
if (bundle.BundleType == (int)EBundleType.AssetBundle)
|
||||
{
|
||||
var operation = new DWSFSLoadAssetBundleOperation(this, bundle);
|
||||
return operation;
|
||||
@@ -135,13 +136,13 @@ namespace YooAsset
|
||||
{
|
||||
DisableUnityWebCache = Convert.ToBoolean(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
|
||||
else if (name == FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES)
|
||||
{
|
||||
DecryptionServices = (IWebDecryptionServices)value;
|
||||
BundleDecryptionServices = (IWebBundleDecryptionServices)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.MANIFEST_SERVICES)
|
||||
else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES)
|
||||
{
|
||||
ManifestServices = (IManifestRestoreServices)value;
|
||||
ManifestRestoreServices = (IManifestRestoreServices)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -36,18 +36,18 @@ namespace YooAsset
|
||||
{
|
||||
string fileLoadPath = _fileSystem.GetWebFileLoadPath(_bundle);
|
||||
string mainURL = DownloadSystemHelper.ConvertToWWWPath(fileLoadPath);
|
||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||
DownloadFileOptions options = new DownloadFileOptions(_bundle, int.MaxValue);
|
||||
options.SetURL(mainURL, mainURL);
|
||||
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices, _fileSystem.DownloadBackend);
|
||||
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(options, _fileSystem.BundleDecryptionServices, _fileSystem.DownloadBackend);
|
||||
_loadWebAssetBundleOp.StartOperation();
|
||||
AddChildOperation(_loadWebAssetBundleOp);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache, _fileSystem.DownloadBackend);
|
||||
_loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(options, _fileSystem.DisableUnityWebCache, _fileSystem.DownloadBackend);
|
||||
_loadWebAssetBundleOp.StartOperation();
|
||||
AddChildOperation(_loadWebAssetBundleOp);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(DWSFSLoadAssetBundleOperation)} loaded asset bundle is null !";
|
||||
Error = $"{nameof(DWSFSLoadAssetBundleOperation)} loaded asset bundle is null.";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -90,8 +90,8 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "WebGL platform not support sync load method !";
|
||||
UnityEngine.Debug.LogError(Error);
|
||||
Error = "WebGL platform not support sync load method.";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace YooAsset
|
||||
{
|
||||
try
|
||||
{
|
||||
var catalog = CatalogTools.DeserializeFromBinary(_webDataRequestOp.Result);
|
||||
var catalog = CatalogFileHelper.DeserializeFromBinary(_webDataRequestOp.Result);
|
||||
if (catalog.PackageName != _fileSystem.PackageName)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.VerifyFileData)
|
||||
{
|
||||
if (ManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
|
||||
if (PackageManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
|
||||
{
|
||||
_steps = ESteps.LoadManifest;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to verify web server package manifest file!";
|
||||
Error = "Failed to verify web server package manifest file.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_deserializer == null)
|
||||
{
|
||||
_deserializer = new DeserializeManifestOperation(_fileSystem.ManifestServices, _webDataRequestOp.Result);
|
||||
_deserializer = new DeserializeManifestOperation(_fileSystem.ManifestRestoreServices, _webDataRequestOp.Result);
|
||||
_deserializer.StartOperation();
|
||||
AddChildOperation(_deserializer);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Web server package hash file content is empty !";
|
||||
Error = $"Web server package hash file content is empty.";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Web server package version file content is empty !";
|
||||
Error = $"Web server package version file content is empty.";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -83,11 +83,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="packageRoot">文件系统的根目录</param>
|
||||
public static FileSystemParameters CreateDefaultBuildinFileSystemParameters(IDecryptionServices decryptionServices = null, string packageRoot = null)
|
||||
public static FileSystemParameters CreateDefaultBuildinFileSystemParameters(IBundleDecryptionServices decryptionServices = null, string packageRoot = null)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultBuildinFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES, decryptionServices);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
@@ -97,12 +97,12 @@ namespace YooAsset
|
||||
/// <param name="remoteServices">远端资源地址查询服务类</param>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="packageRoot">文件系统的根目录</param>
|
||||
public static FileSystemParameters CreateDefaultCacheFileSystemParameters(IRemoteServices remoteServices, IDecryptionServices decryptionServices = null, string packageRoot = null)
|
||||
public static FileSystemParameters CreateDefaultCacheFileSystemParameters(IRemoteServices remoteServices, IBundleDecryptionServices decryptionServices = null, string packageRoot = null)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultCacheFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES, decryptionServices);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
@@ -111,11 +111,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="disableUnityWebCache">禁用Unity的网络缓存</param>
|
||||
public static FileSystemParameters CreateDefaultWebServerFileSystemParameters(IWebDecryptionServices decryptionServices = null, bool disableUnityWebCache = false)
|
||||
public static FileSystemParameters CreateDefaultWebServerFileSystemParameters(IWebBundleDecryptionServices decryptionServices = null, bool disableUnityWebCache = false)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultWebServerFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE, disableUnityWebCache);
|
||||
return fileSystemParams;
|
||||
}
|
||||
@@ -126,12 +126,12 @@ namespace YooAsset
|
||||
/// <param name="remoteServices">远端资源地址查询服务类</param>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="disableUnityWebCache">禁用Unity的网络缓存</param>
|
||||
public static FileSystemParameters CreateDefaultWebRemoteFileSystemParameters(IRemoteServices remoteServices, IWebDecryptionServices decryptionServices = null, bool disableUnityWebCache = false)
|
||||
public static FileSystemParameters CreateDefaultWebRemoteFileSystemParameters(IRemoteServices remoteServices, IWebBundleDecryptionServices decryptionServices = null, bool disableUnityWebCache = false)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultWebRemoteFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE, disableUnityWebCache);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
@@ -7,102 +7,127 @@ namespace YooAsset
|
||||
/// 初始化的时候缓存文件校验级别 <see cref=EFileVerifyLevel>
|
||||
/// </summary>
|
||||
public const string FILE_VERIFY_LEVEL = "FILE_VERIFY_LEVEL";
|
||||
|
||||
/// <summary>
|
||||
/// 初始化的时候缓存文件校验最大并发数 <see cref=int>
|
||||
/// </summary>
|
||||
public const string FILE_VERIFY_MAX_CONCURRENCY = "FILE_VERIFY_MAX_CONCURRENCY";
|
||||
|
||||
/// <summary>
|
||||
/// 覆盖安装缓存清理模式 <see cref=EOverwriteInstallClearMode>
|
||||
/// </summary>
|
||||
public const string INSTALL_CLEAR_MODE = "INSTALL_CLEAR_MODE";
|
||||
|
||||
/// <summary>
|
||||
/// 远端资源地址查询服务类 <see cref=IRemoteServices>
|
||||
/// </summary>
|
||||
public const string REMOTE_SERVICES = "REMOTE_SERVICES";
|
||||
|
||||
/// <summary>
|
||||
/// 解密服务接口的实例类 <see cref=IDecryptionServices>
|
||||
/// 解密服务接口的实例类 <see cref=IBundleDecryptionServices>
|
||||
/// </summary>
|
||||
public const string DECRYPTION_SERVICES = "DECRYPTION_SERVICES";
|
||||
public const string BUNDLE_DECRYPTION_SERVICES = "BUNDLE_DECRYPTION_SERVICES";
|
||||
|
||||
/// <summary>
|
||||
/// 资源清单服务类 <see cref=IManifestRestoreServices>
|
||||
/// </summary>
|
||||
public const string MANIFEST_SERVICES = "MANIFEST_SERVICES";
|
||||
public const string MANIFEST_RESTORE_SERVICES = "MANIFEST_RESTORE_SERVICES";
|
||||
|
||||
/// <summary>
|
||||
/// 数据文件追加文件格式 <see cref=bool>
|
||||
/// </summary>
|
||||
public const string APPEND_FILE_EXTENSION = "APPEND_FILE_EXTENSION";
|
||||
|
||||
/// <summary>
|
||||
/// 禁用Catalog目录查询文件 <see cref=bool>
|
||||
/// </summary>
|
||||
public const string DISABLE_CATALOG_FILE = "DISABLE_CATALOG_FILE";
|
||||
|
||||
/// <summary>
|
||||
/// 禁用Unity的网络缓存 <see cref=bool>
|
||||
/// </summary>
|
||||
public const string DISABLE_UNITY_WEB_CACHE = "DISABLE_UNITY_WEB_CACHE";
|
||||
|
||||
/// <summary>
|
||||
/// 禁用边玩边下机制 <see cref=bool>
|
||||
/// </summary>
|
||||
public const string DISABLE_ONDEMAND_DOWNLOAD = "DISABLE_ONDEMAND_DOWNLOAD";
|
||||
|
||||
/// <summary>
|
||||
/// UnityWebRequest 创建委托 <see cref=UnityWebRequestCreator>
|
||||
/// </summary>
|
||||
public const string UNITY_WEB_REQUEST_CREATOR = "UNITY_WEB_REQUEST_CREATOR";
|
||||
|
||||
/// <summary>
|
||||
/// 下载后台接口 <see cref=IDownloadBackend>
|
||||
/// </summary>
|
||||
public const string DOWNLOAD_BACKEND = "DOWNLOAD_BACKEND";
|
||||
|
||||
/// <summary>
|
||||
/// 最大并发连接数 默认值:10(推荐范围 1-32) <see cref=int>
|
||||
/// </summary>
|
||||
public const string DOWNLOAD_MAX_CONCURRENCY = "DOWNLOAD_MAX_CONCURRENCY";
|
||||
|
||||
/// <summary>
|
||||
/// 每帧发起的最大请求数 默认值:5(推荐范围 1-10)<see cref=int>
|
||||
/// </summary>
|
||||
public const string DOWNLOAD_MAX_REQUEST_PER_FRAME = "DOWNLOAD_MAX_REQUEST_PER_FRAME";
|
||||
|
||||
/// <summary>
|
||||
/// 下载任务的看门狗机制监控时间 <see cref=int>
|
||||
/// </summary>
|
||||
public const string DOWNLOAD_WATCH_DOG_TIME = "DOWNLOAD_WATCH_DOG_TIME";
|
||||
|
||||
/// <summary>
|
||||
/// 启用断点续传的最小尺寸 <see cref=long>
|
||||
/// </summary>
|
||||
public const string RESUME_DOWNLOAD_MINMUM_SIZE = "RESUME_DOWNLOAD_MINMUM_SIZE";
|
||||
|
||||
/// <summary>
|
||||
/// 断点续传下载器关注的错误码 <see cref=List<long>>
|
||||
/// </summary>
|
||||
public const string RESUME_DOWNLOAD_RESPONSE_CODES = "RESUME_DOWNLOAD_RESPONSE_CODES";
|
||||
|
||||
/// <summary>
|
||||
/// 模拟WebGL平台模式 <see cref=bool>
|
||||
/// </summary>
|
||||
public const string VIRTUAL_WEBGL_MODE = "VIRTUAL_WEBGL_MODE";
|
||||
|
||||
/// <summary>
|
||||
/// 模拟虚拟下载模式 <see cref=bool>
|
||||
/// </summary>
|
||||
public const string VIRTUAL_DOWNLOAD_MODE = "VIRTUAL_DOWNLOAD_MODE";
|
||||
|
||||
/// <summary>
|
||||
/// 模拟虚拟下载的网速(单位:字节) <see cref=int>
|
||||
/// </summary>
|
||||
public const string VIRTUAL_DOWNLOAD_SPEED = "VIRTUAL_DOWNLOAD_SPEED";
|
||||
|
||||
/// <summary>
|
||||
/// 异步模拟加载最小帧数 <see cref=int>
|
||||
/// </summary>
|
||||
public const string ASYNC_SIMULATE_MIN_FRAME = "ASYNC_SIMULATE_MIN_FRAME";
|
||||
|
||||
/// <summary>
|
||||
/// 异步模拟加载最大帧数 <see cref=int>
|
||||
/// </summary>
|
||||
public const string ASYNC_SIMULATE_MAX_FRAME = "ASYNC_SIMULATE_MAX_FRAME";
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝内置清单 <see cref=bool>
|
||||
/// </summary>
|
||||
public const string COPY_BUILDIN_PACKAGE_MANIFEST = "COPY_BUILDIN_PACKAGE_MANIFEST";
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝内置清单的目标目录 <see cref=string>
|
||||
/// </summary>
|
||||
public const string COPY_BUILDIN_PACKAGE_MANIFEST_DEST_ROOT = "COPY_BUILDIN_PACKAGE_MANIFEST_DEST_ROOT";
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝内置文件接口的实例类 <see cref=ICopyLocalFileServices>
|
||||
/// </summary>
|
||||
public const string COPY_LOCAL_FILE_SERVICES = "COPY_LOCAL_FILE_SERVICES";
|
||||
|
||||
/// <summary>
|
||||
/// 解压文件系统的根目录 <see cref=string>
|
||||
/// </summary>
|
||||
|
||||
@@ -24,30 +24,30 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
FSInitializeFileSystemOperation InitializeFileSystemAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 加载包裹清单
|
||||
/// </summary>
|
||||
FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout);
|
||||
|
||||
/// <summary>
|
||||
/// 查询包裹版本
|
||||
/// </summary>
|
||||
FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout);
|
||||
FSRequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// 加载包裹清单
|
||||
/// </summary>
|
||||
FSLoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// 清理缓存文件
|
||||
/// </summary>
|
||||
FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options);
|
||||
FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// 下载Bundle文件
|
||||
/// </summary>
|
||||
FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options);
|
||||
|
||||
FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// 加载Bundle文件
|
||||
/// </summary>
|
||||
FSLoadBundleOperation LoadBundleFile(PackageBundle bundle);
|
||||
FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options);
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,19 +1,6 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class ClearCacheFilesOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理模式
|
||||
/// </summary>
|
||||
public string ClearMode;
|
||||
|
||||
/// <summary>
|
||||
/// 附加参数
|
||||
/// </summary>
|
||||
public object ClearParam;
|
||||
}
|
||||
|
||||
internal abstract class FSClearCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,54 +1,6 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class DownloadFileOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 失败后重试次数
|
||||
/// </summary>
|
||||
public readonly int FailedTryAgain;
|
||||
|
||||
/// <summary>
|
||||
/// 主资源地址
|
||||
/// </summary>
|
||||
public string MainURL { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 备用资源地址
|
||||
/// </summary>
|
||||
public string FallbackURL { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝的本地文件路径
|
||||
/// </summary>
|
||||
public string ImportFilePath { set; get; }
|
||||
|
||||
public DownloadFileOptions(int failedTryAgain)
|
||||
{
|
||||
FailedTryAgain = failedTryAgain;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置下载地址
|
||||
/// </summary>
|
||||
public void SetURL(string mainURL, string fallbackURL)
|
||||
{
|
||||
MainURL = mainURL;
|
||||
FallbackURL = fallbackURL;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否有效
|
||||
/// </summary>
|
||||
public bool IsValid()
|
||||
{
|
||||
if (string.IsNullOrEmpty(MainURL) || string.IsNullOrEmpty(FallbackURL))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract class FSDownloadFileOperation : AsyncOperationBase
|
||||
{
|
||||
public PackageBundle Bundle { private set; get; }
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal struct DownloadFileOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源包
|
||||
/// </summary>
|
||||
public readonly PackageBundle Bundle;
|
||||
|
||||
/// <summary>
|
||||
/// 失败后重试次数
|
||||
/// </summary>
|
||||
public readonly int FailedTryAgain;
|
||||
|
||||
/// <summary>
|
||||
/// 主资源地址
|
||||
/// </summary>
|
||||
public string MainURL { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 备用资源地址
|
||||
/// </summary>
|
||||
public string FallbackURL { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝的本地文件路径
|
||||
/// </summary>
|
||||
public string ImportFilePath { set; get; }
|
||||
|
||||
public DownloadFileOptions(PackageBundle bundle, int failedTryAgain)
|
||||
{
|
||||
Bundle = bundle;
|
||||
FailedTryAgain = failedTryAgain;
|
||||
MainURL = null;
|
||||
FallbackURL = null;
|
||||
ImportFilePath = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置下载地址
|
||||
/// </summary>
|
||||
public void SetURL(string mainURL, string fallbackURL)
|
||||
{
|
||||
MainURL = mainURL;
|
||||
FallbackURL = fallbackURL;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否有效
|
||||
/// </summary>
|
||||
public bool IsValid()
|
||||
{
|
||||
if (string.IsNullOrEmpty(MainURL) || string.IsNullOrEmpty(FallbackURL))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff8a96dd005f55346986f8a98aff8c99
|
||||
guid: ae6a979ad693ddf488c7a0f387c6ea76
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal struct LoadBundleOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源包
|
||||
/// </summary>
|
||||
public readonly PackageBundle Bundle;
|
||||
|
||||
public LoadBundleOptions(PackageBundle bundle)
|
||||
{
|
||||
Bundle = bundle;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9143514bc9d4f3e4aa9a50a7cfb08d21
|
||||
guid: 3d4cf0ce3cf4c794fa2d40665d5f3147
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -13,9 +13,8 @@ namespace YooAsset
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PackageBundle _bundle;
|
||||
private readonly DownloadFileOptions _options;
|
||||
private readonly IWebDecryptionServices _decryptionServices;
|
||||
private readonly IWebBundleDecryptionServices _decryptionServices;
|
||||
private readonly IDownloadBackend _downloadBackend;
|
||||
private IDownloadBytesRequest _unityWebDataRequestOp;
|
||||
|
||||
@@ -24,9 +23,8 @@ namespace YooAsset
|
||||
private int _failedTryAgain;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal LoadWebEncryptAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options, IWebDecryptionServices decryptionServices, IDownloadBackend downloadBackend)
|
||||
internal LoadWebEncryptAssetBundleOperation(DownloadFileOptions options, IWebBundleDecryptionServices decryptionServices, IDownloadBackend downloadBackend)
|
||||
{
|
||||
_bundle = bundle;
|
||||
_options = options;
|
||||
_failedTryAgain = options.FailedTryAgain;
|
||||
_decryptionServices = decryptionServices;
|
||||
@@ -48,7 +46,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"The {nameof(IWebDecryptionServices)} is null !";
|
||||
Error = $"The {nameof(IWebBundleDecryptionServices)} is null.";
|
||||
YooLogger.Error(Error);
|
||||
return;
|
||||
}
|
||||
@@ -77,7 +75,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed load encrypted AssetBundle !";
|
||||
Error = "Failed load encrypted AssetBundle.";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -91,7 +89,7 @@ namespace YooAsset
|
||||
if (_failedTryAgain > 0)
|
||||
{
|
||||
_steps = ESteps.TryAgain;
|
||||
YooLogger.Warning($"Failed download : {_unityWebDataRequestOp.URL} Try again !");
|
||||
YooLogger.Warning($"Failed download : {_unityWebDataRequestOp.URL} Try again.");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -124,11 +122,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
private AssetBundle LoadEncryptedAssetBundle(byte[] fileData)
|
||||
{
|
||||
var fileInfo = new WebDecryptFileInfo();
|
||||
fileInfo.BundleName = _bundle.BundleName;
|
||||
fileInfo.FileLoadCRC = _bundle.UnityCRC;
|
||||
var fileInfo = new WebDecryptBundleInfo();
|
||||
fileInfo.BundleName = _options.Bundle.BundleName;
|
||||
fileInfo.FileLoadCRC = _options.Bundle.UnityCRC;
|
||||
fileInfo.FileData = fileData;
|
||||
var decryptResult = _decryptionServices.LoadAssetBundle(fileInfo);
|
||||
var decryptResult = _decryptionServices.LoadAssetBundleSync(fileInfo);
|
||||
return decryptResult.Result;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace YooAsset
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PackageBundle _bundle;
|
||||
private readonly DownloadFileOptions _options;
|
||||
private readonly bool _disableUnityWebCache;
|
||||
private readonly IDownloadBackend _downloadBackend;
|
||||
@@ -25,9 +24,8 @@ namespace YooAsset
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal LoadWebNormalAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options, bool disableUnityWebCache, IDownloadBackend downloadBackend)
|
||||
internal LoadWebNormalAssetBundleOperation(DownloadFileOptions options, bool disableUnityWebCache, IDownloadBackend downloadBackend)
|
||||
{
|
||||
_bundle = bundle;
|
||||
_options = options;
|
||||
_failedTryAgain = options.FailedTryAgain;
|
||||
_disableUnityWebCache = disableUnityWebCache;
|
||||
@@ -46,7 +44,7 @@ namespace YooAsset
|
||||
if (_steps == ESteps.CreateRequest)
|
||||
{
|
||||
string url = GetRequestURL();
|
||||
var args = new DownloadAssetBundleRequestArgs(url, 0, 0, _disableUnityWebCache, _bundle.FileHash, _bundle.UnityCRC);
|
||||
var args = new DownloadAssetBundleRequestArgs(url, 0, 0, _disableUnityWebCache, _options.Bundle.FileHash, _options.Bundle.UnityCRC);
|
||||
_unityAssetBundleRequestOp = _downloadBackend.CreateAssetBundleRequest(args);
|
||||
_unityAssetBundleRequestOp.SendRequest();
|
||||
_steps = ESteps.CheckRequest;
|
||||
@@ -72,7 +70,7 @@ namespace YooAsset
|
||||
if (_failedTryAgain > 0)
|
||||
{
|
||||
_steps = ESteps.TryAgain;
|
||||
YooLogger.Warning($"Failed download : {_unityAssetBundleRequestOp.URL} Try again !");
|
||||
YooLogger.Warning($"Failed download : {_unityAssetBundleRequestOp.URL} Try again.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -80,7 +80,7 @@ internal class LoadWebPackageManifestOperation : AsyncOperationBase
|
||||
|
||||
if (_steps == ESteps.VerifyFileData)
|
||||
{
|
||||
if (ManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
|
||||
if (PackageManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
|
||||
{
|
||||
_steps = ESteps.LoadManifest;
|
||||
}
|
||||
@@ -88,7 +88,7 @@ internal class LoadWebPackageManifestOperation : AsyncOperationBase
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to verify web package manifest file!";
|
||||
Error = "Failed to verify web package manifest file.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ internal class RequestWebPackageHashOperation : AsyncOperationBase
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Web package hash file content is empty !";
|
||||
Error = $"Web package hash file content is empty.";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -64,7 +64,7 @@ internal class RequestWebPackageVersionOperation : AsyncOperationBase
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Web package version file content is empty !";
|
||||
Error = $"Web package version file content is empty.";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -10,17 +10,22 @@ namespace YooAsset
|
||||
{
|
||||
private List<AsyncOperationBase> _childs;
|
||||
private Action<AsyncOperationBase> _callback;
|
||||
private int _whileFrame = 1000;
|
||||
private uint _priority;
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步执行完成
|
||||
/// </summary>
|
||||
internal bool IsWaitForAsyncComplete { private set; get; } = false;
|
||||
internal bool IsWaitForAsyncComplete { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标记脏(用于调度器检测并重排)
|
||||
/// </summary>
|
||||
internal bool IsDirty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经完成
|
||||
/// </summary>
|
||||
internal bool IsFinish { private set; get; } = false;
|
||||
internal bool IsFinish { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 异步系统是否繁忙
|
||||
@@ -38,7 +43,20 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 任务优先级
|
||||
/// </summary>
|
||||
public uint Priority { set; get; } = 0;
|
||||
public uint Priority
|
||||
{
|
||||
set
|
||||
{
|
||||
if (_priority == value)
|
||||
return;
|
||||
_priority = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
get
|
||||
{
|
||||
return _priority;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 任务状态
|
||||
@@ -80,6 +98,7 @@ namespace YooAsset
|
||||
{
|
||||
try
|
||||
{
|
||||
//注意:任务已完成,立即调用回调
|
||||
value.Invoke(this);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -122,7 +141,7 @@ namespace YooAsset
|
||||
}
|
||||
internal virtual void InternalWaitForAsyncComplete()
|
||||
{
|
||||
throw new System.NotImplementedException(this.GetType().Name);
|
||||
throw new YooInternalException($"InternalWaitForAsyncComplete() not implemented : {this.GetType().Name}");
|
||||
}
|
||||
internal virtual string InternalGetDesc()
|
||||
{
|
||||
@@ -137,9 +156,19 @@ namespace YooAsset
|
||||
if (_childs == null)
|
||||
_childs = new List<AsyncOperationBase>(10);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
#if UNITY_EDITOR || DEBUG
|
||||
if (child == null)
|
||||
throw new YooInternalException("The child node is null.");
|
||||
|
||||
if (ReferenceEquals(child, this))
|
||||
throw new YooInternalException("The child node cannot be itself.");
|
||||
|
||||
if (_childs.Contains(child))
|
||||
throw new YooInternalException($"The child node {child.GetType().Name} already exists !");
|
||||
throw new YooInternalException($"The child node {child.GetType().Name} already exists.");
|
||||
|
||||
// 禁止形成环依赖
|
||||
if (WouldCreateCycle(child))
|
||||
throw new YooInternalException($"AddChildOperation would create a cycle : {this.GetType().Name} -> {child.GetType().Name}");
|
||||
#endif
|
||||
|
||||
_childs.Add(child);
|
||||
@@ -153,9 +182,12 @@ namespace YooAsset
|
||||
if (_childs == null)
|
||||
return;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
#if UNITY_EDITOR || DEBUG
|
||||
if (child == null)
|
||||
throw new YooInternalException("The child node is null.");
|
||||
|
||||
if (_childs.Contains(child) == false)
|
||||
throw new YooInternalException($"The child node {child.GetType().Name} not exists !");
|
||||
throw new YooInternalException($"The child node {child.GetType().Name} not exists.");
|
||||
#endif
|
||||
|
||||
_childs.Remove(child);
|
||||
@@ -182,7 +214,16 @@ namespace YooAsset
|
||||
DebugBeginRecording();
|
||||
|
||||
// 开始任务
|
||||
InternalStart();
|
||||
try
|
||||
{
|
||||
InternalStart();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = ex.ToString();
|
||||
YooLogger.Error($"Exception in {this.GetType().Name}.InternalStart : {ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +238,18 @@ namespace YooAsset
|
||||
DebugUpdateRecording();
|
||||
|
||||
// 更新任务
|
||||
InternalUpdate();
|
||||
// 注意:兜底隔离机制
|
||||
// 说明:检测的异常源包含:I/O(解压/读写权限/磁盘满),平台差异等
|
||||
try
|
||||
{
|
||||
InternalUpdate();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = ex.ToString();
|
||||
YooLogger.Error($"Exception in {this.GetType().Name}.InternalUpdate : {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
if (IsDone && IsFinish == false)
|
||||
@@ -224,14 +276,17 @@ namespace YooAsset
|
||||
InternalAbort();
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "user abort";
|
||||
YooLogger.Warning($"Async operation {this.GetType().Name} has been aborted !");
|
||||
YooLogger.Warning($"Async operation {this.GetType().Name} has been aborted.");
|
||||
}
|
||||
|
||||
//注意:强制收尾,确保Task能完成
|
||||
FinishOperation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 强制结束异步任务
|
||||
/// </summary>
|
||||
internal void FinishOperation()
|
||||
private void FinishOperation()
|
||||
{
|
||||
if (IsFinish == false)
|
||||
{
|
||||
@@ -241,43 +296,85 @@ namespace YooAsset
|
||||
// 结束记录
|
||||
DebugEndRecording();
|
||||
|
||||
try
|
||||
if (_callback != null)
|
||||
{
|
||||
_callback?.Invoke(this);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
YooLogger.Error($"Exception in completion callback: {ex}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
_callback = null;
|
||||
if (_taskCompletionSource != null)
|
||||
_taskCompletionSource.TrySetResult(null);
|
||||
var invocationList = _callback.GetInvocationList();
|
||||
foreach (var handler in invocationList)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Action<AsyncOperationBase>)handler).Invoke(this);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
YooLogger.Error($"Exception in completion callback: {ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_callback = null;
|
||||
if (_taskCompletionSource != null)
|
||||
_taskCompletionSource.TrySetResult(null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行While循环
|
||||
/// 执行一次更新逻辑
|
||||
/// </summary>
|
||||
protected bool ExecuteWhileDone()
|
||||
protected void RunOnceExecution()
|
||||
{
|
||||
if (IsDone == false)
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
UpdateOperation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量执行一定次数的更新逻辑
|
||||
/// </summary>
|
||||
/// <param name="count">最大执行次数,默认1000次</param>
|
||||
/// <remarks>
|
||||
/// 用于需要快速完成但又不想完全阻塞主线程的场景。
|
||||
/// </remarks>
|
||||
protected void RunBatchExecution(int count = 1000)
|
||||
{
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
int runCount = count;
|
||||
while (true)
|
||||
{
|
||||
// 执行更新逻辑
|
||||
InternalUpdate();
|
||||
UpdateOperation();
|
||||
if (IsDone)
|
||||
break;
|
||||
|
||||
// 当执行次数用完时
|
||||
_whileFrame--;
|
||||
if (_whileFrame <= 0)
|
||||
{
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Operation {this.GetType().Name} failed to wait for async complete !";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
runCount--;
|
||||
if (runCount <= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 无限次数的执行更新逻辑,直到任务完成
|
||||
/// 注意:该方法会阻塞主线程
|
||||
/// </summary>
|
||||
/// <param name="sleepMS">休眠时长</param>
|
||||
protected void RunUntilCompletion(int sleepMS = 1)
|
||||
{
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
while (true)
|
||||
{
|
||||
UpdateOperation();
|
||||
if (IsDone)
|
||||
break;
|
||||
|
||||
// 注意: 短暂休眠避免完全占用CPU资源
|
||||
System.Threading.Thread.Sleep(sleepMS);
|
||||
}
|
||||
return IsDone;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -285,11 +382,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public void WaitForAsyncComplete()
|
||||
{
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
//TODO 防止异步操作被挂起陷入无限死循环!
|
||||
// 例如:文件解压任务或者文件导入任务!
|
||||
//注意:防止异步操作被挂起陷入无限死循环!
|
||||
if (Status == EOperationStatus.None)
|
||||
{
|
||||
StartOperation();
|
||||
@@ -298,12 +391,19 @@ namespace YooAsset
|
||||
if (IsWaitForAsyncComplete == false)
|
||||
{
|
||||
IsWaitForAsyncComplete = true;
|
||||
InternalWaitForAsyncComplete();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (IsDone == false)
|
||||
throw new YooInternalException($"WaitForAsyncComplete() must complete operation: {this.GetType().Name}");
|
||||
#endif
|
||||
InternalWaitForAsyncComplete();
|
||||
|
||||
if (IsDone == false)
|
||||
{
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Operation {this.GetType().Name} failed to wait for async complete.";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
|
||||
//注意:强制收尾,确保Task能完成
|
||||
FinishOperation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,12 +411,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 开始的时间
|
||||
/// </summary>
|
||||
public string BeginTime = string.Empty;
|
||||
public string BeginTime { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// 处理耗时(单位:毫秒)
|
||||
/// </summary>
|
||||
public long ProcessTime { protected set; get; }
|
||||
public long ProcessTime { get; protected set; }
|
||||
|
||||
// 加载耗时统计
|
||||
private Stopwatch _watch = null;
|
||||
@@ -326,7 +426,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_watch == null)
|
||||
{
|
||||
BeginTime = SpawnTimeToString(UnityEngine.Time.realtimeSinceStartup);
|
||||
BeginTime = SpawnTimeToString(TimeUtility.RealtimeSinceStartup);
|
||||
_watch = Stopwatch.StartNew();
|
||||
}
|
||||
}
|
||||
@@ -350,14 +450,60 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
private string SpawnTimeToString(float spawnTime)
|
||||
private string SpawnTimeToString(double spawnTime)
|
||||
{
|
||||
float h = UnityEngine.Mathf.FloorToInt(spawnTime / 3600f);
|
||||
float m = UnityEngine.Mathf.FloorToInt(spawnTime / 60f - h * 60f);
|
||||
float s = UnityEngine.Mathf.FloorToInt(spawnTime - m * 60f - h * 3600f);
|
||||
double h = System.Math.Floor(spawnTime / 3600);
|
||||
double m = System.Math.Floor(spawnTime / 60 - h * 60);
|
||||
double s = System.Math.Floor(spawnTime - m * 60 - h * 3600);
|
||||
return h.ToString("00") + ":" + m.ToString("00") + ":" + s.ToString("00");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测添加子任务是否会形成循环依赖
|
||||
/// 使用深度优先搜索(DFS)遍历子任务图
|
||||
/// </summary>
|
||||
private bool WouldCreateCycle(AsyncOperationBase child)
|
||||
{
|
||||
const int MaxCycleCheckDepth = 4096; // 循环检测最大深度
|
||||
var stack = new Stack<AsyncOperationBase>();
|
||||
var visited = new HashSet<AsyncOperationBase>();
|
||||
stack.Push(child);
|
||||
|
||||
while (stack.Count > 0)
|
||||
{
|
||||
var node = stack.Pop();
|
||||
if (node == null)
|
||||
continue;
|
||||
|
||||
// 防止重复访问
|
||||
if (visited.Add(node) == false)
|
||||
continue;
|
||||
|
||||
// 防止无限循环(图过大)
|
||||
if (visited.Count > MaxCycleCheckDepth)
|
||||
throw new YooInternalException("Child operation graph is too large, cycle check aborted.");
|
||||
|
||||
// 检测循环:如果遍历到自己,说明形成循环
|
||||
if (ReferenceEquals(node, this))
|
||||
return true;
|
||||
|
||||
if (node._childs == null)
|
||||
continue;
|
||||
|
||||
// 将子节点加入栈
|
||||
for (int i = 0; i < node._childs.Count; i++)
|
||||
{
|
||||
stack.Push(node._childs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取调试信息
|
||||
/// 注意:递归构建子树存在深度风险
|
||||
/// </summary>
|
||||
internal DebugOperationInfo GetDebugOperationInfo()
|
||||
{
|
||||
var operationInfo = new DebugOperationInfo();
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public abstract class GameAsyncOperation : AsyncOperationBase
|
||||
{
|
||||
internal override void InternalStart()
|
||||
{
|
||||
OnStart();
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
OnUpdate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步操作开始
|
||||
/// </summary>
|
||||
protected abstract void OnStart();
|
||||
|
||||
/// <summary>
|
||||
/// 异步操作更新
|
||||
/// </summary>
|
||||
protected abstract void OnUpdate();
|
||||
}
|
||||
}
|
||||
@@ -10,40 +10,56 @@ namespace YooAsset
|
||||
{
|
||||
private readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(100);
|
||||
private readonly List<AsyncOperationBase> _newList = new List<AsyncOperationBase>(100);
|
||||
private uint _priority;
|
||||
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName { private set; get; }
|
||||
public string PackageName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 调度器优先级(值越大越优先)
|
||||
/// </summary>
|
||||
public int Priority { private set; get; }
|
||||
public uint Priority
|
||||
{
|
||||
get { return _priority; }
|
||||
set
|
||||
{
|
||||
if (_priority != value)
|
||||
{
|
||||
_priority = value;
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 优先级是否已变更(需要重新排序)
|
||||
/// </summary>
|
||||
public bool IsDirty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建顺序(用于同优先级稳定排序)
|
||||
/// </summary>
|
||||
public int CreateIndex { private set; get; }
|
||||
public int CreateIndex { get; private set; }
|
||||
|
||||
|
||||
public OperationScheduler(string packageName, int priority, int createIndex)
|
||||
public OperationScheduler(string packageName, int createIndex)
|
||||
{
|
||||
PackageName = packageName;
|
||||
Priority = priority;
|
||||
CreateIndex = createIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始处理异步操作
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 操作会先添加到临时队列,在下一次Update时才会开始执行
|
||||
/// </remarks>
|
||||
public void StartOperation(AsyncOperationBase operation)
|
||||
{
|
||||
_newList.Add(operation);
|
||||
operation.StartOperation();
|
||||
|
||||
// 通知开始回调
|
||||
OperationSystem.InvokeStartCallback(PackageName, operation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,31 +74,29 @@ namespace YooAsset
|
||||
if (operation.IsFinish)
|
||||
{
|
||||
_operations.RemoveAt(i);
|
||||
|
||||
// 通知完成回调
|
||||
OperationSystem.InvokeFinishCallback(PackageName, operation);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加新增的异步操作
|
||||
if (_newList.Count > 0)
|
||||
{
|
||||
bool sorting = false;
|
||||
foreach (var operation in _newList)
|
||||
{
|
||||
if (operation.Priority > 0)
|
||||
{
|
||||
sorting = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_operations.AddRange(_newList);
|
||||
_newList.Clear();
|
||||
}
|
||||
|
||||
// 重新排序优先级
|
||||
if (sorting)
|
||||
_operations.Sort();
|
||||
// 检测是否需要执行排序
|
||||
bool isDirty = false;
|
||||
foreach (var operation in _operations)
|
||||
{
|
||||
if (operation.IsDirty)
|
||||
{
|
||||
operation.IsDirty = false;
|
||||
isDirty = true;
|
||||
}
|
||||
}
|
||||
if (isDirty)
|
||||
{
|
||||
_operations.Sort();
|
||||
}
|
||||
|
||||
// 更新进行中的异步操作
|
||||
@@ -109,7 +123,6 @@ namespace YooAsset
|
||||
foreach (var operation in _newList)
|
||||
{
|
||||
operation.AbortOperation();
|
||||
operation.FinishOperation(); //注意:强制收尾,确保Task能完成
|
||||
}
|
||||
_newList.Clear();
|
||||
|
||||
@@ -117,7 +130,6 @@ namespace YooAsset
|
||||
foreach (var operation in _operations)
|
||||
{
|
||||
operation.AbortOperation();
|
||||
operation.FinishOperation(); //注意:强制收尾,确保Task能完成
|
||||
}
|
||||
_operations.Clear();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Diagnostics;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class OperationSystem
|
||||
internal static class OperationSystem
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
@@ -15,25 +15,41 @@ namespace YooAsset
|
||||
}
|
||||
#endif
|
||||
|
||||
// 全局调度器名称
|
||||
public const string GLOBAL_SCHEDULER_NAME = "";
|
||||
public const string GlobalSchedulerName = "YOOASSET_GLOBAL_SCHEDULER"; // 全局调度器名称
|
||||
private const long MinTimeSlice = 10; // 最小时间片(毫秒)
|
||||
|
||||
private static readonly Dictionary<string, OperationScheduler> _schedulerDic = new Dictionary<string, OperationScheduler>(100);
|
||||
private static readonly List<OperationScheduler> _schedulerList = new List<OperationScheduler>(100);
|
||||
private static bool _schedulerListDirty = false;
|
||||
private static int _createIndex = 0;
|
||||
|
||||
private static Action<string, AsyncOperationBase> _startCallback = null;
|
||||
private static Action<string, AsyncOperationBase> _finishCallback = null;
|
||||
private static bool _isInitialized;
|
||||
private static int _createIndex;
|
||||
|
||||
// 计时器相关
|
||||
private static Stopwatch _watch;
|
||||
private static long _frameTime;
|
||||
private static long _maxTimeSlice = long.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// 异步操作系统的每帧最大执行预算(毫秒)
|
||||
/// </summary>
|
||||
public static long MaxTimeSlice { set; get; } = long.MaxValue;
|
||||
public static long MaxTimeSlice
|
||||
{
|
||||
get
|
||||
{
|
||||
return _maxTimeSlice;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < MinTimeSlice)
|
||||
{
|
||||
_maxTimeSlice = MinTimeSlice;
|
||||
YooLogger.Warning($"MaxTimeSlice minimum value is {MinTimeSlice} milliseconds.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_maxTimeSlice = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步操作系统是否繁忙
|
||||
@@ -45,11 +61,11 @@ namespace YooAsset
|
||||
if (_watch == null)
|
||||
return false;
|
||||
|
||||
if (MaxTimeSlice == long.MaxValue)
|
||||
if (_maxTimeSlice == long.MaxValue)
|
||||
return false;
|
||||
|
||||
// 注意 : 单次调用开销约1微秒
|
||||
return _watch.ElapsedMilliseconds - _frameTime >= MaxTimeSlice;
|
||||
return _watch.ElapsedMilliseconds - _frameTime >= _maxTimeSlice;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,10 +75,17 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static void Initialize()
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
YooLogger.Warning("Operation system is already initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
_isInitialized = true;
|
||||
_watch = Stopwatch.StartNew();
|
||||
|
||||
// 创建全局调度器
|
||||
CreatePackageScheduler(GLOBAL_SCHEDULER_NAME, 0);
|
||||
CreatePackageScheduler(GlobalSchedulerName, uint.MaxValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,10 +93,21 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static void Update()
|
||||
{
|
||||
// 重新排序调度器
|
||||
if (_schedulerListDirty)
|
||||
if (_isInitialized == false)
|
||||
return;
|
||||
|
||||
// 检测是否需要执行排序
|
||||
bool isDirty = false;
|
||||
foreach (var scheduler in _schedulerList)
|
||||
{
|
||||
if (scheduler.IsDirty)
|
||||
{
|
||||
scheduler.IsDirty = false;
|
||||
isDirty = true;
|
||||
}
|
||||
}
|
||||
if (isDirty)
|
||||
{
|
||||
_schedulerListDirty = false;
|
||||
_schedulerList.Sort();
|
||||
}
|
||||
|
||||
@@ -95,6 +129,8 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static void DestroyAll()
|
||||
{
|
||||
_isInitialized = false;
|
||||
|
||||
// 清空所有调度器
|
||||
foreach (var scheduler in _schedulerList)
|
||||
{
|
||||
@@ -102,41 +138,43 @@ namespace YooAsset
|
||||
}
|
||||
_schedulerDic.Clear();
|
||||
_schedulerList.Clear();
|
||||
_schedulerListDirty = false;
|
||||
_createIndex = 0;
|
||||
|
||||
_startCallback = null;
|
||||
_finishCallback = null;
|
||||
_watch = null;
|
||||
_frameTime = 0;
|
||||
MaxTimeSlice = long.MaxValue;
|
||||
_maxTimeSlice = long.MaxValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建包裹调度器
|
||||
/// </summary>
|
||||
internal static void CreatePackageScheduler(string packageName, int priority)
|
||||
public static OperationScheduler CreatePackageScheduler(string packageName, uint priority)
|
||||
{
|
||||
DebugEnsureInitialized(packageName);
|
||||
|
||||
if (_schedulerDic.ContainsKey(packageName))
|
||||
{
|
||||
throw new YooInternalException($"Package scheduler already exists: {packageName}");
|
||||
}
|
||||
|
||||
var scheduler = new OperationScheduler(packageName, priority, _createIndex++);
|
||||
var scheduler = new OperationScheduler(packageName, _createIndex++);
|
||||
_schedulerDic.Add(packageName, scheduler);
|
||||
_schedulerList.Add(scheduler);
|
||||
_schedulerListDirty = true;
|
||||
scheduler.Priority = priority;
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁包裹调度器
|
||||
/// </summary>
|
||||
internal static void DestroyPackageScheduler(string packageName)
|
||||
public static void DestroyPackageScheduler(string packageName)
|
||||
{
|
||||
DebugEnsureInitialized(packageName);
|
||||
|
||||
// 不允许销毁默认调度器
|
||||
if (packageName == GLOBAL_SCHEDULER_NAME)
|
||||
if (packageName == GlobalSchedulerName)
|
||||
{
|
||||
throw new YooInternalException("Cannot destroy the global package scheduler!");
|
||||
throw new YooInternalException("Cannot destroy the global package scheduler.");
|
||||
}
|
||||
|
||||
if (_schedulerDic.TryGetValue(packageName, out var scheduler))
|
||||
@@ -152,6 +190,8 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static void ClearPackageOperation(string packageName)
|
||||
{
|
||||
DebugEnsureInitialized(packageName);
|
||||
|
||||
var scheduler = GetScheduler(packageName);
|
||||
scheduler.ClearAll();
|
||||
}
|
||||
@@ -161,40 +201,32 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static void StartOperation(string packageName, AsyncOperationBase operation)
|
||||
{
|
||||
DebugEnsureInitialized(packageName);
|
||||
|
||||
var scheduler = GetScheduler(packageName);
|
||||
scheduler.StartOperation(operation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 监听任务开始
|
||||
/// 设置调度器优先级
|
||||
/// </summary>
|
||||
public static void RegisterStartCallback(Action<string, AsyncOperationBase> callback)
|
||||
public static void SetSchedulerPriority(string packageName, uint priority)
|
||||
{
|
||||
_startCallback = callback;
|
||||
DebugEnsureInitialized(packageName);
|
||||
|
||||
var scheduler = GetScheduler(packageName);
|
||||
scheduler.Priority = priority;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 监听任务结束
|
||||
/// 获取调度器优先级
|
||||
/// </summary>
|
||||
public static void RegisterFinishCallback(Action<string, AsyncOperationBase> callback)
|
||||
public static uint GetSchedulerPriority(string packageName)
|
||||
{
|
||||
_finishCallback = callback;
|
||||
}
|
||||
DebugEnsureInitialized(packageName);
|
||||
|
||||
/// <summary>
|
||||
/// 触发任务开始回调
|
||||
/// </summary>
|
||||
internal static void InvokeStartCallback(string packageName, AsyncOperationBase operation)
|
||||
{
|
||||
_startCallback?.Invoke(packageName, operation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 触发任务完成回调
|
||||
/// </summary>
|
||||
internal static void InvokeFinishCallback(string packageName, AsyncOperationBase operation)
|
||||
{
|
||||
_finishCallback?.Invoke(packageName, operation);
|
||||
var scheduler = GetScheduler(packageName);
|
||||
return scheduler.Priority;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -202,32 +234,34 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
private static OperationScheduler GetScheduler(string packageName)
|
||||
{
|
||||
// 空包名路由到默认调度器
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
packageName = GLOBAL_SCHEDULER_NAME;
|
||||
|
||||
if (_schedulerDic.TryGetValue(packageName, out var scheduler))
|
||||
{
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
// 严格模式:非默认包裹必须先创建调度器
|
||||
throw new YooInternalException($"Package scheduler not found: {packageName}. Please call YooAssets.CreatePackage() first!");
|
||||
throw new YooInternalException($"Operation scheduler not found: {packageName}.");
|
||||
}
|
||||
|
||||
#region 调试信息
|
||||
internal static List<DebugOperationInfo> GetDebugOperationInfos(string packageName)
|
||||
{
|
||||
// 空包名路由到默认调度器
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
packageName = GLOBAL_SCHEDULER_NAME;
|
||||
DebugEnsureInitialized(packageName);
|
||||
|
||||
if (_schedulerDic.TryGetValue(packageName, out var scheduler))
|
||||
{
|
||||
return scheduler.GetDebugOperationInfos();
|
||||
}
|
||||
var scheduler = GetScheduler(packageName);
|
||||
return scheduler.GetDebugOperationInfos();
|
||||
}
|
||||
#endregion
|
||||
|
||||
return new List<DebugOperationInfo>();
|
||||
#region 调试方法
|
||||
[Conditional("DEBUG")]
|
||||
private static void DebugEnsureInitialized(string packageName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(packageName))
|
||||
throw new YooInternalException("Package name is null or empty.");
|
||||
|
||||
if (_isInitialized == false)
|
||||
throw new YooInternalException($"{nameof(OperationSystem)} not initialized.");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -32,23 +32,23 @@ OperationSystem 是 YooAsset 资源管理系统的**异步操作调度核心**
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ 上层调用者 │
|
||||
│ 上层调用者 │
|
||||
│ (ResourceManager / FileSystem / 业务层) │
|
||||
└─────────────────────────┬───────────────────────────────┘
|
||||
│ StartOperation()
|
||||
┌─────────────────────────▼───────────────────────────────┐
|
||||
│ OperationSystem │
|
||||
│ OperationSystem │
|
||||
│ (调度器) │
|
||||
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
||||
│ │ 优先级队列 │ │ 时间切片 │ │ 回调通知 │ │
|
||||
│ │ 优先级队列 │ │ 时间切片 │ │ 回调通知 │ │
|
||||
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
||||
└─────────────────────────┬───────────────────────────────┘
|
||||
│ UpdateOperation()
|
||||
┌─────────────────────────▼───────────────────────────────┐
|
||||
│ AsyncOperationBase │
|
||||
│ AsyncOperationBase │
|
||||
│ (操作基类) │
|
||||
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
||||
│ │ 状态机 │ │ 子任务管理 │ │ 异步模式 │ │
|
||||
│ │ 状态机 │ │ 子任务管理 │ │ 异步模式 │ │
|
||||
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
||||
└─────────────────────────────────────────────────────────┘
|
||||
```
|
||||
@@ -56,8 +56,8 @@ OperationSystem 是 YooAsset 资源管理系统的**异步操作调度核心**
|
||||
### 核心组件
|
||||
|
||||
- **OperationSystem**: 静态调度器,管理所有操作的执行
|
||||
- **OperationScheduler**: 包裹级调度器,维护操作队列并负责更新调度
|
||||
- **AsyncOperationBase**: 异步操作基类,定义生命周期和状态
|
||||
- **GameAsyncOperation**: 游戏层操作基类,提供更友好的 API
|
||||
- **EOperationStatus**: 操作状态枚举
|
||||
|
||||
---
|
||||
@@ -68,8 +68,8 @@ OperationSystem 是 YooAsset 资源管理系统的**异步操作调度核心**
|
||||
OperationSystem/
|
||||
├── EOperationStatus.cs # 操作状态枚举
|
||||
├── AsyncOperationBase.cs # 异步操作基类
|
||||
├── OperationScheduler.cs # 包裹级调度器
|
||||
├── OperationSystem.cs # 异步操作调度器
|
||||
└── GameAsyncOperation.cs # 游戏层操作基类
|
||||
```
|
||||
|
||||
---
|
||||
@@ -113,12 +113,21 @@ None ─────────────────► Processing ───
|
||||
| `Status` | `EOperationStatus` | 当前状态 |
|
||||
| `Error` | `string` | 错误信息(失败时) |
|
||||
| `Progress` | `float` | 处理进度(0-1) |
|
||||
| `PackageName` | `string` | 所属包裹名称 |
|
||||
| `IsDone` | `bool` | 是否已完成(Succeed 或 Failed) |
|
||||
| `Task` | `Task` | 用于 async/await |
|
||||
| `BeginTime` | `string` | 开始时间(调试用) |
|
||||
| `ProcessTime` | `long` | 处理耗时毫秒(调试用) |
|
||||
|
||||
> 说明:`AsyncOperationBase` 本身不保存包裹名称;包裹名称由 `OperationSystem.StartOperation(packageName, operation)` 传入,并由 `OperationScheduler` 维护。
|
||||
|
||||
#### 内部协作:时间切片(`IsBusy`)
|
||||
|
||||
为配合 `OperationSystem.MaxTimeSlice` 的时间切片预算,`AsyncOperationBase` 提供了内部属性 `IsBusy`(`internal`)用于任务在 `InternalUpdate()` 内主动让出本帧预算。
|
||||
|
||||
- 推荐用法:在 `InternalUpdate()` 内部(或内部子步骤)在执行重逻辑前判断 `IsBusy`,若繁忙则 `return`,把工作拆到下一帧继续执行。
|
||||
- 同步等待特殊处理:当调用了 `WaitForAsyncComplete()` 进入同步等待阶段时,`IsBusy` 会强制返回 `false`,避免因时间切片判断导致同步等待无法推进。
|
||||
- 注意:`WaitForAsyncComplete()` 会阻塞主线程,应谨慎使用;同步等待阶段不受时间切片保护,可能带来卡顿。
|
||||
|
||||
#### 公共事件
|
||||
|
||||
```csharp
|
||||
@@ -150,14 +159,16 @@ public void WaitForAsyncComplete();
|
||||
#### 子任务管理
|
||||
|
||||
```csharp
|
||||
// 子任务列表
|
||||
internal readonly List<AsyncOperationBase> Childs;
|
||||
|
||||
// 添加/移除子任务
|
||||
// 添加/移除子任务(内部使用)
|
||||
internal void AddChildOperation(AsyncOperationBase child);
|
||||
internal void RemoveChildOperation(AsyncOperationBase child);
|
||||
```
|
||||
|
||||
**调用约束(重要):**
|
||||
- 仅允许在 Unity 主线程调用(与 `OperationSystem.Update()` 的调度线程一致)。
|
||||
- 不要在 `InternalUpdate()` 正在遍历/处理中途频繁增删子任务;推荐在任务启动阶段完成子任务挂接,或在确保无并发修改风险的安全点调整。
|
||||
- `AbortOperation()` 会递归中止子任务,子任务的生命周期由父任务统一管理;避免在 `Completed` 回调里再去修改子任务关系,防止时序混乱。
|
||||
|
||||
---
|
||||
|
||||
### OperationSystem(调度器)
|
||||
@@ -206,61 +217,36 @@ public static void ClearPackageOperation(string packageName);
|
||||
/// 启动异步操作
|
||||
/// </summary>
|
||||
public static void StartOperation(string packageName, AsyncOperationBase operation);
|
||||
|
||||
/// <summary>
|
||||
/// 设置调度器优先级
|
||||
/// </summary>
|
||||
public static void SetSchedulerPriority(string packageName, uint priority);
|
||||
|
||||
/// <summary>
|
||||
/// 获取调度器优先级
|
||||
/// </summary>
|
||||
public static uint GetSchedulerPriority(string packageName);
|
||||
```
|
||||
|
||||
#### 包裹调度说明
|
||||
|
||||
- `packageName` 不允许为空(`null` / `""`),否则会抛出异常。
|
||||
- 若需要使用全局调度器,请传入 `OperationSystem.GLOBAL_SCHEDULER_NAME`(`Initialize()` 时自动创建)。
|
||||
- `packageName` 为非全局调度器名称时,必须先通过 `YooAssets.CreatePackage(packageName)` 创建包裹(内部会注册对应 `OperationScheduler`),否则会抛出异常。
|
||||
|
||||
#### 回调监听
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 注册任务开始回调
|
||||
/// </summary>
|
||||
public static void RegisterStartCallback(Action<string, AsyncOperationBase> callback);
|
||||
OperationSystem **当前未提供**全局任务开始/结束回调的注册接口。
|
||||
|
||||
/// <summary>
|
||||
/// 注册任务结束回调
|
||||
/// </summary>
|
||||
public static void RegisterFinishCallback(Action<string, AsyncOperationBase> callback);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### GameAsyncOperation(游戏层基类)
|
||||
|
||||
继承 `AsyncOperationBase`,为业务层提供更友好的 API。
|
||||
如需监听任务结束(推荐),请直接订阅具体任务的 `Completed` 事件:
|
||||
|
||||
```csharp
|
||||
public abstract class GameAsyncOperation : AsyncOperationBase
|
||||
var operation = package.LoadAssetAsync<GameObject>(location);
|
||||
operation.Completed += op =>
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步操作开始
|
||||
/// </summary>
|
||||
protected abstract void OnStart();
|
||||
|
||||
/// <summary>
|
||||
/// 异步操作更新
|
||||
/// </summary>
|
||||
protected abstract void OnUpdate();
|
||||
|
||||
/// <summary>
|
||||
/// 异步操作终止
|
||||
/// </summary>
|
||||
protected abstract void OnAbort();
|
||||
|
||||
/// <summary>
|
||||
/// 异步等待完成(可选重写)
|
||||
/// </summary>
|
||||
protected virtual void OnWaitForAsyncComplete();
|
||||
|
||||
/// <summary>
|
||||
/// 异步操作系统是否繁忙
|
||||
/// </summary>
|
||||
protected bool IsBusy();
|
||||
|
||||
/// <summary>
|
||||
/// 终止异步操作
|
||||
/// </summary>
|
||||
protected void Abort();
|
||||
}
|
||||
// TODO : 根据 op.Status 判断成功/失败
|
||||
};
|
||||
```
|
||||
|
||||
---
|
||||
@@ -339,15 +325,37 @@ void LoadAssetSync()
|
||||
|
||||
操作按 `Priority` 属性降序排列,优先级高的操作先执行。
|
||||
|
||||
#### 操作优先级
|
||||
|
||||
```csharp
|
||||
var operation = package.LoadAssetAsync<GameObject>(location);
|
||||
operation.Priority = 100; // 设置高优先级
|
||||
```
|
||||
|
||||
#### 包裹优先级
|
||||
|
||||
通过 `ResourcePackage.PackagePriority` 可以设置包裹的调度器优先级,值越大越优先更新。
|
||||
|
||||
```csharp
|
||||
// 创建包裹时指定优先级
|
||||
var package = YooAssets.CreatePackage("MyPackage", 100);
|
||||
|
||||
// 运行时动态调整优先级
|
||||
package.PackagePriority = 200;
|
||||
|
||||
// 获取当前优先级
|
||||
uint priority = package.PackagePriority;
|
||||
```
|
||||
|
||||
**使用场景:**
|
||||
- 多包裹场景下,可根据游戏状态动态调整包裹优先级
|
||||
- 例如:进入战斗时提高战斗资源包的优先级,退出战斗时恢复默认优先级
|
||||
|
||||
**排序规则:**
|
||||
- 新操作添加时检查是否需要排序
|
||||
- 仅当存在非零优先级时触发排序
|
||||
- 使用 `List.Sort()` 进行原地排序
|
||||
- 新操作添加时:若新增队列存在非零优先级,则触发排序
|
||||
- 运行中修改 `Priority`:调度器会在每帧 `Update()` 的排序阶段检测 `IsDirty` 并触发重排;若在某个操作的 `InternalUpdate()` 内修改(本帧排序已完成),则新的优先级会延后一帧生效(可能与预期不符)
|
||||
- 若期望本帧生效:请尽量在任务入队前或本帧调度器 `Update()` 开始前设置 `Priority`,避免在 `InternalUpdate()` 内临时调整
|
||||
- 排序使用 `List.Sort()` 进行原地排序;频繁修改优先级会带来额外排序开销,建议按需使用
|
||||
|
||||
### 时间切片
|
||||
|
||||
@@ -358,6 +366,10 @@ operation.Priority = 100; // 设置高优先级
|
||||
OperationSystem.MaxTimeSlice = 8;
|
||||
```
|
||||
|
||||
**操作侧协作建议:**
|
||||
- 在操作的 `InternalUpdate()` 中使用 `IsBusy`(`AsyncOperationBase` 的内部属性)进行“自愿让出”,将重任务拆分到多帧执行。
|
||||
- 在同步等待(`WaitForAsyncComplete()`)阶段,`IsBusy` 会强制返回 `false`,以保证同步等待推进;此时需要自行评估卡顿风险。
|
||||
|
||||
**执行流程:**
|
||||
|
||||
```
|
||||
@@ -420,24 +432,29 @@ OperationSystem.MaxTimeSlice = 8;
|
||||
### 调试信息结构
|
||||
|
||||
```csharp
|
||||
[Serializable]
|
||||
internal struct DebugOperationInfo
|
||||
{
|
||||
public string OperationName; // 操作类型名
|
||||
public string OperationDesc; // 操作描述
|
||||
public string OperationName; // 任务名称
|
||||
public string OperationDesc; // 任务说明
|
||||
public uint Priority; // 优先级
|
||||
public float Progress; // 进度
|
||||
public string BeginTime; // 开始时间
|
||||
public long ProcessTime; // 处理耗时(毫秒)
|
||||
public string Status; // 状态
|
||||
public List<DebugOperationInfo> Childs; // 子操作
|
||||
public float Progress; // 任务进度
|
||||
public string BeginTime; // 任务开始的时间
|
||||
public long ProcessTime; // 处理耗时(单位:毫秒)
|
||||
public string Status; // 任务状态
|
||||
public List<DebugOperationInfo> Childs; // 子任务列表(注意:JsonUtility 序列化深度限制)
|
||||
}
|
||||
```
|
||||
|
||||
> 说明:该结构体真实定义位于 `Runtime/DiagnosticSystem/DebugOperationInfo.cs`,这里仅展示关键字段以便理解。
|
||||
|
||||
### 获取调试信息
|
||||
|
||||
```csharp
|
||||
// 获取指定包裹的所有操作信息
|
||||
var infos = OperationSystem.GetDebugOperationInfos("DefaultPackage");
|
||||
// 获取指定包裹的所有操作信息(内部调试接口)
|
||||
// packageName 不允许为空;全局调度器请使用 OperationSystem.GLOBAL_SCHEDULER_NAME
|
||||
// 非全局包裹需先 YooAssets.CreatePackage(packageName)
|
||||
var infos = OperationSystem.GetDebugOperationInfos(OperationSystem.GLOBAL_SCHEDULER_NAME);
|
||||
|
||||
foreach (var info in infos)
|
||||
{
|
||||
@@ -457,105 +474,6 @@ Debug.Log($"处理耗时: {operation.ProcessTime}ms");
|
||||
|
||||
---
|
||||
|
||||
## 使用示例
|
||||
|
||||
### 自定义异步操作
|
||||
|
||||
```csharp
|
||||
public class MyCustomOperation : GameAsyncOperation
|
||||
{
|
||||
private int _step = 0;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
// 初始化操作
|
||||
_step = 0;
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
// 检查系统是否繁忙(时间切片)
|
||||
if (IsBusy())
|
||||
return;
|
||||
|
||||
// 执行步骤
|
||||
switch (_step)
|
||||
{
|
||||
case 0:
|
||||
// 第一步
|
||||
Progress = 0.3f;
|
||||
_step = 1;
|
||||
break;
|
||||
case 1:
|
||||
// 第二步
|
||||
Progress = 0.6f;
|
||||
_step = 2;
|
||||
break;
|
||||
case 2:
|
||||
// 完成
|
||||
Status = EOperationStatus.Succeed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAbort()
|
||||
{
|
||||
// 清理资源
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 启动自定义操作
|
||||
|
||||
```csharp
|
||||
var operation = new MyCustomOperation();
|
||||
OperationSystem.StartOperation("DefaultPackage", operation);
|
||||
|
||||
// 使用回调
|
||||
operation.Completed += (op) =>
|
||||
{
|
||||
if (op.Status == EOperationStatus.Succeed)
|
||||
Debug.Log("操作成功");
|
||||
};
|
||||
|
||||
// 或使用 await
|
||||
await operation.Task;
|
||||
```
|
||||
|
||||
### 带子任务的操作
|
||||
|
||||
```csharp
|
||||
public class ParentOperation : GameAsyncOperation
|
||||
{
|
||||
private ChildOperation _child;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
_child = new ChildOperation();
|
||||
AddChildOperation(_child); // 添加子任务
|
||||
OperationSystem.StartOperation(PackageName, _child);
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (_child.IsDone)
|
||||
{
|
||||
if (_child.Status == EOperationStatus.Succeed)
|
||||
Status = EOperationStatus.Succeed;
|
||||
else
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAbort()
|
||||
{
|
||||
// 子任务会自动中止
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 设计模式
|
||||
|
||||
### 模板方法模式
|
||||
@@ -589,7 +507,7 @@ AsyncOperationBase
|
||||
|
||||
### 组合模式
|
||||
|
||||
通过 `Childs` 列表支持父子操作关系:
|
||||
通过内部子任务列表支持父子操作关系:
|
||||
|
||||
```
|
||||
ParentOperation
|
||||
@@ -608,10 +526,6 @@ IEnumerator + IComparable<AsyncOperationBase>
|
||||
│
|
||||
▼
|
||||
AsyncOperationBase (抽象基类)
|
||||
│
|
||||
├── GameAsyncOperation (游戏层基类)
|
||||
│ │
|
||||
│ └── [业务层自定义操作]
|
||||
│
|
||||
└── [YooAsset 内部操作]
|
||||
│
|
||||
@@ -632,4 +546,4 @@ IEnumerator + IComparable<AsyncOperationBase>
|
||||
4. **子任务中止**:父操作中止时会自动中止所有子操作
|
||||
5. **回调异常**:`Completed` 回调中的异常会被捕获并记录,不会中断系统
|
||||
6. **编辑器重置**:编辑器中使用 `RuntimeInitializeOnLoadMethod` 自动重置状态
|
||||
7. **循环保护**:`WaitForAsyncComplete()` 有 1000 帧上限,防止无限循环
|
||||
7. **循环保护**:在 `InternalWaitForAsyncComplete()` 中建议使用 `RunBatchExecution()`(默认 1000 次)限制单次推进次数,避免陷入无限循环或长时间占用主线程
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class EditorSimulateModeHelper
|
||||
public class EditorSimulateBuildInvoker
|
||||
{
|
||||
public static PackageInvokeBuildResult SimulateBuild(string packageName)
|
||||
public static PackageInvokeBuildResult Build(string packageName)
|
||||
{
|
||||
var buildParam = new PackageInvokeBuildParam(packageName);
|
||||
buildParam.BuildPipelineName = "EditorSimulateBuildPipeline";
|
||||
@@ -6,22 +6,22 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 下载是否已经完成
|
||||
/// </summary>
|
||||
public bool IsDone;
|
||||
public bool IsDone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度(0-1f)
|
||||
/// </summary>
|
||||
public float Progress;
|
||||
public float Progress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件的总大小
|
||||
/// </summary>
|
||||
public long TotalBytes;
|
||||
public long TotalBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 已经下载的文件大小
|
||||
/// </summary>
|
||||
public long DownloadedBytes;
|
||||
public long DownloadedBytes { get; set; }
|
||||
|
||||
public static DownloadStatus CreateDefaultStatus()
|
||||
{
|
||||
|
||||
@@ -76,62 +76,48 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public GameObject InstantiateSync()
|
||||
{
|
||||
return InstantiateSyncInternal(false, Vector3.zero, Quaternion.identity, null, false);
|
||||
var options = new InstantiateOptions(true);
|
||||
return InstantiateSyncInternal(options);
|
||||
}
|
||||
public GameObject InstantiateSync(Transform parent)
|
||||
|
||||
/// <summary>
|
||||
/// 同步初始化游戏对象
|
||||
/// </summary>
|
||||
public GameObject InstantiateSync(InstantiateOptions options)
|
||||
{
|
||||
return InstantiateSyncInternal(false, Vector3.zero, Quaternion.identity, parent, false);
|
||||
}
|
||||
public GameObject InstantiateSync(Transform parent, bool worldPositionStays)
|
||||
{
|
||||
return InstantiateSyncInternal(false, Vector3.zero, Quaternion.identity, parent, worldPositionStays);
|
||||
}
|
||||
public GameObject InstantiateSync(Vector3 position, Quaternion rotation)
|
||||
{
|
||||
return InstantiateSyncInternal(true, position, rotation, null, false);
|
||||
}
|
||||
public GameObject InstantiateSync(Vector3 position, Quaternion rotation, Transform parent)
|
||||
{
|
||||
return InstantiateSyncInternal(true, position, rotation, parent, false);
|
||||
return InstantiateSyncInternal(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化游戏对象
|
||||
/// </summary>
|
||||
public InstantiateOperation InstantiateAsync(bool actived = true)
|
||||
public InstantiateOperation InstantiateAsync()
|
||||
{
|
||||
return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, null, false, actived);
|
||||
}
|
||||
public InstantiateOperation InstantiateAsync(Transform parent, bool actived = true)
|
||||
{
|
||||
return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, false, actived);
|
||||
}
|
||||
public InstantiateOperation InstantiateAsync(Transform parent, bool worldPositionStays, bool actived = true)
|
||||
{
|
||||
return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, worldPositionStays, actived);
|
||||
}
|
||||
public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, bool actived = true)
|
||||
{
|
||||
return InstantiateAsyncInternal(true, position, rotation, null, false, actived);
|
||||
}
|
||||
public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent, bool actived = true)
|
||||
{
|
||||
return InstantiateAsyncInternal(true, position, rotation, parent, false, actived);
|
||||
var options = new InstantiateOptions(true);
|
||||
return InstantiateAsyncInternal(options);
|
||||
}
|
||||
|
||||
private GameObject InstantiateSyncInternal(bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays)
|
||||
/// <summary>
|
||||
/// 异步初始化游戏对象
|
||||
/// </summary>
|
||||
public InstantiateOperation InstantiateAsync(InstantiateOptions options)
|
||||
{
|
||||
return InstantiateAsyncInternal(options);
|
||||
}
|
||||
|
||||
private GameObject InstantiateSyncInternal(InstantiateOptions options)
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
if (Provider.AssetObject == null)
|
||||
return null;
|
||||
|
||||
return InstantiateOperation.InstantiateInternal(Provider.AssetObject, setPositionAndRotation, position, rotation, parent, worldPositionStays);
|
||||
return InstantiateOperation.InstantiateInternal(Provider.AssetObject, options);
|
||||
}
|
||||
private InstantiateOperation InstantiateAsyncInternal(bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays, bool actived)
|
||||
private InstantiateOperation InstantiateAsyncInternal(InstantiateOptions options)
|
||||
{
|
||||
string packageName = GetAssetInfo().PackageName;
|
||||
InstantiateOperation operation = new InstantiateOperation(this, setPositionAndRotation, position, rotation, parent, worldPositionStays, actived);
|
||||
InstantiateOperation operation = new InstantiateOperation(this, options);
|
||||
OperationSystem.StartOperation(packageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace YooAsset
|
||||
/// 异步卸载场景对象
|
||||
/// 注意:场景卸载成功后,会自动释放该handle的引用计数!
|
||||
/// </summary>
|
||||
public UnloadSceneOperation UnloadAsync()
|
||||
public UnloadSceneOperation UnloadSceneAsync()
|
||||
{
|
||||
string packageName = GetAssetInfo().PackageName;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user