Compare commits

..

3 Commits

Author SHA1 Message Date
何冠峰
0a1c81faf1 refactor : 重构代码 2026-01-17 18:44:48 +08:00
何冠峰
e10888de93 refactor : 重构代码 2026-01-17 17:06:57 +08:00
何冠峰
da222c6179 refactor : 重构代码 2026-01-17 16:12:03 +08:00
85 changed files with 502 additions and 527 deletions

View File

@@ -36,7 +36,7 @@ namespace YooAsset
public void Register(Guid messageID, UnityAction<MessageEventArgs> callback) public void Register(Guid messageID, UnityAction<MessageEventArgs> callback)
{ {
if (messageID == Guid.Empty) if (messageID == Guid.Empty)
throw new ArgumentException("messageID is empty !"); throw new ArgumentException("messageID is empty.");
if (_messageCallbacks.ContainsKey(messageID) == false) if (_messageCallbacks.ContainsKey(messageID) == false)
_messageCallbacks.Add(messageID, callback); _messageCallbacks.Add(messageID, callback);
@@ -49,7 +49,7 @@ namespace YooAsset
public void Send(Guid messageID, byte[] data) public void Send(Guid messageID, byte[] data)
{ {
if (messageID == Guid.Empty) if (messageID == Guid.Empty)
throw new ArgumentException("messageID is empty !"); throw new ArgumentException("messageID is empty.");
// 接收对方的消息 // 接收对方的消息
RemotePlayerConnection.Instance.HandleEditorMessage(messageID, data); RemotePlayerConnection.Instance.HandleEditorMessage(messageID, data);

View File

@@ -36,7 +36,7 @@ namespace YooAsset
public void Register(Guid messageID, UnityAction<MessageEventArgs> callback) public void Register(Guid messageID, UnityAction<MessageEventArgs> callback)
{ {
if (messageID == Guid.Empty) if (messageID == Guid.Empty)
throw new ArgumentException("messageID is empty !"); throw new ArgumentException("messageID is empty.");
if (_messageCallbacks.ContainsKey(messageID) == false) if (_messageCallbacks.ContainsKey(messageID) == false)
_messageCallbacks.Add(messageID, callback); _messageCallbacks.Add(messageID, callback);
@@ -49,7 +49,7 @@ namespace YooAsset
public void Send(Guid messageID, byte[] data) public void Send(Guid messageID, byte[] data)
{ {
if (messageID == Guid.Empty) if (messageID == Guid.Empty)
throw new ArgumentException("messageID is empty !"); throw new ArgumentException("messageID is empty.");
// 接收对方的消息 // 接收对方的消息
RemoteEditorConnection.Instance.HandlePlayerMessage(messageID, data); RemoteEditorConnection.Instance.HandlePlayerMessage(messageID, data);

View File

@@ -76,7 +76,7 @@ namespace YooAsset
else else
{ {
if (string.IsNullOrEmpty(_args.FileHash)) if (string.IsNullOrEmpty(_args.FileHash))
throw new YooInternalException("File hash is null or empty !"); throw new YooInternalException("File hash is null or empty.");
// 使用 Unity 缓存 // 使用 Unity 缓存
// 说明The file hash defining the version of the asset bundle. // 说明The file hash defining the version of the asset bundle.

View File

@@ -109,7 +109,7 @@ namespace YooAsset
catch (Exception ex) catch (Exception ex)
{ {
Status = EDownloadRequestStatus.Failed; 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 else
{ {
Status = EDownloadRequestStatus.Failed; Status = EDownloadRequestStatus.Failed;
Error = $"[{GetType().Name}] URL: {URL} - 错误: {_webRequest.error}"; Error = $"[{GetType().Name}] URL: {URL} - Error: {_webRequest.error}";
OnRequestFailed(); OnRequestFailed();
} }
@@ -226,7 +226,7 @@ namespace YooAsset
protected void ApplyRequestOptions(int timeout, int watchdogTime, Dictionary<string, string> headers) protected void ApplyRequestOptions(int timeout, int watchdogTime, Dictionary<string, string> headers)
{ {
if (_webRequest == null) if (_webRequest == null)
throw new YooInternalException("Web request is null !"); throw new YooInternalException("Web request is null.");
// 设置看门狗超时时间 // 设置看门狗超时时间
_watchdogTime = watchdogTime; _watchdogTime = watchdogTime;

View File

@@ -57,7 +57,7 @@ namespace YooAsset
#elif UNITY_STANDALONE_LINUX #elif UNITY_STANDALONE_LINUX
url = StringUtility.Format("file:///root/{0}", path); url = StringUtility.Format("file:///root/{0}", path);
#else #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 #endif
// For some special cases when users have special characters in their devices, url paths can not be identified correctly. // For some special cases when users have special characters in their devices, url paths can not be identified correctly.

View File

@@ -39,7 +39,7 @@ namespace YooAsset
if (_assetBundle == null) if (_assetBundle == null)
{ {
_steps = ESteps.Done; _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; Status = EOperationStatus.Failed;
return; return;
} }

View File

@@ -39,7 +39,7 @@ namespace YooAsset
if (_assetBundle == null) if (_assetBundle == null)
{ {
_steps = ESteps.Done; _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; Status = EOperationStatus.Failed;
return; return;
} }

View File

@@ -72,7 +72,7 @@ namespace YooAsset
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
{ {
//注意:场景加载无法强制异步转同步 //注意:场景加载无法强制异步转同步
YooLogger.Error("The scene is loading asyn !"); YooLogger.Error("The scene is loading asyn.");
} }
else else
{ {

View File

@@ -39,7 +39,7 @@ namespace YooAsset
if (_assetBundle == null) if (_assetBundle == null)
{ {
_steps = ESteps.Done; _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; Status = EOperationStatus.Failed;
return; return;
} }

View File

@@ -5,7 +5,7 @@ namespace YooAsset
{ {
internal override void InternalStart() internal override void InternalStart()
{ {
Error = $"{nameof(RawBundleLoadAllAssetsOperation)} not support load all assets !"; Error = $"{nameof(RawBundleLoadAllAssetsOperation)} not support load all assets.";
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
} }
internal override void InternalUpdate() internal override void InternalUpdate()

View File

@@ -5,7 +5,7 @@ namespace YooAsset
{ {
internal override void InternalStart() internal override void InternalStart()
{ {
Error = $"{nameof(RawBundleLoadAssetOperation)} not support load asset !"; Error = $"{nameof(RawBundleLoadAssetOperation)} not support load asset.";
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
} }
internal override void InternalUpdate() internal override void InternalUpdate()

View File

@@ -5,7 +5,7 @@ namespace YooAsset
{ {
internal override void InternalStart() internal override void InternalStart()
{ {
Error = $"{nameof(RawBundleLoadSceneOperation)} not support load scene !"; Error = $"{nameof(RawBundleLoadSceneOperation)} not support load scene.";
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
} }
internal override void InternalUpdate() internal override void InternalUpdate()

View File

@@ -5,7 +5,7 @@ namespace YooAsset
{ {
internal override void InternalStart() internal override void InternalStart()
{ {
Error = $"{nameof(RawBundleLoadSubAssetsOperation)} not support load sub assets !"; Error = $"{nameof(RawBundleLoadSubAssetsOperation)} not support load sub assets.";
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
} }
internal override void InternalUpdate() internal override void InternalUpdate()

View File

@@ -28,7 +28,7 @@ namespace YooAsset
_steps = ESteps.CheckBundle; _steps = ESteps.CheckBundle;
#else #else
_steps = ESteps.Done; _steps = ESteps.Done;
Error = $"{nameof(VirtualBundleLoadAllAssetsOperation)} only support unity editor platform !"; Error = $"{nameof(VirtualBundleLoadAllAssetsOperation)} only support unity editor platform.";
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
#endif #endif
} }

View File

@@ -27,7 +27,7 @@ namespace YooAsset
_steps = ESteps.CheckBundle; _steps = ESteps.CheckBundle;
#else #else
_steps = ESteps.Done; _steps = ESteps.Done;
Error = $"{nameof(VirtualBundleLoadAssetOperation)} only support unity editor platform !"; Error = $"{nameof(VirtualBundleLoadAssetOperation)} only support unity editor platform.";
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
#endif #endif
} }

View File

@@ -31,7 +31,7 @@ namespace YooAsset
_steps = ESteps.LoadScene; _steps = ESteps.LoadScene;
#else #else
_steps = ESteps.Done; _steps = ESteps.Done;
Error = $"{nameof(VirtualBundleLoadSceneOperation)} only support unity editor platform !"; Error = $"{nameof(VirtualBundleLoadSceneOperation)} only support unity editor platform.";
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
#endif #endif
} }
@@ -77,7 +77,7 @@ namespace YooAsset
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
{ {
// 注意:场景加载无法强制异步转同步 // 注意:场景加载无法强制异步转同步
YooLogger.Error("The scene is loading asyn !"); YooLogger.Error("The scene is loading asyn.");
} }
else else
{ {

View File

@@ -28,7 +28,7 @@ namespace YooAsset
_steps = ESteps.CheckBundle; _steps = ESteps.CheckBundle;
#else #else
_steps = ESteps.Done; _steps = ESteps.Done;
Error = $"{nameof(VirtualBundleLoadSubAssetsOperation)} only support unity editor platform !"; Error = $"{nameof(VirtualBundleLoadSubAssetsOperation)} only support unity editor platform.";
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
#endif #endif
} }

View File

@@ -206,7 +206,7 @@ namespace YooAsset
public static DefaultBuildinFileCatalog DeserializeFromBinary(byte[] binaryData) public static DefaultBuildinFileCatalog DeserializeFromBinary(byte[] binaryData)
{ {
if (binaryData == null || binaryData.Length == 0) 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); BufferReader buffer = new BufferReader(binaryData);
@@ -214,7 +214,7 @@ namespace YooAsset
// 读取文件标记 // 读取文件标记
uint fileSign = buffer.ReadUInt32(); uint fileSign = buffer.ReadUInt32();
if (fileSign != CatalogFileDefine.FileSign) if (fileSign != CatalogFileDefine.FileSign)
throw new Exception("Invalid catalog file !"); throw new Exception("Invalid catalog file.");
// 读取文件版本 // 读取文件版本
string fileVersion = buffer.ReadUTF8(); string fileVersion = buffer.ReadUTF8();

View File

@@ -333,14 +333,14 @@ namespace YooAsset
#if UNITY_ANDROID #if UNITY_ANDROID
//TODO : 安卓平台内置文件属于APK压缩包内的文件。 //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; return null;
#else #else
if (bundle.Encrypted) if (bundle.Encrypted)
{ {
if (DecryptionServices == null) if (DecryptionServices == null)
{ {
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !"); YooLogger.Error($"The {nameof(IDecryptionServices)} is null.");
return null; return null;
} }
@@ -370,14 +370,14 @@ namespace YooAsset
#if UNITY_ANDROID #if UNITY_ANDROID
//TODO : 安卓平台内置文件属于APK压缩包内的文件。 //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; return null;
#else #else
if (bundle.Encrypted) if (bundle.Encrypted)
{ {
if (DecryptionServices == null) if (DecryptionServices == null)
{ {
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !"); YooLogger.Error($"The {nameof(IDecryptionServices)} is null.");
return null; return null;
} }

View File

@@ -33,7 +33,7 @@ namespace YooAsset
#if UNITY_WEBGL #if UNITY_WEBGL
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"{nameof(DefaultBuildinFileSystem)} is not support WEBGL platform !"; Error = $"{nameof(DefaultBuildinFileSystem)} is not support WEBGL platform.";
#else #else
if (_fileSystem.CopyBuildinPackageManifest) if (_fileSystem.CopyBuildinPackageManifest)
_steps = ESteps.LoadBuildinPackageVersion; _steps = ESteps.LoadBuildinPackageVersion;
@@ -181,7 +181,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Fatal error : catalog is null !"; Error = "Fatal error : catalog is null.";
return; return;
} }

View File

@@ -48,7 +48,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"The {nameof(IBundleDecryptionServices)} is null !"; Error = $"The {nameof(IBundleDecryptionServices)} is null.";
YooLogger.Error(Error); YooLogger.Error(Error);
return; return;
} }
@@ -247,7 +247,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"The {nameof(IDecryptionServices)} is null !"; Error = $"The {nameof(IDecryptionServices)} is null.";
YooLogger.Error(Error); YooLogger.Error(Error);
return; return;
} }

View File

@@ -94,7 +94,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Failed to verify buildin package manifest file !"; Error = "Failed to verify buildin package manifest file.";
} }
} }

View File

@@ -85,7 +85,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Buildin package hash file content is empty !"; Error = $"Buildin package hash file content is empty.";
} }
else else
{ {

View File

@@ -83,7 +83,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Buildin package version file content is empty !"; Error = $"Buildin package version file content is empty.";
} }
else else
{ {

View File

@@ -407,7 +407,7 @@ namespace YooAsset
{ {
if (BundleDecryptionServices == null) if (BundleDecryptionServices == null)
{ {
YooLogger.Error($"The {nameof(IBundleDecryptionServices)} is null !"); YooLogger.Error($"The {nameof(IBundleDecryptionServices)} is null.");
return null; return null;
} }
@@ -435,7 +435,7 @@ namespace YooAsset
{ {
if (BundleDecryptionServices == null) if (BundleDecryptionServices == null)
{ {
YooLogger.Error($"The {nameof(IBundleDecryptionServices)} is null !"); YooLogger.Error($"The {nameof(IBundleDecryptionServices)} is null.");
return null; return null;
} }
@@ -552,7 +552,7 @@ namespace YooAsset
} }
catch (Exception ex) catch (Exception ex)
{ {
YooLogger.Error($"Failed to write cache file ! {ex.Message}"); YooLogger.Error($"Failed to write cache file. Error: {ex.Message}");
return false; return false;
} }

View File

@@ -39,7 +39,7 @@ namespace YooAsset
} }
catch (Exception ex) catch (Exception ex)
{ {
YooLogger.Error($"Failed to delete cache file ! {ex.Message}"); YooLogger.Error($"Failed to delete cache file. Error: {ex.Message}");
return false; return false;
} }
} }

View File

@@ -28,7 +28,7 @@ namespace YooAsset
#if UNITY_WEBGL #if UNITY_WEBGL
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"{nameof(DefaultCacheFileSystem)} is not support WEBGL platform !"; Error = $"{nameof(DefaultCacheFileSystem)} is not support WEBGL platform.";
#else #else
_steps = ESteps.CheckAppFootPrint; _steps = ESteps.CheckAppFootPrint;
#endif #endif
@@ -48,23 +48,23 @@ namespace YooAsset
{ {
if (_fileSystem.InstallClearMode == EOverwriteInstallClearMode.None) 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) else if (_fileSystem.InstallClearMode == EOverwriteInstallClearMode.ClearAllCacheFiles)
{ {
_fileSystem.DeleteAllBundleFiles(); _fileSystem.DeleteAllBundleFiles();
_fileSystem.DeleteAllManifestFiles(); _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) else if (_fileSystem.InstallClearMode == EOverwriteInstallClearMode.ClearAllBundleFiles)
{ {
_fileSystem.DeleteAllBundleFiles(); _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) else if (_fileSystem.InstallClearMode == EOverwriteInstallClearMode.ClearAllManifestFiles)
{ {
_fileSystem.DeleteAllManifestFiles(); _fileSystem.DeleteAllManifestFiles();
YooLogger.Warning("Delete all manifest files when overwrite install application !"); YooLogger.Warning("Delete all manifest files when overwrite install application.");
} }
else else
{ {

View File

@@ -120,7 +120,7 @@ namespace YooAsset
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Abort download file !"; Error = "Abort download file.";
} }
if (_steps == ESteps.LoadAssetBundle) if (_steps == ESteps.LoadAssetBundle)
@@ -131,7 +131,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"The {nameof(IBundleDecryptionServices)} is null !"; Error = $"The {nameof(IBundleDecryptionServices)} is null.";
YooLogger.Error(Error); YooLogger.Error(Error);
return; return;
} }
@@ -389,7 +389,7 @@ namespace YooAsset
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Abort download file !"; Error = "Abort download file.";
} }
if (_steps == ESteps.LoadCacheRawBundle) if (_steps == ESteps.LoadCacheRawBundle)

View File

@@ -45,7 +45,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Can not found active package manifest !"; Error = "Can not found active package manifest.";
} }
else else
{ {
@@ -59,7 +59,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Clear param is null !"; Error = "Clear param is null.";
return; return;
} }

View File

@@ -43,7 +43,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Can not found active package manifest !"; Error = "Can not found active package manifest.";
} }
else else
{ {
@@ -57,7 +57,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Clear param is null !"; Error = "Clear param is null.";
return; return;
} }

View File

@@ -41,7 +41,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Can not found active package manifest !"; Error = "Can not found active package manifest.";
} }
else else
{ {

View File

@@ -38,7 +38,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Can not found active package manifest !"; Error = "Can not found active package manifest.";
} }
else else
{ {

View File

@@ -62,7 +62,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Download file options is invalid !"; Error = "Download file options is invalid.";
Debug.Log(Error); Debug.Log(Error);
return; return;
} }
@@ -95,7 +95,7 @@ namespace YooAsset
if (IsWaitForAsyncComplete == false && _failedTryAgain > 0) if (IsWaitForAsyncComplete == false && _failedTryAgain > 0)
{ {
_steps = ESteps.TryAgain; _steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_downloadFileOp.URL} Try again !"); YooLogger.Warning($"Failed download : {_downloadFileOp.URL} Try again.");
} }
else else
{ {

View File

@@ -51,7 +51,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Cache package hash file content is empty !"; Error = $"Cache package hash file content is empty.";
} }
else else
{ {

View File

@@ -67,7 +67,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Failed to verify cache package manifest file!"; Error = "Failed to verify cache package manifest file.";
} }
} }

View File

@@ -62,7 +62,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Remote package version file content is empty !"; Error = $"Remote package version file content is empty.";
} }
else else
{ {

View File

@@ -170,7 +170,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"{_fileSystem.GetType().FullName} failed to write file !"; Error = $"{_fileSystem.GetType().FullName} failed to write file.";
} }
// 注意:缓存完成后直接删除临时文件 // 注意:缓存完成后直接删除临时文件

View File

@@ -133,7 +133,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"{_fileSystem.GetType().FullName} failed to write file !"; Error = $"{_fileSystem.GetType().FullName} failed to write file.";
} }
// 注意:缓存完成后直接删除临时文件 // 注意:缓存完成后直接删除临时文件
@@ -151,7 +151,7 @@ namespace YooAsset
if (_steps != ESteps.Done) if (_steps != ESteps.Done)
{ {
// 注意:不中断下载任务,保持后台继续下载 // 注意:不中断下载任务,保持后台继续下载
YooLogger.Error($"Try load bundle {_bundle.BundleName} from remote : {URL} !"); YooLogger.Error($"Try load bundle {_bundle.BundleName} from remote : {URL}");
} }
} }

View File

@@ -63,7 +63,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Failed to verify file : {_element.TempFilePath} ! ErrorCode : {VerifyResult}"; Error = $"Failed to verify file : {_element.TempFilePath} ErrorCode : {VerifyResult}";
} }
} }
} }

View File

@@ -161,7 +161,7 @@ namespace YooAsset
PackageName = packageName; PackageName = packageName;
if (string.IsNullOrEmpty(packageRoot)) 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; _packageRoot = packageRoot;

View File

@@ -105,7 +105,7 @@ namespace YooAsset
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Abort download file !"; Error = "Abort download file.";
} }
if (_steps == ESteps.LoadAssetBundle) if (_steps == ESteps.LoadAssetBundle)
@@ -116,7 +116,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Virtual WebGL Mode only support asyn load method !"; Error = "Virtual WebGL Mode only support asyn load method.";
YooLogger.Error(Error); YooLogger.Error(Error);
} }
else else

View File

@@ -61,7 +61,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Download file options is invalid !"; Error = "Download file options is invalid.";
Debug.Log(Error); Debug.Log(Error);
return; return;
} }
@@ -94,7 +94,7 @@ namespace YooAsset
if (IsWaitForAsyncComplete == false && _failedTryAgain > 0) if (IsWaitForAsyncComplete == false && _failedTryAgain > 0)
{ {
_steps = ESteps.TryAgain; _steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_downloadFileOp.URL} Try again !"); YooLogger.Warning($"Failed download : {_downloadFileOp.URL} Try again.");
} }
else else
{ {
@@ -127,7 +127,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Try load bundle {Bundle.BundleName} from remote !"; Error = $"Try load bundle {Bundle.BundleName} from remote.";
YooLogger.Error(Error); YooLogger.Error(Error);
} }
} }

View File

@@ -67,7 +67,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Failed to verify simulation package manifest file !"; Error = "Failed to verify simulation package manifest file.";
} }
} }

View File

@@ -67,7 +67,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"{nameof(DWRFSLoadAssetBundleOperation)} loaded asset bundle is null !"; Error = $"{nameof(DWRFSLoadAssetBundleOperation)} loaded asset bundle is null.";
} }
else else
{ {
@@ -90,7 +90,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "WebGL platform not support sync load method !"; Error = "WebGL platform not support sync load method.";
YooLogger.Error(Error); YooLogger.Error(Error);
} }
} }

View File

@@ -67,7 +67,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"{nameof(DWSFSLoadAssetBundleOperation)} loaded asset bundle is null !"; Error = $"{nameof(DWSFSLoadAssetBundleOperation)} loaded asset bundle is null.";
} }
else else
{ {
@@ -90,7 +90,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "WebGL platform not support sync load method !"; Error = "WebGL platform not support sync load method.";
YooLogger.Error(Error); YooLogger.Error(Error);
} }
} }

View File

@@ -78,7 +78,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Failed to verify web server package manifest file!"; Error = "Failed to verify web server package manifest file.";
} }
} }

View File

@@ -59,7 +59,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Web server package hash file content is empty !"; Error = $"Web server package hash file content is empty.";
} }
else else
{ {

View File

@@ -56,7 +56,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Web server package version file content is empty !"; Error = $"Web server package version file content is empty.";
} }
else else
{ {

View File

@@ -46,7 +46,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"The {nameof(IWebBundleDecryptionServices)} is null !"; Error = $"The {nameof(IWebBundleDecryptionServices)} is null.";
YooLogger.Error(Error); YooLogger.Error(Error);
return; return;
} }
@@ -75,7 +75,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Failed load encrypted AssetBundle !"; Error = "Failed load encrypted AssetBundle.";
} }
else else
{ {
@@ -89,7 +89,7 @@ namespace YooAsset
if (_failedTryAgain > 0) if (_failedTryAgain > 0)
{ {
_steps = ESteps.TryAgain; _steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_unityWebDataRequestOp.URL} Try again !"); YooLogger.Warning($"Failed download : {_unityWebDataRequestOp.URL} Try again.");
} }
else else
{ {

View File

@@ -70,7 +70,7 @@ namespace YooAsset
if (_failedTryAgain > 0) if (_failedTryAgain > 0)
{ {
_steps = ESteps.TryAgain; _steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_unityAssetBundleRequestOp.URL} Try again !"); YooLogger.Warning($"Failed download : {_unityAssetBundleRequestOp.URL} Try again.");
} }
else else
{ {

View File

@@ -88,7 +88,7 @@ internal class LoadWebPackageManifestOperation : AsyncOperationBase
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Failed to verify web package manifest file!"; Error = "Failed to verify web package manifest file.";
} }
} }

View File

@@ -64,7 +64,7 @@ internal class RequestWebPackageHashOperation : AsyncOperationBase
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Web package hash file content is empty !"; Error = $"Web package hash file content is empty.";
} }
else else
{ {

View File

@@ -64,7 +64,7 @@ internal class RequestWebPackageVersionOperation : AsyncOperationBase
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Web package version file content is empty !"; Error = $"Web package version file content is empty.";
} }
else else
{ {

View File

@@ -10,17 +10,22 @@ namespace YooAsset
{ {
private List<AsyncOperationBase> _childs; private List<AsyncOperationBase> _childs;
private Action<AsyncOperationBase> _callback; private Action<AsyncOperationBase> _callback;
private uint _priority = 0; private uint _priority;
/// <summary> /// <summary>
/// 等待异步执行完成 /// 等待异步执行完成
/// </summary> /// </summary>
internal bool IsWaitForAsyncComplete { private set; get; } = false; internal bool IsWaitForAsyncComplete { get; private set; }
/// <summary>
/// 标记脏(用于调度器检测并重排)
/// </summary>
internal bool IsDirty { get; set; }
/// <summary> /// <summary>
/// 是否已经完成 /// 是否已经完成
/// </summary> /// </summary>
internal bool IsFinish { private set; get; } = false; internal bool IsFinish { get; private set; }
/// <summary> /// <summary>
/// 异步系统是否繁忙 /// 异步系统是否繁忙
@@ -35,11 +40,6 @@ namespace YooAsset
} }
} }
/// <summary>
/// 标记脏(用于调度器检测并重排)
/// </summary>
internal bool IsDirty { set; get; } = false;
/// <summary> /// <summary>
/// 任务优先级 /// 任务优先级
/// </summary> /// </summary>
@@ -98,6 +98,7 @@ namespace YooAsset
{ {
try try
{ {
//注意:任务已完成,立即调用回调
value.Invoke(this); value.Invoke(this);
} }
catch (Exception ex) catch (Exception ex)
@@ -157,13 +158,13 @@ namespace YooAsset
#if UNITY_EDITOR || DEBUG #if UNITY_EDITOR || DEBUG
if (child == null) if (child == null)
throw new YooInternalException("The child node is null !"); throw new YooInternalException("The child node is null.");
if (ReferenceEquals(child, this)) if (ReferenceEquals(child, this))
throw new YooInternalException("The child node cannot be itself !"); throw new YooInternalException("The child node cannot be itself.");
if (_childs.Contains(child)) 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)) if (WouldCreateCycle(child))
@@ -183,10 +184,10 @@ namespace YooAsset
#if UNITY_EDITOR || DEBUG #if UNITY_EDITOR || DEBUG
if (child == null) if (child == null)
throw new YooInternalException("The child node is null !"); throw new YooInternalException("The child node is null.");
if (_childs.Contains(child) == false) 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 #endif
_childs.Remove(child); _childs.Remove(child);
@@ -275,7 +276,7 @@ namespace YooAsset
InternalAbort(); InternalAbort();
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "user abort"; Error = "user abort";
YooLogger.Warning($"Async operation {this.GetType().Name} has been aborted !"); YooLogger.Warning($"Async operation {this.GetType().Name} has been aborted.");
} }
//注意强制收尾确保Task能完成 //注意强制收尾确保Task能完成
@@ -295,21 +296,25 @@ namespace YooAsset
// 结束记录 // 结束记录
DebugEndRecording(); DebugEndRecording();
try if (_callback != null)
{ {
//TODO 单个回调异常会阻断后续订阅者 var invocationList = _callback.GetInvocationList();
_callback?.Invoke(this); foreach (var handler in invocationList)
} {
catch (Exception ex) try
{ {
YooLogger.Error($"Exception in completion callback: {ex}"); ((Action<AsyncOperationBase>)handler).Invoke(this);
} }
finally catch (Exception ex)
{ {
_callback = null; YooLogger.Error($"Exception in completion callback: {ex}");
if (_taskCompletionSource != null) }
_taskCompletionSource.TrySetResult(null); }
} }
_callback = null;
if (_taskCompletionSource != null)
_taskCompletionSource.TrySetResult(null);
} }
} }
@@ -327,7 +332,10 @@ namespace YooAsset
/// <summary> /// <summary>
/// 批量执行一定次数的更新逻辑 /// 批量执行一定次数的更新逻辑
/// </summary> /// </summary>
/// <param name="count">次</param> /// <param name="count">最大执行次数默认1000次</param>
/// <remarks>
/// 用于需要快速完成但又不想完全阻塞主线程的场景。
/// </remarks>
protected void RunBatchExecution(int count = 1000) protected void RunBatchExecution(int count = 1000)
{ {
if (IsDone) if (IsDone)
@@ -374,7 +382,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void WaitForAsyncComplete() public void WaitForAsyncComplete()
{ {
//TODO 防止异步操作被挂起陷入无限死循环! //注意:防止异步操作被挂起陷入无限死循环!
if (Status == EOperationStatus.None) if (Status == EOperationStatus.None)
{ {
StartOperation(); StartOperation();
@@ -390,7 +398,7 @@ namespace YooAsset
if (IsDone == false) if (IsDone == false)
{ {
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Operation {this.GetType().Name} failed to wait for async complete !"; Error = $"Operation {this.GetType().Name} failed to wait for async complete.";
YooLogger.Error(Error); YooLogger.Error(Error);
} }
@@ -403,12 +411,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 开始的时间 /// 开始的时间
/// </summary> /// </summary>
public string BeginTime { protected set; get; } public string BeginTime { get; protected set; }
/// <summary> /// <summary>
/// 处理耗时(单位:毫秒) /// 处理耗时(单位:毫秒)
/// </summary> /// </summary>
public long ProcessTime { protected set; get; } public long ProcessTime { get; protected set; }
// 加载耗时统计 // 加载耗时统计
private Stopwatch _watch = null; private Stopwatch _watch = null;
@@ -449,9 +457,14 @@ namespace YooAsset
double s = System.Math.Floor(spawnTime - m * 60 - h * 3600); double s = System.Math.Floor(spawnTime - m * 60 - h * 3600);
return h.ToString("00") + ":" + m.ToString("00") + ":" + s.ToString("00"); return h.ToString("00") + ":" + m.ToString("00") + ":" + s.ToString("00");
} }
/// <summary>
/// 检测添加子任务是否会形成循环依赖
/// 使用深度优先搜索DFS遍历子任务图
/// </summary>
private bool WouldCreateCycle(AsyncOperationBase child) private bool WouldCreateCycle(AsyncOperationBase child)
{ {
const int maxVisited = 4096; const int MaxCycleCheckDepth = 4096; // 循环检测最大深度
var stack = new Stack<AsyncOperationBase>(); var stack = new Stack<AsyncOperationBase>();
var visited = new HashSet<AsyncOperationBase>(); var visited = new HashSet<AsyncOperationBase>();
stack.Push(child); stack.Push(child);
@@ -462,18 +475,22 @@ namespace YooAsset
if (node == null) if (node == null)
continue; continue;
// 防止重复访问
if (visited.Add(node) == false) if (visited.Add(node) == false)
continue; continue;
if (visited.Count > maxVisited) // 防止无限循环(图过大)
throw new YooInternalException("Child operation graph is too large, cycle check aborted !"); if (visited.Count > MaxCycleCheckDepth)
throw new YooInternalException("Child operation graph is too large, cycle check aborted.");
// 检测循环:如果遍历到自己,说明形成循环
if (ReferenceEquals(node, this)) if (ReferenceEquals(node, this))
return true; return true;
if (node._childs == null) if (node._childs == null)
continue; continue;
// 将子节点加入栈
for (int i = 0; i < node._childs.Count; i++) for (int i = 0; i < node._childs.Count; i++)
{ {
stack.Push(node._childs[i]); stack.Push(node._childs[i]);

View File

@@ -10,12 +10,12 @@ namespace YooAsset
{ {
private readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(100); private readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(100);
private readonly List<AsyncOperationBase> _newList = new List<AsyncOperationBase>(100); private readonly List<AsyncOperationBase> _newList = new List<AsyncOperationBase>(100);
private uint _priority = 0; private uint _priority;
/// <summary> /// <summary>
/// 所属包裹名称 /// 所属包裹名称
/// </summary> /// </summary>
public string PackageName { private set; get; } public string PackageName { get; private set; }
/// <summary> /// <summary>
/// 调度器优先级(值越大越优先) /// 调度器优先级(值越大越优先)
@@ -36,12 +36,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 优先级是否已变更(需要重新排序) /// 优先级是否已变更(需要重新排序)
/// </summary> /// </summary>
public bool IsDirty { set; get; } = false; public bool IsDirty { get; set; }
/// <summary> /// <summary>
/// 创建顺序(用于同优先级稳定排序) /// 创建顺序(用于同优先级稳定排序)
/// </summary> /// </summary>
public int CreateIndex { private set; get; } public int CreateIndex { get; private set; }
public OperationScheduler(string packageName, int createIndex) public OperationScheduler(string packageName, int createIndex)
@@ -53,6 +53,9 @@ namespace YooAsset
/// <summary> /// <summary>
/// 开始处理异步操作 /// 开始处理异步操作
/// </summary> /// </summary>
/// <remarks>
/// 操作会先添加到临时队列在下一次Update时才会开始执行
/// </remarks>
public void StartOperation(AsyncOperationBase operation) public void StartOperation(AsyncOperationBase operation)
{ {
_newList.Add(operation); _newList.Add(operation);

View File

@@ -15,13 +15,13 @@ namespace YooAsset
} }
#endif #endif
// 全局调度器名称 public const string GlobalSchedulerName = "YOOASSET_GLOBAL_SCHEDULER"; // 全局调度器名称
public const string GLOBAL_SCHEDULER_NAME = "YOOASSET_GLOBAL_SCHEDULER"; private const long MinTimeSlice = 10; // 最小时间片(毫秒)
private static readonly Dictionary<string, OperationScheduler> _schedulerDic = new Dictionary<string, OperationScheduler>(100); private static readonly Dictionary<string, OperationScheduler> _schedulerDic = new Dictionary<string, OperationScheduler>(100);
private static readonly List<OperationScheduler> _schedulerList = new List<OperationScheduler>(100); private static readonly List<OperationScheduler> _schedulerList = new List<OperationScheduler>(100);
private static bool _isInitialize = false; private static bool _isInitialized;
private static int _createIndex = 0; private static int _createIndex;
// 计时器相关 // 计时器相关
private static Stopwatch _watch; private static Stopwatch _watch;
@@ -33,12 +33,16 @@ namespace YooAsset
/// </summary> /// </summary>
public static long MaxTimeSlice public static long MaxTimeSlice
{ {
get
{
return _maxTimeSlice;
}
set set
{ {
if (value < 10) if (value < MinTimeSlice)
{ {
_maxTimeSlice = 10; _maxTimeSlice = MinTimeSlice;
YooLogger.Warning($"MaxTimeSlice minimum value is 10 milliseconds."); YooLogger.Warning($"MaxTimeSlice minimum value is {MinTimeSlice} milliseconds.");
} }
else else
{ {
@@ -71,14 +75,17 @@ namespace YooAsset
/// </summary> /// </summary>
public static void Initialize() public static void Initialize()
{ {
if (_isInitialize == false) if (_isInitialized)
{ {
_isInitialize = true; YooLogger.Warning("Operation system is already initialized.");
_watch = Stopwatch.StartNew(); return;
// 创建全局调度器
CreatePackageScheduler(GLOBAL_SCHEDULER_NAME, uint.MaxValue);
} }
_isInitialized = true;
_watch = Stopwatch.StartNew();
// 创建全局调度器
CreatePackageScheduler(GlobalSchedulerName, uint.MaxValue);
} }
/// <summary> /// <summary>
@@ -86,7 +93,7 @@ namespace YooAsset
/// </summary> /// </summary>
public static void Update() public static void Update()
{ {
if (_isInitialize == false) if (_isInitialized == false)
return; return;
// 检测是否需要执行排序 // 检测是否需要执行排序
@@ -122,8 +129,7 @@ namespace YooAsset
/// </summary> /// </summary>
public static void DestroyAll() public static void DestroyAll()
{ {
_isInitialize = false; _isInitialized = false;
YooLogger.Log("Operation system destroy all !");
// 清空所有调度器 // 清空所有调度器
foreach (var scheduler in _schedulerList) foreach (var scheduler in _schedulerList)
@@ -136,7 +142,7 @@ namespace YooAsset
_watch = null; _watch = null;
_frameTime = 0; _frameTime = 0;
MaxTimeSlice = long.MaxValue; _maxTimeSlice = long.MaxValue;
} }
/// <summary> /// <summary>
@@ -144,7 +150,7 @@ namespace YooAsset
/// </summary> /// </summary>
public static OperationScheduler CreatePackageScheduler(string packageName, uint priority) public static OperationScheduler CreatePackageScheduler(string packageName, uint priority)
{ {
DebugCheckInitialize(packageName); DebugEnsureInitialized(packageName);
if (_schedulerDic.ContainsKey(packageName)) if (_schedulerDic.ContainsKey(packageName))
{ {
@@ -163,12 +169,12 @@ namespace YooAsset
/// </summary> /// </summary>
public static void DestroyPackageScheduler(string packageName) public static void DestroyPackageScheduler(string packageName)
{ {
DebugCheckInitialize(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)) if (_schedulerDic.TryGetValue(packageName, out var scheduler))
@@ -184,7 +190,7 @@ namespace YooAsset
/// </summary> /// </summary>
public static void ClearPackageOperation(string packageName) public static void ClearPackageOperation(string packageName)
{ {
DebugCheckInitialize(packageName); DebugEnsureInitialized(packageName);
var scheduler = GetScheduler(packageName); var scheduler = GetScheduler(packageName);
scheduler.ClearAll(); scheduler.ClearAll();
@@ -195,7 +201,7 @@ namespace YooAsset
/// </summary> /// </summary>
public static void StartOperation(string packageName, AsyncOperationBase operation) public static void StartOperation(string packageName, AsyncOperationBase operation)
{ {
DebugCheckInitialize(packageName); DebugEnsureInitialized(packageName);
var scheduler = GetScheduler(packageName); var scheduler = GetScheduler(packageName);
scheduler.StartOperation(operation); scheduler.StartOperation(operation);
@@ -206,7 +212,7 @@ namespace YooAsset
/// </summary> /// </summary>
public static void SetSchedulerPriority(string packageName, uint priority) public static void SetSchedulerPriority(string packageName, uint priority)
{ {
DebugCheckInitialize(packageName); DebugEnsureInitialized(packageName);
var scheduler = GetScheduler(packageName); var scheduler = GetScheduler(packageName);
scheduler.Priority = priority; scheduler.Priority = priority;
@@ -217,7 +223,7 @@ namespace YooAsset
/// </summary> /// </summary>
public static uint GetSchedulerPriority(string packageName) public static uint GetSchedulerPriority(string packageName)
{ {
DebugCheckInitialize(packageName); DebugEnsureInitialized(packageName);
var scheduler = GetScheduler(packageName); var scheduler = GetScheduler(packageName);
return scheduler.Priority; return scheduler.Priority;
@@ -240,7 +246,7 @@ namespace YooAsset
#region #region
internal static List<DebugOperationInfo> GetDebugOperationInfos(string packageName) internal static List<DebugOperationInfo> GetDebugOperationInfos(string packageName)
{ {
DebugCheckInitialize(packageName); DebugEnsureInitialized(packageName);
var scheduler = GetScheduler(packageName); var scheduler = GetScheduler(packageName);
return scheduler.GetDebugOperationInfos(); return scheduler.GetDebugOperationInfos();
@@ -249,13 +255,13 @@ namespace YooAsset
#region #region
[Conditional("DEBUG")] [Conditional("DEBUG")]
private static void DebugCheckInitialize(string packageName) private static void DebugEnsureInitialized(string packageName)
{ {
if (string.IsNullOrWhiteSpace(packageName)) if (string.IsNullOrWhiteSpace(packageName))
throw new YooInternalException("Package name is null or empty."); throw new YooInternalException("Package name is null or empty.");
if (_isInitialize == false) if (_isInitialized == false)
throw new YooInternalException($"{nameof(OperationSystem)} not initialized !"); throw new YooInternalException($"{nameof(OperationSystem)} not initialized.");
} }
#endregion #endregion
} }

View File

@@ -116,14 +116,14 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Instantiate game object is null !"; Error = $"Instantiate game object is null.";
} }
} }
else else
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Instantiate async results is null !"; Error = $"Instantiate async results is null.";
} }
} }
#endif #endif

View File

@@ -84,7 +84,7 @@ namespace YooAsset
if (_loadBundleOp == null) if (_loadBundleOp == null)
{ {
// 统计计数增加 // 统计计数增加
_resManager.BundleLoadingCounter++; _resManager.IncrementBundleLoadingCounter();
_loadBundleOp = LoadBundleInfo.CreateBundleLoader(); _loadBundleOp = LoadBundleInfo.CreateBundleLoader();
_loadBundleOp.StartOperation(); _loadBundleOp.StartOperation();
AddChildOperation(_loadBundleOp); AddChildOperation(_loadBundleOp);
@@ -105,7 +105,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"The bundle loader result is null ! {LoadBundleInfo.Bundle.BundleName}"; Error = $"The bundle loader result is null. Bundle: {LoadBundleInfo.Bundle.BundleName}";
} }
else else
{ {
@@ -122,7 +122,7 @@ namespace YooAsset
} }
// 统计计数减少 // 统计计数减少
_resManager.BundleLoadingCounter--; _resManager.DecrementBundleLoadingCounter();
} }
} }
internal override void InternalWaitForAsyncComplete() internal override void InternalWaitForAsyncComplete()
@@ -171,7 +171,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Bundle loader destroyed !"; Error = "Bundle loader destroyed.";
} }
} }
@@ -268,7 +268,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Abort bundle loader !"; Error = "Bundle loader aborted.";
} }
if (_steps == ESteps.LoadBundleFile) if (_steps == ESteps.LoadBundleFile)

View File

@@ -73,7 +73,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Scene is invalid !"; Error = "Scene is invalid.";
return; return;
} }
@@ -81,7 +81,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Scene is not loaded !"; Error = "Scene is not loaded.";
return; return;
} }
@@ -97,7 +97,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Unload scene failed, see the console logs !"; Error = "Unload scene failed, see the console logs.";
return; return;
} }
} }

View File

@@ -168,7 +168,7 @@ namespace YooAsset
BundleResultObject = _mainBundleLoader.Result; BundleResultObject = _mainBundleLoader.Result;
if (BundleResultObject == null) if (BundleResultObject == null)
{ {
string error = $"Loaded bundle result is null !"; string error = $"Loaded bundle result is null.";
InvokeCompletion(error, EOperationStatus.Failed); InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }

View File

@@ -7,18 +7,24 @@ using UnityEngine.SceneManagement;
namespace YooAsset namespace YooAsset
{ {
/// <summary>
/// 资源管理器
/// 注意此类不是线程安全的所有方法必须在Unity主线程调用
/// </summary>
internal class ResourceManager internal class ResourceManager
{ {
internal readonly Dictionary<string, ProviderOperation> ProviderDic = new Dictionary<string, ProviderOperation>(5000); internal readonly Dictionary<string, ProviderOperation> ProviderDic = new Dictionary<string, ProviderOperation>(5000);
internal readonly Dictionary<string, LoadBundleOperation> LoaderDic = new Dictionary<string, LoadBundleOperation>(5000); internal readonly Dictionary<string, LoadBundleOperation> LoaderDic = new Dictionary<string, LoadBundleOperation>(5000);
internal readonly List<SceneHandle> SceneHandles = new List<SceneHandle>(100); internal readonly List<SceneHandle> SceneHandles = new List<SceneHandle>(100);
private readonly List<SceneHandle> _tempSceneHandles = new List<SceneHandle>(100);
private FileSystemHost _fileSystemHost; private FileSystemHost _fileSystemHost;
private long _sceneCreateIndex = 0;
private int _bundleLoadingMaxConcurrency; private int _bundleLoadingMaxConcurrency;
private int _bundleLoadingCounter;
private long _sceneCreateIndex;
// 开发者配置选项 // 开发者配置选项
public bool AutoUnloadBundleWhenUnused { private set; get; } public bool AutoUnloadBundleWhenUnused { get; private set; }
public bool WebGLForceSyncLoadAsset { private set; get; } public bool WebGLForceSyncLoadAsset { get; private set; }
/// <summary> /// <summary>
/// 所属包裹 /// 所属包裹
@@ -30,12 +36,6 @@ namespace YooAsset
/// </summary> /// </summary>
public bool LockLoadOperation = false; public bool LockLoadOperation = false;
/// <summary>
/// 统计正在加载的Bundle文件数量
/// </summary>
public int BundleLoadingCounter = 0;
public ResourceManager(string packageName) public ResourceManager(string packageName)
{ {
PackageName = packageName; PackageName = packageName;
@@ -68,18 +68,21 @@ namespace YooAsset
{ {
if (assetInfo == null) if (assetInfo == null)
{ {
YooLogger.Error($"{nameof(AssetInfo)} is null !"); YooLogger.Error($"{nameof(AssetInfo)} is null.");
return; return;
} }
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Error($"Failed to unload asset ! {assetInfo.Error}"); YooLogger.Error($"Failed to unload asset. Error: {assetInfo.Error}");
return; return;
} }
// 多次循环尝试卸载,以处理复杂的依赖链
// 例如A依赖BB依赖C需要多次循环才能完全卸载
while (loopCount > 0) while (loopCount > 0)
{ {
loopCount--; loopCount--;
bool hasUnloaded = false;
// 卸载主资源包加载器 // 卸载主资源包加载器
string mainBundleName = _fileSystemHost.GetMainBundleName(assetInfo.Asset.BundleID); string mainBundleName = _fileSystemHost.GetMainBundleName(assetInfo.Asset.BundleID);
@@ -91,6 +94,7 @@ namespace YooAsset
{ {
mainLoader.DestroyLoader(); mainLoader.DestroyLoader();
LoaderDic.Remove(mainBundleName); LoaderDic.Remove(mainBundleName);
hasUnloaded = true;
} }
} }
@@ -105,9 +109,14 @@ namespace YooAsset
{ {
dependLoader.DestroyLoader(); dependLoader.DestroyLoader();
LoaderDic.Remove(dependBundleName); LoaderDic.Remove(dependBundleName);
hasUnloaded = true;
} }
} }
} }
// 如果本次循环没有卸载任何资源,提前退出
if (hasUnloaded == false)
break;
} }
} }
@@ -120,7 +129,7 @@ namespace YooAsset
{ {
if (LockLoadOperation) if (LockLoadOperation)
{ {
string error = $"The load operation locked !"; string error = $"The load operation locked.";
YooLogger.Error(error); YooLogger.Error(error);
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompletedWithError(error); completedProvider.SetCompletedWithError(error);
@@ -129,7 +138,7 @@ namespace YooAsset
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Error($"Failed to load scene ! {assetInfo.Error}"); YooLogger.Error($"Failed to load scene. Error: {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompletedWithError(assetInfo.Error); completedProvider.SetCompletedWithError(assetInfo.Error);
return completedProvider.CreateHandle<SceneHandle>(); return completedProvider.CreateHandle<SceneHandle>();
@@ -159,7 +168,7 @@ namespace YooAsset
{ {
if (LockLoadOperation) if (LockLoadOperation)
{ {
string error = $"The load operation locked !"; string error = $"The load operation locked.";
YooLogger.Error(error); YooLogger.Error(error);
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompletedWithError(error); completedProvider.SetCompletedWithError(error);
@@ -168,7 +177,7 @@ namespace YooAsset
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Error($"Failed to load asset ! {assetInfo.Error}"); YooLogger.Error($"Failed to load asset. Error: {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompletedWithError(assetInfo.Error); completedProvider.SetCompletedWithError(assetInfo.Error);
return completedProvider.CreateHandle<AssetHandle>(); return completedProvider.CreateHandle<AssetHandle>();
@@ -195,7 +204,7 @@ namespace YooAsset
{ {
if (LockLoadOperation) if (LockLoadOperation)
{ {
string error = $"The load operation locked !"; string error = $"The load operation locked.";
YooLogger.Error(error); YooLogger.Error(error);
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompletedWithError(error); completedProvider.SetCompletedWithError(error);
@@ -204,7 +213,7 @@ namespace YooAsset
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Error($"Failed to load sub assets ! {assetInfo.Error}"); YooLogger.Error($"Failed to load sub assets. Error: {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompletedWithError(assetInfo.Error); completedProvider.SetCompletedWithError(assetInfo.Error);
return completedProvider.CreateHandle<SubAssetsHandle>(); return completedProvider.CreateHandle<SubAssetsHandle>();
@@ -231,7 +240,7 @@ namespace YooAsset
{ {
if (LockLoadOperation) if (LockLoadOperation)
{ {
string error = $"The load operation locked !"; string error = $"The load operation locked.";
YooLogger.Error(error); YooLogger.Error(error);
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompletedWithError(error); completedProvider.SetCompletedWithError(error);
@@ -240,7 +249,7 @@ namespace YooAsset
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Error($"Failed to load all assets ! {assetInfo.Error}"); YooLogger.Error($"Failed to load all assets. Error: {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompletedWithError(assetInfo.Error); completedProvider.SetCompletedWithError(assetInfo.Error);
return completedProvider.CreateHandle<AllAssetsHandle>(); return completedProvider.CreateHandle<AllAssetsHandle>();
@@ -267,7 +276,7 @@ namespace YooAsset
{ {
if (LockLoadOperation) if (LockLoadOperation)
{ {
string error = $"The load operation locked !"; string error = $"The load operation locked.";
YooLogger.Error(error); YooLogger.Error(error);
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompletedWithError(error); completedProvider.SetCompletedWithError(error);
@@ -276,7 +285,7 @@ namespace YooAsset
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Error($"Failed to load raw file ! {assetInfo.Error}"); YooLogger.Error($"Failed to load raw file. Error: {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompletedWithError(assetInfo.Error); completedProvider.SetCompletedWithError(assetInfo.Error);
return completedProvider.CreateHandle<RawFileHandle>(); return completedProvider.CreateHandle<RawFileHandle>();
@@ -339,9 +348,26 @@ namespace YooAsset
{ {
return LoaderDic.Count > 0; return LoaderDic.Count > 0;
} }
internal void IncrementBundleLoadingCounter()
{
_bundleLoadingCounter++;
}
internal void DecrementBundleLoadingCounter()
{
_bundleLoadingCounter--;
if (_bundleLoadingCounter < 0)
{
YooLogger.Error("BundleLoadingCounter is negative.");
_bundleLoadingCounter = 0;
}
}
internal int GetBundleLoadingCounter()
{
return _bundleLoadingCounter;
}
internal bool BundleLoadingIsBusy() internal bool BundleLoadingIsBusy()
{ {
return BundleLoadingCounter >= _bundleLoadingMaxConcurrency; return _bundleLoadingCounter >= _bundleLoadingMaxConcurrency;
} }
private LoadBundleOperation CreateBundleFileLoaderInternal(BundleInfo bundleInfo) private LoadBundleOperation CreateBundleFileLoaderInternal(BundleInfo bundleInfo)
@@ -373,7 +399,7 @@ namespace YooAsset
} }
private void OnSceneUnloaded(Scene scene) private void OnSceneUnloaded(Scene scene)
{ {
List<SceneHandle> removeList = new List<SceneHandle>(); _tempSceneHandles.Clear(); //复用列表
foreach (var sceneHandle in SceneHandles) foreach (var sceneHandle in SceneHandles)
{ {
if (sceneHandle.IsValid) if (sceneHandle.IsValid)
@@ -381,11 +407,11 @@ namespace YooAsset
if (sceneHandle.SceneObject == scene) if (sceneHandle.SceneObject == scene)
{ {
sceneHandle.Release(); sceneHandle.Release();
removeList.Add(sceneHandle); _tempSceneHandles.Add(sceneHandle);
} }
} }
} }
foreach (var sceneHandle in removeList) foreach (var sceneHandle in _tempSceneHandles)
{ {
SceneHandles.Remove(sceneHandle); SceneHandles.Remove(sceneHandle);
} }

View File

@@ -19,17 +19,17 @@ namespace YooAsset
/// <summary> /// <summary>
/// 所属包裹 /// 所属包裹
/// </summary> /// </summary>
public string PackageName { private set; get; } public string PackageName { get; private set; }
/// <summary> /// <summary>
/// 资源类型 /// 资源类型
/// </summary> /// </summary>
public System.Type AssetType { private set; get; } public System.Type AssetType { get; private set; }
/// <summary> /// <summary>
/// 错误信息 /// 错误信息
/// </summary> /// </summary>
public string Error { private set; get; } public string Error { get; private set; }
/// <summary> /// <summary>
/// 加载方法 /// 加载方法

View File

@@ -12,7 +12,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 当前激活的清单 /// 当前激活的清单
/// </summary> /// </summary>
public PackageManifest ActiveManifest { private set; get; } public PackageManifest ActiveManifest { get; private set; }
public FileSystemHost(string packageName) public FileSystemHost(string packageName)
@@ -75,8 +75,10 @@ namespace YooAsset
/// <summary> /// <summary>
/// 获取主文件系统 /// 获取主文件系统
/// 说明:文件系统列表里,最后一个属于主文件系统
/// </summary> /// </summary>
/// <remarks>
/// 文件系统列表里,最后一个属于主文件系统
/// </remarks>
public IFileSystem GetMainFileSystem() public IFileSystem GetMainFileSystem()
{ {
int count = FileSystems.Count; int count = FileSystems.Count;
@@ -112,7 +114,7 @@ namespace YooAsset
var fileSystem = GetBelongFileSystem(packageBundle); var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem != null) if (fileSystem != null)
{ {
BundleInfo bundleInfo = new BundleInfo(fileSystem, packageBundle); var bundleInfo = new BundleInfo(fileSystem, packageBundle);
return bundleInfo; return bundleInfo;
} }
@@ -123,7 +125,7 @@ namespace YooAsset
if (assetInfo == null || assetInfo.IsInvalid) if (assetInfo == null || assetInfo.IsInvalid)
throw new YooInternalException(); throw new YooInternalException();
// 注意:如果清单里未找到资源包会抛出异常 // 注意:如果清单里未找到资源包会抛出异常
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset); var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset);
return CreateBundleInfo(packageBundle); return CreateBundleInfo(packageBundle);
} }
@@ -161,6 +163,8 @@ namespace YooAsset
#endregion #endregion
#region #region
private const int DefaultBundleInfoCapacity = 1000;
public bool IsNeedDownloadFromRemoteInternal(AssetInfo assetInfo) public bool IsNeedDownloadFromRemoteInternal(AssetInfo assetInfo)
{ {
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
@@ -183,6 +187,20 @@ namespace YooAsset
return false; return false;
} }
private delegate bool NeedPredicate(IFileSystem fileSystem, PackageBundle bundle);
private bool NeedDownload(IFileSystem fileSystem, PackageBundle bundle)
{
return fileSystem.NeedDownload(bundle);
}
private bool NeedUnpack(IFileSystem fileSystem, PackageBundle bundle)
{
return fileSystem.NeedUnpack(bundle);
}
private bool NeedImport(IFileSystem fileSystem, PackageBundle bundle)
{
return fileSystem.NeedImport(bundle);
}
public ResourceDownloaderOperation CreateResourceDownloader(ResourceDownloaderOptions options) public ResourceDownloaderOperation CreateResourceDownloader(ResourceDownloaderOptions options)
{ {
return CreateResourceDownloader(ActiveManifest, options); return CreateResourceDownloader(ActiveManifest, options);
@@ -191,9 +209,9 @@ namespace YooAsset
{ {
List<BundleInfo> downloadList; List<BundleInfo> downloadList;
if (options.Tags == null) if (options.Tags == null)
downloadList = GetDownloadListByAll(manifest); downloadList = GetBundleInfoListByAll(manifest, NeedDownload);
else else
downloadList = GetDownloadListByTags(manifest, options.Tags); downloadList = GetBundleInfoListByTags(manifest, options.Tags, NeedDownload);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain); var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain);
return operation; return operation;
@@ -207,9 +225,9 @@ namespace YooAsset
{ {
List<BundleInfo> downloadList; List<BundleInfo> downloadList;
if (options.AssetInfos == null) if (options.AssetInfos == null)
downloadList = GetDownloadListByAll(manifest); downloadList = GetBundleInfoListByAll(manifest, NeedDownload);
else else
downloadList = GetDownloadListByAssetInfos(manifest, options.AssetInfos, options.DownloadBundleDependencies); downloadList = GetBundleInfoListByAssetInfos(manifest, options.AssetInfos, options.DownloadBundleDependencies, NeedDownload);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain); var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain);
return operation; return operation;
@@ -221,13 +239,13 @@ namespace YooAsset
} }
public ResourceUnpackerOperation CreateResourceUnpacker(PackageManifest manifest, ResourceUnpackerOptions options) public ResourceUnpackerOperation CreateResourceUnpacker(PackageManifest manifest, ResourceUnpackerOptions options)
{ {
List<BundleInfo> unpcakList; List<BundleInfo> unpackList;
if (options.Tags == null) if (options.Tags == null)
unpcakList = GetUnpackListByAll(manifest); unpackList = GetBundleInfoListByAll(manifest, NeedUnpack);
else else
unpcakList = GetUnpackListByTags(manifest, options.Tags); unpackList = GetBundleInfoListByTags(manifest, options.Tags, NeedUnpack);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, options.MaximumConcurrency, options.FailedTryAgain); var operation = new ResourceUnpackerOperation(PackageName, unpackList, options.MaximumConcurrency, options.FailedTryAgain);
return operation; return operation;
} }
@@ -237,24 +255,24 @@ namespace YooAsset
} }
public ResourceImporterOperation CreateResourceImporter(PackageManifest manifest, BundleImporterOptions options) public ResourceImporterOperation CreateResourceImporter(PackageManifest manifest, BundleImporterOptions options)
{ {
List<BundleInfo> importerList = GetImporterListByBundleInfos(manifest, options.BundleInfos); List<BundleInfo> importerList = GetBundleInfoListByBundleInfos(manifest, options.BundleInfos, NeedImport);
var operation = new ResourceImporterOperation(PackageName, importerList, options.MaximumConcurrency, options.FailedTryAgain); var operation = new ResourceImporterOperation(PackageName, importerList, options.MaximumConcurrency, options.FailedTryAgain);
return operation; return operation;
} }
private List<BundleInfo> GetDownloadListByAll(PackageManifest manifest) private List<BundleInfo> GetBundleInfoListByAll(PackageManifest manifest, Func<IFileSystem, PackageBundle, bool> predicate)
{ {
if (manifest == null) if (manifest == null)
return new List<BundleInfo>(); return new List<BundleInfo>();
List<BundleInfo> result = new List<BundleInfo>(1000); List<BundleInfo> result = new List<BundleInfo>(DefaultBundleInfoCapacity);
foreach (var packageBundle in manifest.BundleList) foreach (var packageBundle in manifest.BundleList)
{ {
var fileSystem = GetBelongFileSystem(packageBundle); var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem == null) if (fileSystem == null)
continue; continue;
if (fileSystem.NeedDownload(packageBundle)) if (predicate(fileSystem, packageBundle))
{ {
var bundleInfo = new BundleInfo(fileSystem, packageBundle); var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo); result.Add(bundleInfo);
@@ -262,21 +280,21 @@ namespace YooAsset
} }
return result; return result;
} }
private List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags) private List<BundleInfo> GetBundleInfoListByTags(PackageManifest manifest, string[] tags, Func<IFileSystem, PackageBundle, bool> predicate)
{ {
if (manifest == null) if (manifest == null)
return new List<BundleInfo>(); return new List<BundleInfo>();
List<BundleInfo> result = new List<BundleInfo>(1000); List<BundleInfo> result = new List<BundleInfo>(DefaultBundleInfoCapacity);
foreach (var packageBundle in manifest.BundleList) foreach (var packageBundle in manifest.BundleList)
{ {
var fileSystem = GetBelongFileSystem(packageBundle); var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem == null) if (fileSystem == null)
continue; continue;
if (fileSystem.NeedDownload(packageBundle)) if (predicate(fileSystem, packageBundle))
{ {
// 如果未带任何标记,则统一下载 // 注意:如果未带任何标记,则统一处理
if (packageBundle.HasAnyTags() == false) if (packageBundle.HasAnyTags() == false)
{ {
var bundleInfo = new BundleInfo(fileSystem, packageBundle); var bundleInfo = new BundleInfo(fileSystem, packageBundle);
@@ -284,7 +302,6 @@ namespace YooAsset
} }
else else
{ {
// 查询DLC资源
if (packageBundle.HasTag(tags)) if (packageBundle.HasTag(tags))
{ {
var bundleInfo = new BundleInfo(fileSystem, packageBundle); var bundleInfo = new BundleInfo(fileSystem, packageBundle);
@@ -295,7 +312,7 @@ namespace YooAsset
} }
return result; return result;
} }
private List<BundleInfo> GetDownloadListByAssetInfos(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDownload) private List<BundleInfo> GetBundleInfoListByAssetInfos(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDepend, Func<IFileSystem, PackageBundle, bool> predicate)
{ {
if (manifest == null) if (manifest == null)
return new List<BundleInfo>(); return new List<BundleInfo>();
@@ -331,7 +348,7 @@ namespace YooAsset
} }
// 下载主资源包内所有资源对象依赖的资源包 // 下载主资源包内所有资源对象依赖的资源包
if (recursiveDownload) if (recursiveDepend)
{ {
foreach (var otherMainAsset in mainBundle.IncludeMainAssets) foreach (var otherMainAsset in mainBundle.IncludeMainAssets)
{ {
@@ -355,14 +372,14 @@ namespace YooAsset
} }
} }
List<BundleInfo> result = new List<BundleInfo>(1000); List<BundleInfo> result = new List<BundleInfo>(DefaultBundleInfoCapacity);
foreach (var packageBundle in checkList) foreach (var packageBundle in checkList)
{ {
var fileSystem = GetBelongFileSystem(packageBundle); var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem == null) if (fileSystem == null)
continue; continue;
if (fileSystem.NeedDownload(packageBundle)) if (predicate(fileSystem, packageBundle))
{ {
var bundleInfo = new BundleInfo(fileSystem, packageBundle); var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo); result.Add(bundleInfo);
@@ -370,62 +387,19 @@ namespace YooAsset
} }
return result; return result;
} }
private List<BundleInfo> GetUnpackListByAll(PackageManifest manifest) private List<BundleInfo> GetBundleInfoListByBundleInfos(PackageManifest manifest, ImportBundleInfo[] fileInfos, Func<IFileSystem, PackageBundle, bool> predicate)
{ {
if (manifest == null) if (manifest == null)
return new List<BundleInfo>(); return new List<BundleInfo>();
List<BundleInfo> result = new List<BundleInfo>(1000); List<BundleInfo> result = new List<BundleInfo>(DefaultBundleInfoCapacity);
foreach (var packageBundle in manifest.BundleList)
{
var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem == null)
continue;
if (fileSystem.NeedUnpack(packageBundle))
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
}
return result;
}
private List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags)
{
if (manifest == null)
return new List<BundleInfo>();
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in manifest.BundleList)
{
var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem == null)
continue;
if (fileSystem.NeedUnpack(packageBundle))
{
if (packageBundle.HasTag(tags))
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
}
}
return result;
}
private List<BundleInfo> GetImporterListByBundleInfos(PackageManifest manifest, ImportBundleInfo[] fileInfos)
{
if (manifest == null)
return new List<BundleInfo>();
List<BundleInfo> result = new List<BundleInfo>();
foreach (var fileInfo in fileInfos) foreach (var fileInfo in fileInfos)
{ {
string filePath = fileInfo.FilePath; string filePath = fileInfo.FilePath;
if (string.IsNullOrEmpty(filePath)) if (string.IsNullOrEmpty(filePath))
continue; continue;
PackageBundle packageBundle = null; PackageBundle packageBundle;
if (string.IsNullOrEmpty(fileInfo.BundleName) == false) if (string.IsNullOrEmpty(fileInfo.BundleName) == false)
{ {
if (manifest.TryGetPackageBundleByBundleName(fileInfo.BundleName, out packageBundle) == false) if (manifest.TryGetPackageBundleByBundleName(fileInfo.BundleName, out packageBundle) == false)
@@ -458,7 +432,7 @@ namespace YooAsset
if (fileSystem == null) if (fileSystem == null)
continue; continue;
if (fileSystem.NeedImport(packageBundle)) if (predicate(fileSystem, packageBundle))
{ {
var bundleInfo = new BundleInfo(fileSystem, packageBundle, filePath); var bundleInfo = new BundleInfo(fileSystem, packageBundle, filePath);
result.Add(bundleInfo); result.Add(bundleInfo);

View File

@@ -36,27 +36,27 @@ namespace YooAsset
if (_steps == ESteps.Prepare) if (_steps == ESteps.Prepare)
{ {
var fileSytems = _host.FileSystems; var fileSystems = _host.FileSystems;
if (fileSytems == null || fileSytems.Count == 0) if (fileSystems == null || fileSystems.Count == 0)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "The file system is empty !"; Error = "The file system is empty.";
return; return;
} }
foreach (var fileSystem in fileSytems) foreach (var fileSystem in fileSystems)
{ {
if (fileSystem == null) if (fileSystem == null)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "An empty object exists in the list!"; Error = "An empty object exists in the list.";
return; return;
} }
} }
_cloneList = fileSytems.ToList(); _cloneList = fileSystems.ToList();
_steps = ESteps.ClearCacheFiles; _steps = ESteps.ClearCacheFiles;
} }

View File

@@ -6,17 +6,17 @@ namespace YooAsset
/// <summary> /// <summary>
/// 清理模式 /// 清理模式
/// </summary> /// </summary>
public string ClearMode { set; get; } public string ClearMode { get; set; }
/// <summary> /// <summary>
/// 附加参数 /// 附加参数
/// </summary> /// </summary>
public object ClearParam { set; get; } public object ClearParam { get; set; }
/// <summary> /// <summary>
/// 资源清单 /// 资源清单
/// </summary> /// </summary>
internal PackageManifest Manifest { set; get; } internal PackageManifest Manifest { get; set; }
public ClearCacheFilesOptions(EFileClearMode clearMode) public ClearCacheFilesOptions(EFileClearMode clearMode)
{ {

View File

@@ -43,7 +43,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "The Package is initializing ! Please try to destroy the package again later."; Error = "The Package is initializing. Please try to destroy the package again later.";
} }
else if (_resourcePackage.InitializeStatus == EOperationStatus.Failed) else if (_resourcePackage.InitializeStatus == EOperationStatus.Failed)
{ {

View File

@@ -35,12 +35,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 统计的下载文件总数量 /// 统计的下载文件总数量
/// </summary> /// </summary>
public int TotalDownloadCount { private set; get; } public int TotalDownloadCount { get; private set; }
/// <summary> /// <summary>
/// 统计的下载文件的总大小 /// 统计的下载文件的总大小
/// </summary> /// </summary>
public long TotalDownloadBytes { private set; get; } public long TotalDownloadBytes { get; private set; }
/// <summary> /// <summary>
/// 当前已经完成的下载总数量 /// 当前已经完成的下载总数量
@@ -61,37 +61,37 @@ namespace YooAsset
/// <summary> /// <summary>
/// 下载完成事件委托(无论成功或失败) /// 下载完成事件委托(无论成功或失败)
/// </summary> /// </summary>
public DownloadFinishedEventHandler DownloadFinishedHandler { set; get; } public DownloadFinishedEventHandler DownloadFinishedHandler { get; set; }
/// <summary> /// <summary>
/// 下载进度更新事件委托 /// 下载进度更新事件委托
/// </summary> /// </summary>
public DownloadProgressChangedEventHandler DownloadProgressChangedHandler { set; get; } public DownloadProgressChangedEventHandler DownloadProgressChangedHandler { get; set; }
/// <summary> /// <summary>
/// 下载错误事件委托 /// 下载错误事件委托
/// </summary> /// </summary>
public DownloadErrorEventHandler DownloadErrorHandler { set; get; } public DownloadErrorEventHandler DownloadErrorHandler { get; set; }
/// <summary> /// <summary>
/// 开始下载单个文件事件委托 /// 开始下载单个文件事件委托
/// </summary> /// </summary>
public DownloadFileStartedEventHandler DownloadFileStartedHandler { set; get; } public DownloadFileStartedEventHandler DownloadFileStartedHandler { get; set; }
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int maximumConcurrency, int failedTryAgain) internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int maximumConcurrency, int failedTryAgain)
{ {
_packageName = packageName; _packageName = packageName;
_bundleInfoList = downloadList; _bundleInfoList = downloadList;
_maximumConcurrency = UnityEngine.Mathf.Clamp(maximumConcurrency, 1, MAX_LOADER_COUNT); ; _maximumConcurrency = UnityEngine.Mathf.Clamp(maximumConcurrency, 1, MAX_LOADER_COUNT);
_failedTryAgain = failedTryAgain; _failedTryAgain = failedTryAgain;
// 统计下载信息 // 统计下载信息
CalculatDownloaderInfo(); CalculateDownloaderInfo();
} }
internal override void InternalStart() internal override void InternalStart()
{ {
YooLogger.Log($"Begine to download {TotalDownloadCount} files and {TotalDownloadBytes} bytes"); YooLogger.Log($"Begin to download {TotalDownloadCount} files and {TotalDownloadBytes} bytes");
_steps = ESteps.Check; _steps = ESteps.Check;
} }
internal override void InternalUpdate() internal override void InternalUpdate()
@@ -262,7 +262,7 @@ namespace YooAsset
} }
} }
} }
private void CalculatDownloaderInfo() private void CalculateDownloaderInfo()
{ {
if (_bundleInfoList != null) if (_bundleInfoList != null)
{ {
@@ -288,23 +288,23 @@ namespace YooAsset
{ {
if (_packageName != downloader._packageName) if (_packageName != downloader._packageName)
{ {
YooLogger.Error("The downloaders have different resource packages !"); YooLogger.Error("The downloaders have different resource packages.");
return; return;
} }
if (Status != EOperationStatus.None) if (Status != EOperationStatus.None)
{ {
YooLogger.Error("The downloader is running, can not combine with other downloader !"); YooLogger.Error("The downloader is running, can not combine with other downloader.");
return; return;
} }
HashSet<string> temper = new HashSet<string>(); HashSet<string> combineGuidSet = new HashSet<string>();
foreach (var bundleInfo in _bundleInfoList) foreach (var bundleInfo in _bundleInfoList)
{ {
string combineGUID = bundleInfo.GetDownloadCombineGUID(); string combineGUID = bundleInfo.GetDownloadCombineGUID();
if (temper.Contains(combineGUID) == false) if (combineGuidSet.Contains(combineGUID) == false)
{ {
temper.Add(combineGUID); combineGuidSet.Add(combineGUID);
} }
} }
@@ -312,14 +312,14 @@ namespace YooAsset
foreach (var bundleInfo in downloader._bundleInfoList) foreach (var bundleInfo in downloader._bundleInfoList)
{ {
string combineGUID = bundleInfo.GetDownloadCombineGUID(); string combineGUID = bundleInfo.GetDownloadCombineGUID();
if (temper.Contains(combineGUID) == false) if (combineGuidSet.Contains(combineGUID) == false)
{ {
_bundleInfoList.Add(bundleInfo); _bundleInfoList.Add(bundleInfo);
} }
} }
// 重新统计下载信息 // 重新统计下载信息
CalculatDownloaderInfo(); CalculateDownloaderInfo();
} }
/// <summary> /// <summary>

View File

@@ -9,23 +9,23 @@ namespace YooAsset
/// <summary> /// <summary>
/// 最大并发数量 /// 最大并发数量
/// </summary> /// </summary>
public int MaximumConcurrency { set; get; } public int MaximumConcurrency { get; set; }
/// <summary> /// <summary>
/// 失败后的重试次数 /// 失败后的重试次数
/// </summary> /// </summary>
public int FailedTryAgain { set; get; } public int FailedTryAgain { get; set; }
/// <summary> /// <summary>
/// 下载资源对象所属资源包内所有资源对象依赖的资源包 /// 下载资源对象所属资源包内所有资源对象依赖的资源包
/// </summary> /// </summary>
public bool DownloadBundleDependencies { set; get; } public bool DownloadBundleDependencies { get; set; }
/// <summary> /// <summary>
/// 资源信息列表 /// 资源信息列表
/// 说明如果列表为NULL则下载所有资产 /// 说明如果列表为NULL则下载所有资产
/// </summary> /// </summary>
public AssetInfo[] AssetInfos { set; get; } public AssetInfo[] AssetInfos { get; set; }
public BundleDownloaderOptions(AssetInfo assetInfo, bool downloadDependencies, int maximumConcurrency, int failedTryAgain) public BundleDownloaderOptions(AssetInfo assetInfo, bool downloadDependencies, int maximumConcurrency, int failedTryAgain)
{ {
@@ -51,18 +51,18 @@ namespace YooAsset
/// <summary> /// <summary>
/// 最大并发数量 /// 最大并发数量
/// </summary> /// </summary>
public int MaximumConcurrency { set; get; } public int MaximumConcurrency { get; set; }
/// <summary> /// <summary>
/// 失败后的重试次数 /// 失败后的重试次数
/// </summary> /// </summary>
public int FailedTryAgain { set; get; } public int FailedTryAgain { get; set; }
/// <summary> /// <summary>
/// 资源标签列表 /// 资源标签列表
/// 说明如果列表为NULL则下载所有资产 /// 说明如果列表为NULL则下载所有资产
/// </summary> /// </summary>
public string[] Tags { set; get; } public string[] Tags { get; set; }
public ResourceDownloaderOptions(int maximumConcurrency, int failedTryAgain) public ResourceDownloaderOptions(int maximumConcurrency, int failedTryAgain)
{ {
@@ -92,18 +92,18 @@ namespace YooAsset
/// <summary> /// <summary>
/// 最大并发数量 /// 最大并发数量
/// </summary> /// </summary>
public int MaximumConcurrency { set; get; } public int MaximumConcurrency { get; set; }
/// <summary> /// <summary>
/// 失败后的重试次数 /// 失败后的重试次数
/// </summary> /// </summary>
public int FailedTryAgain { set; get; } public int FailedTryAgain { get; set; }
/// <summary> /// <summary>
/// 资源标签列表 /// 资源标签列表
/// 说明如果列表为NULL则解压所有资产 /// 说明如果列表为NULL则解压所有资产
/// </summary> /// </summary>
public string[] Tags { set; get; } public string[] Tags { get; set; }
public ResourceUnpackerOptions(int maximumConcurrency, int failedTryAgain) public ResourceUnpackerOptions(int maximumConcurrency, int failedTryAgain)
{ {
@@ -133,17 +133,17 @@ namespace YooAsset
/// <summary> /// <summary>
/// 最大并发数量 /// 最大并发数量
/// </summary> /// </summary>
public int MaximumConcurrency { set; get; } public int MaximumConcurrency { get; set; }
/// <summary> /// <summary>
/// 失败后的重试次数 /// 失败后的重试次数
/// </summary> /// </summary>
public int FailedTryAgain { set; get; } public int FailedTryAgain { get; set; }
/// <summary> /// <summary>
/// 资源包信息列表 /// 资源包信息列表
/// </summary> /// </summary>
public ImportBundleInfo[] BundleInfos { set; get; } public ImportBundleInfo[] BundleInfos { get; set; }
public BundleImporterOptions(ImportBundleInfo[] bundleInfos, int maximumConcurrency, int failedTryAgain) public BundleImporterOptions(ImportBundleInfo[] bundleInfos, int maximumConcurrency, int failedTryAgain)
{ {

View File

@@ -51,7 +51,6 @@ namespace YooAsset
else else
throw new NotImplementedException($"{_options.GetType().Name}"); throw new NotImplementedException($"{_options.GetType().Name}");
_package._playMode = _playMode;
_steps = ESteps.CheckOptions; _steps = ESteps.CheckOptions;
} }
@@ -90,7 +89,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"{_playMode} can not support WebGL plateform !"; Error = $"{_playMode} can not support WebGL plateform.";
YooLogger.Error(Error); YooLogger.Error(Error);
return; return;
} }
@@ -104,7 +103,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"{nameof(EPlayMode.WebPlayMode)} only support WebGL plateform !"; Error = $"{nameof(EPlayMode.WebPlayMode)} only support WebGL plateform.";
YooLogger.Error(Error); YooLogger.Error(Error);
return; return;
} }
@@ -122,8 +121,7 @@ namespace YooAsset
resourceManager.Initialize(_options, fileSystemHost); resourceManager.Initialize(_options, fileSystemHost);
_fileSystemHost = fileSystemHost; _fileSystemHost = fileSystemHost;
_package._fileSystemHost = fileSystemHost; _package.InternalInitialize(resourceManager, fileSystemHost);
_package._resourceManager = resourceManager;
_steps = ESteps.InitFileSystem; _steps = ESteps.InitFileSystem;
} }

View File

@@ -31,7 +31,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 解析的清单实例 /// 解析的清单实例
/// </summary> /// </summary>
public PackageManifest Manifest { private set; get; } public PackageManifest Manifest { get; private set; }
public DeserializeManifestOperation(IManifestRestoreServices services, byte[] binaryData) public DeserializeManifestOperation(IManifestRestoreServices services, byte[] binaryData)
{ {
@@ -68,7 +68,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Buffer is invalid !"; Error = "Buffer is invalid.";
return; return;
} }
@@ -78,7 +78,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "The manifest file format is invalid !"; Error = "The manifest file format is invalid.";
return; return;
} }
@@ -115,9 +115,9 @@ namespace YooAsset
// 检测配置 // 检测配置
if (Manifest.EnableAddressable && Manifest.LocationToLower) if (Manifest.EnableAddressable && Manifest.LocationToLower)
throw new YooManifestException("Addressable not support location to lower !"); throw new YooManifestException("Addressable not support location to lower.");
if (Manifest.EnableAddressable == false && Manifest.ReplaceAssetPathWithAddress) if (Manifest.EnableAddressable == false && Manifest.ReplaceAssetPathWithAddress)
throw new YooManifestException("Replace asset path with address need enable Addressable !"); throw new YooManifestException("Replace asset path with address need enable Addressable.");
_steps = ESteps.PrepareAssetList; _steps = ESteps.PrepareAssetList;
} }

View File

@@ -40,7 +40,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "The file system parameters is empty !"; Error = "The file system parameters is empty.";
return; return;
} }
@@ -50,7 +50,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "An empty object exists in the list!"; Error = "An empty object exists in the list.";
return; return;
} }
} }
@@ -76,7 +76,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = "Failed to create file system instance !"; Error = "Failed to create file system instance.";
return; return;
} }

View File

@@ -6,12 +6,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 包裹版本 /// 包裹版本
/// </summary> /// </summary>
public string PackageVersion { set; get; } public string PackageVersion { get; set; }
/// <summary> /// <summary>
/// 超时时间 /// 超时时间
/// </summary> /// </summary>
public int Timeout { set; get; } public int Timeout { get; set; }
public LoadPackageManifestOptions(string packageVersion, int timeout) public LoadPackageManifestOptions(string packageVersion, int timeout)
{ {

View File

@@ -102,7 +102,7 @@ namespace YooAsset
{ {
if (Status != EOperationStatus.Succeed) if (Status != EOperationStatus.Succeed)
{ {
YooLogger.Error($"{nameof(PreDownloadContentOperation)} status is not succeed !"); YooLogger.Error($"{nameof(PreDownloadContentOperation)} status is not succeed.");
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName); return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName);
} }
@@ -116,7 +116,7 @@ namespace YooAsset
{ {
if (Status != EOperationStatus.Succeed) if (Status != EOperationStatus.Succeed)
{ {
YooLogger.Error($"{nameof(PreDownloadContentOperation)} status is not succeed !"); YooLogger.Error($"{nameof(PreDownloadContentOperation)} status is not succeed.");
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName); return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName);
} }

View File

@@ -6,12 +6,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 预下载的包裹版本 /// 预下载的包裹版本
/// </summary> /// </summary>
public string PackageVersion { set; get; } public string PackageVersion { get; set; }
/// <summary> /// <summary>
/// 资源清单请求超时时间 /// 资源清单请求超时时间
/// </summary> /// </summary>
public int Timeout { set; get; } public int Timeout { get; set; }
public PreDownloadContentOptions(string packageVersion, int timeout) public PreDownloadContentOptions(string packageVersion, int timeout)
{ {

View File

@@ -18,7 +18,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 当前最新的包裹版本 /// 当前最新的包裹版本
/// </summary> /// </summary>
public string PackageVersion { private set; get; } public string PackageVersion { get; private set; }
internal RequestPackageVersionOperation(FileSystemHost host, RequestPackageVersionOptions options) internal RequestPackageVersionOperation(FileSystemHost host, RequestPackageVersionOptions options)

View File

@@ -6,12 +6,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 在URL末尾添加时间戳 /// 在URL末尾添加时间戳
/// </summary> /// </summary>
public bool AppendTimeTicks { set; get; } public bool AppendTimeTicks { get; set; }
/// <summary> /// <summary>
/// 超时时间 /// 超时时间
/// </summary> /// </summary>
public int Timeout { set; get; } public int Timeout { get; set; }
public RequestPackageVersionOptions(bool appendTimeTicks, int timeout) public RequestPackageVersionOptions(bool appendTimeTicks, int timeout)
{ {

View File

@@ -335,7 +335,7 @@ namespace YooAsset
{ {
string error; string error;
if (string.IsNullOrEmpty(location)) if (string.IsNullOrEmpty(location))
error = $"The location is null or empty !"; error = $"The location is null or empty.";
else else
error = $"The location is invalid : {location}"; error = $"The location is invalid : {location}";
AssetInfo assetInfo = new AssetInfo(PackageName, error); AssetInfo assetInfo = new AssetInfo(PackageName, error);
@@ -369,8 +369,8 @@ namespace YooAsset
{ {
if (IncludeAssetGUID == false) if (IncludeAssetGUID == false)
{ {
YooLogger.Warning("Package manifest not include asset guid ! Please check asset bundle collector settings."); YooLogger.Warning("Package manifest not include asset guid. Please check asset bundle collector settings.");
AssetInfo assetInfo = new AssetInfo(PackageName, "AssetGUID data is empty !"); AssetInfo assetInfo = new AssetInfo(PackageName, "AssetGUID data is empty.");
return assetInfo; return assetInfo;
} }
@@ -384,7 +384,7 @@ namespace YooAsset
{ {
string error; string error;
if (string.IsNullOrEmpty(assetGUID)) if (string.IsNullOrEmpty(assetGUID))
error = $"The assetGUID is null or empty !"; error = $"The assetGUID is null or empty.";
else else
error = $"The assetGUID is invalid : {assetGUID}"; error = $"The assetGUID is invalid : {assetGUID}";
AssetInfo assetInfo = new AssetInfo(PackageName, error); AssetInfo assetInfo = new AssetInfo(PackageName, error);

View File

@@ -19,10 +19,5 @@ namespace YooAsset
public const string FileVersion = "2025.9.30"; public const string FileVersion = "2025.9.30";
public const string VERSION_2025_8_28 = "2025.8.28"; public const string VERSION_2025_8_28 = "2025.8.28";
public const string VERSION_2025_9_30 = "2025.9.30"; public const string VERSION_2025_9_30 = "2025.9.30";
/// <summary>
/// 版本兼容
/// </summary>
public const bool BackwardCompatible = true;
} }
} }

View File

@@ -8,6 +8,8 @@ namespace YooAsset
{ {
internal static class PackageManifestTools internal static class PackageManifestTools
{ {
private const int MD5HashLength = 32; //MD5的哈希值通常为32个字符
/// <summary> /// <summary>
/// 验证清单文件的二进制数据 /// 验证清单文件的二进制数据
/// </summary> /// </summary>
@@ -19,9 +21,8 @@ namespace YooAsset
return false; return false;
// 注意:兼容俩种验证方式 // 注意:兼容俩种验证方式
// 注意计算MD5的哈希值通常为32个字符
string fileHash; string fileHash;
if (hashValue.Length == 32) if (hashValue.Length == MD5HashLength)
fileHash = HashUtility.BytesMD5(fileData); fileHash = HashUtility.BytesMD5(fileData);
else else
fileHash = HashUtility.BytesCRC32(fileData); fileHash = HashUtility.BytesCRC32(fileData);

View File

@@ -9,9 +9,8 @@ namespace YooAsset
public class ResourcePackage public class ResourcePackage
{ {
private InitializePackageOperation _initializeOp; private InitializePackageOperation _initializeOp;
internal ResourceManager _resourceManager; private ResourceManager _resourceManager;
internal FileSystemHost _fileSystemHost; private FileSystemHost _fileSystemHost;
internal EPlayMode _playMode;
/// <summary> /// <summary>
/// 包裹名 /// 包裹名
@@ -53,15 +52,16 @@ namespace YooAsset
set { OperationSystem.SetSchedulerPriority(PackageName, value); } set { OperationSystem.SetSchedulerPriority(PackageName, value); }
} }
internal ResourcePackage(string packageName) internal ResourcePackage(string packageName)
{ {
PackageName = packageName; PackageName = packageName;
} }
internal void InternalInitialize(ResourceManager manager, FileSystemHost host)
/// <summary> {
/// 销毁资源包裹 _resourceManager = manager;
/// </summary> _fileSystemHost = host;
}
internal void InternalDestroy() internal void InternalDestroy()
{ {
_initializeOp = null; _initializeOp = null;
@@ -91,7 +91,7 @@ namespace YooAsset
// 检测重复初始化 // 检测重复初始化
if (_initializeOp != null) if (_initializeOp != null)
throw new YooPackageException(PackageName, $"Package '{PackageName}' is already initialized !"); throw new YooPackageException(PackageName, $"Resource package '{PackageName}' is already initialized.");
// 开始初始化操作 // 开始初始化操作
_initializeOp = new InitializePackageOperation(this, options); _initializeOp = new InitializePackageOperation(this, options);
@@ -113,7 +113,7 @@ namespace YooAsset
{ {
var options = new UnloadAllAssetsOptions(true, true); var options = new UnloadAllAssetsOptions(true, true);
var operation = new DestroyPackageOperation(this, options); var operation = new DestroyPackageOperation(this, options);
OperationSystem.StartOperation(OperationSystem.GLOBAL_SCHEDULER_NAME, operation); OperationSystem.StartOperation(OperationSystem.GlobalSchedulerName, operation);
return operation; return operation;
} }
@@ -123,7 +123,8 @@ namespace YooAsset
/// </summary> /// </summary>
public RequestPackageVersionOperation RequestPackageVersionAsync() public RequestPackageVersionOperation RequestPackageVersionAsync()
{ {
var options = new RequestPackageVersionOptions(true, 60); int defaultTimeout = 60;
var options = new RequestPackageVersionOptions(true, defaultTimeout);
return RequestPackageVersionAsync(options); return RequestPackageVersionAsync(options);
} }
@@ -132,7 +133,7 @@ namespace YooAsset
/// </summary> /// </summary>
public RequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options) public RequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
{ {
DebugCheckInitialize(false); EnsureInitialized(false);
var operation = new RequestPackageVersionOperation(_fileSystemHost, options); var operation = new RequestPackageVersionOperation(_fileSystemHost, options);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
@@ -143,12 +144,12 @@ namespace YooAsset
/// </summary> /// </summary>
public LoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options) public LoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options)
{ {
DebugCheckInitialize(false); EnsureInitialized(false);
// 注意:强烈建议在更新之前保持加载器为空! // 注意:强烈建议在更新之前保持加载器为空!
if (_resourceManager.HasAnyLoader()) if (_resourceManager.HasAnyLoader())
{ {
YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(UnloadAllAssetsAsync)} method to release loaded bundle !"); YooLogger.Warning($"Found loaded bundle before update manifest. Recommended to call the {nameof(UnloadAllAssetsAsync)} method to release loaded bundle.");
} }
var operation = new LoadPackageManifestOperation(_fileSystemHost, options); var operation = new LoadPackageManifestOperation(_fileSystemHost, options);
@@ -161,7 +162,7 @@ namespace YooAsset
/// </summary> /// </summary>
public PreDownloadContentOperation PreDownloadContentAsync(PreDownloadContentOptions options) public PreDownloadContentOperation PreDownloadContentAsync(PreDownloadContentOptions options)
{ {
DebugCheckInitialize(false); EnsureInitialized(false);
var operation = new PreDownloadContentOperation(_fileSystemHost, options); var operation = new PreDownloadContentOperation(_fileSystemHost, options);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
@@ -172,7 +173,7 @@ namespace YooAsset
/// </summary> /// </summary>
public ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options) public ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
{ {
DebugCheckInitialize(false); EnsureInitialized(false);
options.Manifest = _fileSystemHost.ActiveManifest; options.Manifest = _fileSystemHost.ActiveManifest;
var operation = new ClearCacheFilesOperation(_fileSystemHost, options); var operation = new ClearCacheFilesOperation(_fileSystemHost, options);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
@@ -186,7 +187,7 @@ namespace YooAsset
/// </summary> /// </summary>
public string GetPackageVersion() public string GetPackageVersion()
{ {
DebugCheckInitialize(); EnsureInitialized();
return _fileSystemHost.ActiveManifest.PackageVersion; return _fileSystemHost.ActiveManifest.PackageVersion;
} }
@@ -195,7 +196,7 @@ namespace YooAsset
/// </summary> /// </summary>
public string GetPackageNote() public string GetPackageNote()
{ {
DebugCheckInitialize(); EnsureInitialized();
return _fileSystemHost.ActiveManifest.PackageNote; return _fileSystemHost.ActiveManifest.PackageNote;
} }
@@ -204,7 +205,7 @@ namespace YooAsset
/// </summary> /// </summary>
public PackageDetails GetPackageDetails() public PackageDetails GetPackageDetails()
{ {
DebugCheckInitialize(); EnsureInitialized();
return _fileSystemHost.ActiveManifest.GetPackageDetails(); return _fileSystemHost.ActiveManifest.GetPackageDetails();
} }
#endregion #endregion
@@ -225,7 +226,7 @@ namespace YooAsset
/// <param name="options">卸载选项</param> /// <param name="options">卸载选项</param>
public UnloadAllAssetsOperation UnloadAllAssetsAsync(UnloadAllAssetsOptions options) public UnloadAllAssetsOperation UnloadAllAssetsAsync(UnloadAllAssetsOptions options)
{ {
DebugCheckInitialize(); EnsureInitialized();
var operation = new UnloadAllAssetsOperation(_resourceManager, options); var operation = new UnloadAllAssetsOperation(_resourceManager, options);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
@@ -238,7 +239,8 @@ namespace YooAsset
/// </summary> /// </summary>
public UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync() public UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync()
{ {
var options = new UnloadUnusedAssetsOptions(10); int defaultLoopCount = 10;
var options = new UnloadUnusedAssetsOptions(defaultLoopCount);
return UnloadUnusedAssetsAsync(options); return UnloadUnusedAssetsAsync(options);
} }
@@ -248,7 +250,7 @@ namespace YooAsset
/// </summary> /// </summary>
public UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync(UnloadUnusedAssetsOptions options) public UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync(UnloadUnusedAssetsOptions options)
{ {
DebugCheckInitialize(); EnsureInitialized();
var operation = new UnloadUnusedAssetsOperation(_resourceManager, options); var operation = new UnloadUnusedAssetsOperation(_resourceManager, options);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
@@ -260,7 +262,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void TryUnloadUnusedAsset(string location, int loopCount = 10) public void TryUnloadUnusedAsset(string location, int loopCount = 10)
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
_resourceManager.TryUnloadUnusedAsset(assetInfo, loopCount); _resourceManager.TryUnloadUnusedAsset(assetInfo, loopCount);
} }
@@ -271,7 +273,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void TryUnloadUnusedAsset(AssetInfo assetInfo, int loopCount = 10) public void TryUnloadUnusedAsset(AssetInfo assetInfo, int loopCount = 10)
{ {
DebugCheckInitialize(); EnsureInitialized();
_resourceManager.TryUnloadUnusedAsset(assetInfo, loopCount); _resourceManager.TryUnloadUnusedAsset(assetInfo, loopCount);
} }
#endregion #endregion
@@ -283,7 +285,7 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public bool IsNeedDownloadFromRemote(string location) public bool IsNeedDownloadFromRemote(string location)
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
return _fileSystemHost.IsNeedDownloadFromRemoteInternal(assetInfo); return _fileSystemHost.IsNeedDownloadFromRemoteInternal(assetInfo);
} }
@@ -294,7 +296,7 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public bool IsNeedDownloadFromRemote(AssetInfo assetInfo) public bool IsNeedDownloadFromRemote(AssetInfo assetInfo)
{ {
DebugCheckInitialize(); EnsureInitialized();
return _fileSystemHost.IsNeedDownloadFromRemoteInternal(assetInfo); return _fileSystemHost.IsNeedDownloadFromRemoteInternal(assetInfo);
} }
@@ -303,7 +305,7 @@ namespace YooAsset
/// </summary> /// </summary>
public AssetInfo[] GetAllAssetInfos() public AssetInfo[] GetAllAssetInfos()
{ {
DebugCheckInitialize(); EnsureInitialized();
return _fileSystemHost.ActiveManifest.GetAllAssetInfos(); return _fileSystemHost.ActiveManifest.GetAllAssetInfos();
} }
@@ -313,7 +315,7 @@ namespace YooAsset
/// <param name="tag">资源标签</param> /// <param name="tag">资源标签</param>
public AssetInfo[] GetAssetInfos(string tag) public AssetInfo[] GetAssetInfos(string tag)
{ {
DebugCheckInitialize(); EnsureInitialized();
string[] tags = new string[] { tag }; string[] tags = new string[] { tag };
return _fileSystemHost.ActiveManifest.GetAssetInfosByTags(tags); return _fileSystemHost.ActiveManifest.GetAssetInfosByTags(tags);
} }
@@ -324,7 +326,7 @@ namespace YooAsset
/// <param name="tags">资源标签列表</param> /// <param name="tags">资源标签列表</param>
public AssetInfo[] GetAssetInfos(string[] tags) public AssetInfo[] GetAssetInfos(string[] tags)
{ {
DebugCheckInitialize(); EnsureInitialized();
return _fileSystemHost.ActiveManifest.GetAssetInfosByTags(tags); return _fileSystemHost.ActiveManifest.GetAssetInfosByTags(tags);
} }
@@ -334,7 +336,7 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public AssetInfo GetAssetInfo(string location) public AssetInfo GetAssetInfo(string location)
{ {
DebugCheckInitialize(); EnsureInitialized();
return ConvertLocationToAssetInfo(location, null); return ConvertLocationToAssetInfo(location, null);
} }
@@ -345,7 +347,7 @@ namespace YooAsset
/// <param name="type">资源类型</param> /// <param name="type">资源类型</param>
public AssetInfo GetAssetInfo(string location, System.Type type) public AssetInfo GetAssetInfo(string location, System.Type type)
{ {
DebugCheckInitialize(); EnsureInitialized();
return ConvertLocationToAssetInfo(location, type); return ConvertLocationToAssetInfo(location, type);
} }
@@ -355,7 +357,7 @@ namespace YooAsset
/// <param name="assetGUID">资源GUID</param> /// <param name="assetGUID">资源GUID</param>
public AssetInfo GetAssetInfoByGUID(string assetGUID) public AssetInfo GetAssetInfoByGUID(string assetGUID)
{ {
DebugCheckInitialize(); EnsureInitialized();
return ConvertAssetGUIDToAssetInfo(assetGUID, null); return ConvertAssetGUIDToAssetInfo(assetGUID, null);
} }
@@ -366,7 +368,7 @@ namespace YooAsset
/// <param name="type">资源类型</param> /// <param name="type">资源类型</param>
public AssetInfo GetAssetInfoByGUID(string assetGUID, System.Type type) public AssetInfo GetAssetInfoByGUID(string assetGUID, System.Type type)
{ {
DebugCheckInitialize(); EnsureInitialized();
return ConvertAssetGUIDToAssetInfo(assetGUID, type); return ConvertAssetGUIDToAssetInfo(assetGUID, type);
} }
@@ -376,7 +378,7 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public bool CheckLocationValid(string location) public bool CheckLocationValid(string location)
{ {
DebugCheckInitialize(); EnsureInitialized();
string assetPath = _fileSystemHost.ActiveManifest.TryMappingToAssetPath(location); string assetPath = _fileSystemHost.ActiveManifest.TryMappingToAssetPath(location);
return string.IsNullOrEmpty(assetPath) == false; return string.IsNullOrEmpty(assetPath) == false;
} }
@@ -389,7 +391,7 @@ namespace YooAsset
/// <param name="assetInfo">资源信息</param> /// <param name="assetInfo">资源信息</param>
public RawFileHandle LoadRawFileSync(AssetInfo assetInfo) public RawFileHandle LoadRawFileSync(AssetInfo assetInfo)
{ {
DebugCheckInitialize(); EnsureInitialized();
return LoadRawFileInternal(assetInfo, true, 0); return LoadRawFileInternal(assetInfo, true, 0);
} }
@@ -399,7 +401,7 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public RawFileHandle LoadRawFileSync(string location) public RawFileHandle LoadRawFileSync(string location)
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
return LoadRawFileInternal(assetInfo, true, 0); return LoadRawFileInternal(assetInfo, true, 0);
} }
@@ -411,7 +413,7 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public RawFileHandle LoadRawFileAsync(AssetInfo assetInfo, uint priority = 0) public RawFileHandle LoadRawFileAsync(AssetInfo assetInfo, uint priority = 0)
{ {
DebugCheckInitialize(); EnsureInitialized();
return LoadRawFileInternal(assetInfo, false, priority); return LoadRawFileInternal(assetInfo, false, priority);
} }
@@ -422,7 +424,7 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public RawFileHandle LoadRawFileAsync(string location, uint priority = 0) public RawFileHandle LoadRawFileAsync(string location, uint priority = 0)
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
return LoadRawFileInternal(assetInfo, false, priority); return LoadRawFileInternal(assetInfo, false, priority);
} }
@@ -447,7 +449,7 @@ namespace YooAsset
/// <param name="physicsMode">场景物理模式</param> /// <param name="physicsMode">场景物理模式</param>
public SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None) public SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None)
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
return LoadSceneInternal(assetInfo, true, sceneMode, physicsMode, false, 0); return LoadSceneInternal(assetInfo, true, sceneMode, physicsMode, false, 0);
} }
@@ -460,7 +462,7 @@ namespace YooAsset
/// <param name="physicsMode">场景物理模式</param> /// <param name="physicsMode">场景物理模式</param>
public SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None) public SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None)
{ {
DebugCheckInitialize(); EnsureInitialized();
return LoadSceneInternal(assetInfo, true, sceneMode, physicsMode, false, 0); return LoadSceneInternal(assetInfo, true, sceneMode, physicsMode, false, 0);
} }
@@ -474,7 +476,7 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 0) public SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 0)
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
return LoadSceneInternal(assetInfo, false, sceneMode, physicsMode, suspendLoad, priority); return LoadSceneInternal(assetInfo, false, sceneMode, physicsMode, suspendLoad, priority);
} }
@@ -489,13 +491,13 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 0) public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 0)
{ {
DebugCheckInitialize(); EnsureInitialized();
return LoadSceneInternal(assetInfo, false, sceneMode, physicsMode, suspendLoad, priority); return LoadSceneInternal(assetInfo, false, sceneMode, physicsMode, suspendLoad, priority);
} }
private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, LocalPhysicsMode physicsMode, bool suspendLoad, uint priority) private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, LocalPhysicsMode physicsMode, bool suspendLoad, uint priority)
{ {
DebugCheckAssetLoadType(assetInfo.AssetType); DebugEnsureAssetType(assetInfo.AssetType);
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadScene; assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadScene;
var loadSceneParams = new LoadSceneParameters(sceneMode, physicsMode); var loadSceneParams = new LoadSceneParameters(sceneMode, physicsMode);
var handle = _resourceManager.LoadSceneAsync(assetInfo, loadSceneParams, suspendLoad, priority); var handle = _resourceManager.LoadSceneAsync(assetInfo, loadSceneParams, suspendLoad, priority);
@@ -505,14 +507,14 @@ namespace YooAsset
} }
#endregion #endregion
#region #region []
/// <summary> /// <summary>
/// 同步加载资源对象 /// 同步加载资源对象
/// </summary> /// </summary>
/// <param name="assetInfo">资源信息</param> /// <param name="assetInfo">资源信息</param>
public AssetHandle LoadAssetSync(AssetInfo assetInfo) public AssetHandle LoadAssetSync(AssetInfo assetInfo)
{ {
DebugCheckInitialize(); EnsureInitialized();
return LoadAssetInternal(assetInfo, true, 0); return LoadAssetInternal(assetInfo, true, 0);
} }
@@ -523,7 +525,7 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public AssetHandle LoadAssetSync<TObject>(string location) where TObject : UnityEngine.Object public AssetHandle LoadAssetSync<TObject>(string location) where TObject : UnityEngine.Object
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadAssetInternal(assetInfo, true, 0); return LoadAssetInternal(assetInfo, true, 0);
} }
@@ -535,7 +537,7 @@ namespace YooAsset
/// <param name="type">资源类型</param> /// <param name="type">资源类型</param>
public AssetHandle LoadAssetSync(string location, System.Type type) public AssetHandle LoadAssetSync(string location, System.Type type)
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAssetInternal(assetInfo, true, 0); return LoadAssetInternal(assetInfo, true, 0);
} }
@@ -546,9 +548,8 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public AssetHandle LoadAssetSync(string location) public AssetHandle LoadAssetSync(string location)
{ {
DebugCheckInitialize(); EnsureInitialized();
Type type = typeof(UnityEngine.Object); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(UnityEngine.Object));
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAssetInternal(assetInfo, true, 0); return LoadAssetInternal(assetInfo, true, 0);
} }
@@ -560,7 +561,7 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public AssetHandle LoadAssetAsync(AssetInfo assetInfo, uint priority = 0) public AssetHandle LoadAssetAsync(AssetInfo assetInfo, uint priority = 0)
{ {
DebugCheckInitialize(); EnsureInitialized();
return LoadAssetInternal(assetInfo, false, priority); return LoadAssetInternal(assetInfo, false, priority);
} }
@@ -572,7 +573,7 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public AssetHandle LoadAssetAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object public AssetHandle LoadAssetAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadAssetInternal(assetInfo, false, priority); return LoadAssetInternal(assetInfo, false, priority);
} }
@@ -585,7 +586,7 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public AssetHandle LoadAssetAsync(string location, System.Type type, uint priority = 0) public AssetHandle LoadAssetAsync(string location, System.Type type, uint priority = 0)
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAssetInternal(assetInfo, false, priority); return LoadAssetInternal(assetInfo, false, priority);
} }
@@ -597,16 +598,15 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public AssetHandle LoadAssetAsync(string location, uint priority = 0) public AssetHandle LoadAssetAsync(string location, uint priority = 0)
{ {
DebugCheckInitialize(); EnsureInitialized();
Type type = typeof(UnityEngine.Object); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(UnityEngine.Object));
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAssetInternal(assetInfo, false, priority); return LoadAssetInternal(assetInfo, false, priority);
} }
private AssetHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority) private AssetHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
{ {
DebugCheckAssetLoadType(assetInfo.AssetType); DebugEnsureAssetType(assetInfo.AssetType);
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadAsset; assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadAsset;
var handle = _resourceManager.LoadAssetAsync(assetInfo, priority); var handle = _resourceManager.LoadAssetAsync(assetInfo, priority);
if (waitForAsyncComplete) if (waitForAsyncComplete)
@@ -615,14 +615,14 @@ namespace YooAsset
} }
#endregion #endregion
#region #region []
/// <summary> /// <summary>
/// 同步加载子资源对象 /// 同步加载子资源对象
/// </summary> /// </summary>
/// <param name="assetInfo">资源信息</param> /// <param name="assetInfo">资源信息</param>
public SubAssetsHandle LoadSubAssetsSync(AssetInfo assetInfo) public SubAssetsHandle LoadSubAssetsSync(AssetInfo assetInfo)
{ {
DebugCheckInitialize(); EnsureInitialized();
return LoadSubAssetsInternal(assetInfo, true, 0); return LoadSubAssetsInternal(assetInfo, true, 0);
} }
@@ -633,7 +633,7 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public SubAssetsHandle LoadSubAssetsSync<TObject>(string location) where TObject : UnityEngine.Object public SubAssetsHandle LoadSubAssetsSync<TObject>(string location) where TObject : UnityEngine.Object
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadSubAssetsInternal(assetInfo, true, 0); return LoadSubAssetsInternal(assetInfo, true, 0);
} }
@@ -645,7 +645,7 @@ namespace YooAsset
/// <param name="type">子对象类型</param> /// <param name="type">子对象类型</param>
public SubAssetsHandle LoadSubAssetsSync(string location, System.Type type) public SubAssetsHandle LoadSubAssetsSync(string location, System.Type type)
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadSubAssetsInternal(assetInfo, true, 0); return LoadSubAssetsInternal(assetInfo, true, 0);
} }
@@ -656,9 +656,8 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public SubAssetsHandle LoadSubAssetsSync(string location) public SubAssetsHandle LoadSubAssetsSync(string location)
{ {
DebugCheckInitialize(); EnsureInitialized();
Type type = typeof(UnityEngine.Object); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(UnityEngine.Object));
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadSubAssetsInternal(assetInfo, true, 0); return LoadSubAssetsInternal(assetInfo, true, 0);
} }
@@ -670,7 +669,7 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo, uint priority = 0) public SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo, uint priority = 0)
{ {
DebugCheckInitialize(); EnsureInitialized();
return LoadSubAssetsInternal(assetInfo, false, priority); return LoadSubAssetsInternal(assetInfo, false, priority);
} }
@@ -682,7 +681,7 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public SubAssetsHandle LoadSubAssetsAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object public SubAssetsHandle LoadSubAssetsAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadSubAssetsInternal(assetInfo, false, priority); return LoadSubAssetsInternal(assetInfo, false, priority);
} }
@@ -695,7 +694,7 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public SubAssetsHandle LoadSubAssetsAsync(string location, System.Type type, uint priority = 0) public SubAssetsHandle LoadSubAssetsAsync(string location, System.Type type, uint priority = 0)
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadSubAssetsInternal(assetInfo, false, priority); return LoadSubAssetsInternal(assetInfo, false, priority);
} }
@@ -707,16 +706,15 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public SubAssetsHandle LoadSubAssetsAsync(string location, uint priority = 0) public SubAssetsHandle LoadSubAssetsAsync(string location, uint priority = 0)
{ {
DebugCheckInitialize(); EnsureInitialized();
Type type = typeof(UnityEngine.Object); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(UnityEngine.Object));
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadSubAssetsInternal(assetInfo, false, priority); return LoadSubAssetsInternal(assetInfo, false, priority);
} }
private SubAssetsHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority) private SubAssetsHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
{ {
DebugCheckAssetLoadType(assetInfo.AssetType); DebugEnsureAssetType(assetInfo.AssetType);
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadSubAssets; assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadSubAssets;
var handle = _resourceManager.LoadSubAssetsAsync(assetInfo, priority); var handle = _resourceManager.LoadSubAssetsAsync(assetInfo, priority);
if (waitForAsyncComplete) if (waitForAsyncComplete)
@@ -725,14 +723,14 @@ namespace YooAsset
} }
#endregion #endregion
#region #region []
/// <summary> /// <summary>
/// 同步加载资源包内所有资源对象 /// 同步加载资源包内所有资源对象
/// </summary> /// </summary>
/// <param name="assetInfo">资源信息</param> /// <param name="assetInfo">资源信息</param>
public AllAssetsHandle LoadAllAssetsSync(AssetInfo assetInfo) public AllAssetsHandle LoadAllAssetsSync(AssetInfo assetInfo)
{ {
DebugCheckInitialize(); EnsureInitialized();
return LoadAllAssetsInternal(assetInfo, true, 0); return LoadAllAssetsInternal(assetInfo, true, 0);
} }
@@ -743,7 +741,7 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public AllAssetsHandle LoadAllAssetsSync<TObject>(string location) where TObject : UnityEngine.Object public AllAssetsHandle LoadAllAssetsSync<TObject>(string location) where TObject : UnityEngine.Object
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadAllAssetsInternal(assetInfo, true, 0); return LoadAllAssetsInternal(assetInfo, true, 0);
} }
@@ -755,7 +753,7 @@ namespace YooAsset
/// <param name="type">子对象类型</param> /// <param name="type">子对象类型</param>
public AllAssetsHandle LoadAllAssetsSync(string location, System.Type type) public AllAssetsHandle LoadAllAssetsSync(string location, System.Type type)
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAllAssetsInternal(assetInfo, true, 0); return LoadAllAssetsInternal(assetInfo, true, 0);
} }
@@ -766,9 +764,8 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public AllAssetsHandle LoadAllAssetsSync(string location) public AllAssetsHandle LoadAllAssetsSync(string location)
{ {
DebugCheckInitialize(); EnsureInitialized();
Type type = typeof(UnityEngine.Object); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(UnityEngine.Object));
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAllAssetsInternal(assetInfo, true, 0); return LoadAllAssetsInternal(assetInfo, true, 0);
} }
@@ -780,7 +777,7 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo, uint priority = 0) public AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo, uint priority = 0)
{ {
DebugCheckInitialize(); EnsureInitialized();
return LoadAllAssetsInternal(assetInfo, false, priority); return LoadAllAssetsInternal(assetInfo, false, priority);
} }
@@ -792,7 +789,7 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public AllAssetsHandle LoadAllAssetsAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object public AllAssetsHandle LoadAllAssetsAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadAllAssetsInternal(assetInfo, false, priority); return LoadAllAssetsInternal(assetInfo, false, priority);
} }
@@ -805,7 +802,7 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public AllAssetsHandle LoadAllAssetsAsync(string location, System.Type type, uint priority = 0) public AllAssetsHandle LoadAllAssetsAsync(string location, System.Type type, uint priority = 0)
{ {
DebugCheckInitialize(); EnsureInitialized();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAllAssetsInternal(assetInfo, false, priority); return LoadAllAssetsInternal(assetInfo, false, priority);
} }
@@ -817,16 +814,15 @@ namespace YooAsset
/// <param name="priority">加载的优先级</param> /// <param name="priority">加载的优先级</param>
public AllAssetsHandle LoadAllAssetsAsync(string location, uint priority = 0) public AllAssetsHandle LoadAllAssetsAsync(string location, uint priority = 0)
{ {
DebugCheckInitialize(); EnsureInitialized();
Type type = typeof(UnityEngine.Object); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(UnityEngine.Object));
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAllAssetsInternal(assetInfo, false, priority); return LoadAllAssetsInternal(assetInfo, false, priority);
} }
private AllAssetsHandle LoadAllAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority) private AllAssetsHandle LoadAllAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
{ {
DebugCheckAssetLoadType(assetInfo.AssetType); DebugEnsureAssetType(assetInfo.AssetType);
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadAllAssets; assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadAllAssets;
var handle = _resourceManager.LoadAllAssetsAsync(assetInfo, priority); var handle = _resourceManager.LoadAllAssetsAsync(assetInfo, priority);
if (waitForAsyncComplete) if (waitForAsyncComplete)
@@ -841,16 +837,16 @@ namespace YooAsset
/// </summary> /// </summary>
public ResourceDownloaderOperation CreateResourceDownloader(ResourceDownloaderOptions options) public ResourceDownloaderOperation CreateResourceDownloader(ResourceDownloaderOptions options)
{ {
DebugCheckInitialize(); EnsureInitialized();
return _fileSystemHost.CreateResourceDownloader(options); return _fileSystemHost.CreateResourceDownloader(options);
} }
/// <summary> /// <summary>
/// 创建资源下载器,用于下载指定的资源信息列表依赖的资源包文件 /// 创建资源下载器,用于下载指定的资源信息列表依赖的资源包文件
/// </summary> /// </summary>
public ResourceDownloaderOperation CreateResourceDownloader(BundleDownloaderOptions options) public ResourceDownloaderOperation CreateResourceDownloader(BundleDownloaderOptions options)
{ {
DebugCheckInitialize(); EnsureInitialized();
return _fileSystemHost.CreateResourceDownloader(options); return _fileSystemHost.CreateResourceDownloader(options);
} }
#endregion #endregion
@@ -861,7 +857,7 @@ namespace YooAsset
/// </summary> /// </summary>
public ResourceUnpackerOperation CreateResourceUnpacker(ResourceUnpackerOptions options) public ResourceUnpackerOperation CreateResourceUnpacker(ResourceUnpackerOptions options)
{ {
DebugCheckInitialize(); EnsureInitialized();
return _fileSystemHost.CreateResourceUnpacker(options); return _fileSystemHost.CreateResourceUnpacker(options);
} }
#endregion #endregion
@@ -872,7 +868,7 @@ namespace YooAsset
/// </summary> /// </summary>
public ResourceImporterOperation CreateResourceImporter(BundleImporterOptions options) public ResourceImporterOperation CreateResourceImporter(BundleImporterOptions options)
{ {
DebugCheckInitialize(); EnsureInitialized();
return _fileSystemHost.CreateResourceImporter(options); return _fileSystemHost.CreateResourceImporter(options);
} }
#endregion #endregion
@@ -889,47 +885,43 @@ namespace YooAsset
#endregion #endregion
#region #region
private void DebugCheckInitialize(bool checkActiveManifest = true) private void EnsureInitialized(bool checkActiveManifest = true)
{ {
if (InitializeStatus != EOperationStatus.Succeed) if (InitializeStatus != EOperationStatus.Succeed)
{ {
if (InitializeStatus == EOperationStatus.None) if (InitializeStatus == EOperationStatus.None)
{ {
throw new YooPackageException(PackageName, "Package not initialize !"); throw new YooPackageException(PackageName, "Resource package not initialized.");
} }
else if (InitializeStatus == EOperationStatus.Processing) else if (InitializeStatus == EOperationStatus.Processing)
{ {
throw new YooPackageException(PackageName, "Package initialize not completed !"); throw new YooPackageException(PackageName, "Resource package initialization not completed.");
} }
else if (InitializeStatus == EOperationStatus.Failed) else if (InitializeStatus == EOperationStatus.Failed)
{ {
string error = _initializeOp == null ? string.Empty : _initializeOp.Error; string error = _initializeOp == null ? string.Empty : _initializeOp.Error;
throw new YooPackageException(PackageName, $"Package initialize failed ! {error}"); throw new YooPackageException(PackageName, $"Resource package initialization failed. Error: {error}");
} }
} }
if (checkActiveManifest) if (checkActiveManifest)
{ {
if (_fileSystemHost.ActiveManifest == null) if (_fileSystemHost.ActiveManifest == null)
throw new YooPackageException(PackageName, "Can not found active package manifest !"); throw new YooPackageException(PackageName, "Cannot found active package manifest.");
} }
} }
[Conditional("DEBUG")] [Conditional("DEBUG")]
private void DebugCheckAssetLoadType(System.Type type) private void DebugEnsureAssetType(System.Type type)
{ {
if (type == null) if (type == null)
return; return;
if (typeof(UnityEngine.Behaviour).IsAssignableFrom(type)) if (typeof(UnityEngine.Behaviour).IsAssignableFrom(type))
{ throw new YooLoadException($"Load asset type is invalid : {type.FullName}");
throw new YooLoadException($"Load asset type is invalid : {type.FullName} !");
}
if (typeof(UnityEngine.Object).IsAssignableFrom(type) == false) if (typeof(UnityEngine.Object).IsAssignableFrom(type) == false)
{ throw new YooLoadException($"Load asset type is invalid : {type.FullName}");
throw new YooLoadException($"Load asset type is invalid : {type.FullName} !");
}
} }
#endregion #endregion

View File

@@ -121,7 +121,7 @@ namespace YooAsset
byte[] bytes = Encoding.UTF8.GetBytes(value); byte[] bytes = Encoding.UTF8.GetBytes(value);
int count = bytes.Length; int count = bytes.Length;
if (count > ushort.MaxValue) if (count > ushort.MaxValue)
throw new FormatException($"Write string length cannot be greater than {ushort.MaxValue} !"); throw new FormatException($"Write string length cannot be greater than {ushort.MaxValue}");
WriteUInt16(Convert.ToUInt16(count)); WriteUInt16(Convert.ToUInt16(count));
WriteBytes(bytes); WriteBytes(bytes);
@@ -137,7 +137,7 @@ namespace YooAsset
{ {
int count = values.Length; int count = values.Length;
if (count > ushort.MaxValue) if (count > ushort.MaxValue)
throw new FormatException($"Write array length cannot be greater than {ushort.MaxValue} !"); throw new FormatException($"Write array length cannot be greater than {ushort.MaxValue}");
WriteUInt16(Convert.ToUInt16(count)); WriteUInt16(Convert.ToUInt16(count));
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
@@ -156,7 +156,7 @@ namespace YooAsset
{ {
int count = values.Length; int count = values.Length;
if (count > ushort.MaxValue) if (count > ushort.MaxValue)
throw new FormatException($"Write array length cannot be greater than {ushort.MaxValue} !"); throw new FormatException($"Write array length cannot be greater than {ushort.MaxValue}");
WriteUInt16(Convert.ToUInt16(count)); WriteUInt16(Convert.ToUInt16(count));
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
@@ -175,7 +175,7 @@ namespace YooAsset
{ {
int count = values.Length; int count = values.Length;
if (count > ushort.MaxValue) if (count > ushort.MaxValue)
throw new FormatException($"Write array length cannot be greater than {ushort.MaxValue} !"); throw new FormatException($"Write array length cannot be greater than {ushort.MaxValue}");
WriteUInt16(Convert.ToUInt16(count)); WriteUInt16(Convert.ToUInt16(count));
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)

View File

@@ -13,21 +13,21 @@ namespace YooAsset
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void OnRuntimeInitialize() private static void OnRuntimeInitialize()
{ {
_isInitialize = false; _isInitialized = false;
_packages.Clear(); _packages.Clear();
} }
#endif #endif
private static bool _isInitialize = false; private static bool _isInitialized;
private static GameObject _driver = null; private static GameObject _driver;
private static readonly List<ResourcePackage> _packages = new List<ResourcePackage>(); private static readonly Dictionary<string, ResourcePackage> _packages = new Dictionary<string, ResourcePackage>(10);
/// <summary> /// <summary>
/// 是否已经初始化 /// 是否已经初始化
/// </summary> /// </summary>
public static bool Initialized public static bool Initialized
{ {
get { return _isInitialize; } get { return _isInitialized; }
} }
/// <summary> /// <summary>
@@ -36,31 +36,27 @@ namespace YooAsset
/// <param name="logger">自定义日志处理</param> /// <param name="logger">自定义日志处理</param>
public static void Initialize(ILogger logger = null) public static void Initialize(ILogger logger = null)
{ {
if (_isInitialize) if (_isInitialized)
{ {
UnityEngine.Debug.LogWarning($"{nameof(YooAssets)} is initialized !"); YooLogger.Warning("YooAssets is already initialized.");
return; return;
} }
if (_isInitialize == false) YooLogger.Logger = logger;
{
YooLogger.Logger = logger;
// 创建驱动器 // 创建驱动器
_isInitialize = true; _isInitialized = true;
_driver = new UnityEngine.GameObject($"[{nameof(YooAssets)}]"); _driver = new UnityEngine.GameObject($"[{nameof(YooAssets)}]");
_driver.AddComponent<YooAssetsDriver>(); _driver.AddComponent<YooAssetsDriver>();
UnityEngine.Object.DontDestroyOnLoad(_driver); UnityEngine.Object.DontDestroyOnLoad(_driver);
YooLogger.Log($"{nameof(YooAssets)} initialize !");
#if DEBUG #if DEBUG
// 添加远程调试脚本 // 添加远程调试脚本
_driver.AddComponent<RemoteDebuggerInRuntime>(); _driver.AddComponent<RemoteDebuggerInRuntime>();
#endif #endif
// 初始化异步操作系统 // 初始化异步操作系统
OperationSystem.Initialize(); OperationSystem.Initialize();
}
} }
/// <summary> /// <summary>
@@ -68,9 +64,9 @@ namespace YooAsset
/// </summary> /// </summary>
public static void Destroy() public static void Destroy()
{ {
if (_isInitialize) if (_isInitialized)
{ {
_isInitialize = false; _isInitialized = false;
if (_driver != null) if (_driver != null)
GameObject.Destroy(_driver); GameObject.Destroy(_driver);
@@ -91,35 +87,25 @@ namespace YooAsset
/// </summary> /// </summary>
internal static void Update() internal static void Update()
{ {
if (_isInitialize) if (_isInitialized)
{ {
OperationSystem.Update(); OperationSystem.Update();
} }
} }
/// <summary>
/// 创建资源包裹
/// </summary>
/// <param name="packageName">包裹名称</param>
public static ResourcePackage CreatePackage(string packageName)
{
return CreatePackage(packageName, 0);
}
/// <summary> /// <summary>
/// 创建资源包裹 /// 创建资源包裹
/// </summary> /// </summary>
/// <param name="packageName">包裹名称</param> /// <param name="packageName">包裹名称</param>
/// <param name="packagePriority">包裹优先级(值越大越优先更新)</param> /// <param name="packagePriority">包裹优先级(值越大越优先更新)</param>
public static ResourcePackage CreatePackage(string packageName, uint packagePriority) public static ResourcePackage CreatePackage(string packageName, uint packagePriority = 0)
{ {
CheckException(packageName); EnsureInitialized(packageName);
if (ContainsPackage(packageName)) if (ContainsPackage(packageName))
throw new YooPackageException(packageName, $"Package {packageName} already existed ! Cannot create duplicate packages."); throw new YooPackageException(packageName, $"Resource package {packageName} already existed. Cannot create duplicate packages.");
YooLogger.Log($"Create resource package : {packageName}");
ResourcePackage package = new ResourcePackage(packageName); ResourcePackage package = new ResourcePackage(packageName);
_packages.Add(package); _packages.Add(packageName, package);
// 注册包裹调度器 // 注册包裹调度器
OperationSystem.CreatePackageScheduler(packageName, packagePriority); OperationSystem.CreatePackageScheduler(packageName, packagePriority);
@@ -133,7 +119,7 @@ namespace YooAsset
/// <param name="packageName">包裹名称</param> /// <param name="packageName">包裹名称</param>
public static ResourcePackage GetPackage(string packageName) public static ResourcePackage GetPackage(string packageName)
{ {
CheckException(packageName); EnsureInitialized(packageName);
var package = GetPackageInternal(packageName); var package = GetPackageInternal(packageName);
if (package == null) if (package == null)
YooLogger.Error($"Can not found resource package : {packageName}"); YooLogger.Error($"Can not found resource package : {packageName}");
@@ -146,16 +132,16 @@ namespace YooAsset
/// <param name="packageName">包裹名称</param> /// <param name="packageName">包裹名称</param>
public static ResourcePackage TryGetPackage(string packageName) public static ResourcePackage TryGetPackage(string packageName)
{ {
CheckException(packageName); EnsureInitialized(packageName);
return GetPackageInternal(packageName); return GetPackageInternal(packageName);
} }
/// <summary> /// <summary>
/// 获取所有资源包裹 /// 获取所有资源包裹
/// </summary> /// </summary>
public static List<ResourcePackage> GetAllPackages() public static IReadOnlyList<ResourcePackage> GetAllPackages()
{ {
return _packages.ToList(); return _packages.Values.ToList();
} }
/// <summary> /// <summary>
@@ -164,35 +150,24 @@ namespace YooAsset
/// <param name="packageName">包裹名称</param> /// <param name="packageName">包裹名称</param>
public static bool RemovePackage(string packageName) public static bool RemovePackage(string packageName)
{ {
CheckException(packageName); EnsureInitialized(packageName);
ResourcePackage package = GetPackageInternal(packageName); ResourcePackage package = GetPackageInternal(packageName);
if (package == null) if (package == null)
return false;
return RemovePackage(package);
}
/// <summary>
/// 移除资源包裹
/// </summary>
/// <param name="package">包裹实例对象</param>
public static bool RemovePackage(ResourcePackage package)
{
CheckException(package);
string packageName = package.PackageName;
if (package.InitializeStatus != EOperationStatus.None)
{ {
YooLogger.Error($"The resource package {packageName} has not been destroyed, please call the method {nameof(ResourcePackage.DestroyPackageAsync)} to destroy!"); YooLogger.Error($"Can not found resource package : {packageName}");
return false; return false;
} }
YooLogger.Log($"Remove resource package : {packageName}"); if (package.InitializeStatus != EOperationStatus.None)
{
YooLogger.Error($"The resource package {packageName} has not been destroyed, please call the method {nameof(ResourcePackage.DestroyPackageAsync)} to destroy.");
return false;
}
// 先销毁调度器,再移除包裹 // 先销毁调度器,再移除包裹
OperationSystem.DestroyPackageScheduler(packageName); OperationSystem.DestroyPackageScheduler(packageName);
_packages.Remove(package); return _packages.Remove(packageName);
return true;
} }
/// <summary> /// <summary>
@@ -201,35 +176,23 @@ namespace YooAsset
/// <param name="packageName">包裹名称</param> /// <param name="packageName">包裹名称</param>
public static bool ContainsPackage(string packageName) public static bool ContainsPackage(string packageName)
{ {
CheckException(packageName); EnsureInitialized(packageName);
var package = GetPackageInternal(packageName); var package = GetPackageInternal(packageName);
return package != null; return package != null;
} }
private static ResourcePackage GetPackageInternal(string packageName) private static ResourcePackage GetPackageInternal(string packageName)
{ {
foreach (var package in _packages) _packages.TryGetValue(packageName, out var package);
{ return package;
if (package.PackageName == packageName)
return package;
}
return null;
} }
private static void CheckException(string packageName) private static void EnsureInitialized(string packageName)
{ {
if (_isInitialize == false) if (_isInitialized == false)
throw new YooInitializeException($"{nameof(YooAssets)} not initialized ! Please call {nameof(YooAssets.Initialize)} first."); throw new YooInitializeException($"YooAssets not initialized. Please call {nameof(YooAssets.Initialize)} first.");
if (string.IsNullOrEmpty(packageName)) if (string.IsNullOrEmpty(packageName))
throw new YooInitializeException("Package name cannot be null or empty !"); throw new YooInitializeException("Package name cannot be null or empty.");
}
private static void CheckException(ResourcePackage package)
{
if (_isInitialize == false)
throw new YooInitializeException($"{nameof(YooAssets)} not initialized ! Please call {nameof(YooAssets.Initialize)} first.");
if (package == null)
throw new YooInitializeException("Package instance cannot be null !");
} }
#region #region
@@ -248,9 +211,9 @@ namespace YooAsset
DebugReport report = new DebugReport(); DebugReport report = new DebugReport();
report.FrameCount = Time.frameCount; report.FrameCount = Time.frameCount;
foreach (var package in _packages) foreach (var kv in _packages)
{ {
var packageData = package.GetDebugPackageData(); var packageData = kv.Value.GetDebugPackageData();
report.PackageDatas.Add(packageData); report.PackageDatas.Add(packageData);
} }
return report; return report;

View File

@@ -24,7 +24,7 @@ namespace YooAsset
#if UNITY_EDITOR #if UNITY_EDITOR
void OnApplicationQuit() void OnApplicationQuit()
{ {
// 说明在编辑器下确保播放被停止时IO类操作被终止。 //注意在编辑器下确保播放被停止时IO类操作被终止。
YooAssets.Destroy(); YooAssets.Destroy();
} }
#endif #endif

View File

@@ -9,7 +9,7 @@ public static class YooAssetsExtension
public static LoadGameObjectOperation LoadGameObjectAsync(this ResourcePackage package, string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false) public static LoadGameObjectOperation LoadGameObjectAsync(this ResourcePackage package, string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false)
{ {
var operation = new LoadGameObjectOperation(package.PackageName, location, position, rotation, parent, destroyGoOnRelease); var operation = new LoadGameObjectOperation(package.PackageName, location, position, rotation, parent, destroyGoOnRelease);
OperationSystem.StartOperation(OperationSystem.GLOBAL_SCHEDULER_NAME, operation); OperationSystem.StartOperation(OperationSystem.GlobalSchedulerName, operation);
return operation; return operation;
} }
} }

View File

@@ -11,6 +11,6 @@ public class OperationHelper
/// </summary> /// </summary>
public static void StartOperation(AsyncOperationBase operation) public static void StartOperation(AsyncOperationBase operation)
{ {
OperationSystem.StartOperation(OperationSystem.GLOBAL_SCHEDULER_NAME, operation); OperationSystem.StartOperation(OperationSystem.GlobalSchedulerName, operation);
} }
} }