diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DestroyPackageOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DestroyPackageOperation.cs
index 3f30a47a..e098324a 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DestroyPackageOperation.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DestroyPackageOperation.cs
@@ -35,30 +35,28 @@ namespace YooAsset
if (_steps == ESteps.CheckInitStatus)
{
- if (_resourcePackage.InitializeStatus == EOperationStatus.None)
+ switch (_resourcePackage.InitializeStatus)
{
- _steps = ESteps.DestroyPackage;
- }
- else if (_resourcePackage.InitializeStatus == EOperationStatus.Processing)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = "The Package is initializing. Please try to destroy the package again later.";
- }
- else if (_resourcePackage.InitializeStatus == EOperationStatus.Failed)
- {
- _steps = ESteps.DestroyPackage;
- }
- else if (_resourcePackage.InitializeStatus == EOperationStatus.Succeed)
- {
- if (_resourcePackage.PackageValid)
- _steps = ESteps.UnloadAllAssets;
- else
+ case EOperationStatus.None:
+ case EOperationStatus.Failed:
_steps = ESteps.DestroyPackage;
- }
- else
- {
- throw new System.NotImplementedException(_resourcePackage.InitializeStatus.ToString());
+ break;
+
+ case EOperationStatus.Processing:
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = "The Package is initializing. Please try to destroy the package again later.";
+ break;
+
+ case EOperationStatus.Succeed:
+ if (_resourcePackage.PackageValid)
+ _steps = ESteps.UnloadAllAssets;
+ else
+ _steps = ESteps.DestroyPackage;
+ break;
+
+ default:
+ throw new System.NotImplementedException(_resourcePackage.InitializeStatus.ToString());
}
}
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs
index 23fde1ac..fc7f5105 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs
@@ -168,10 +168,7 @@ namespace YooAsset
{
_lastDownloadBytes = downloadBytes;
_lastDownloadCount = _cachedDownloadCount;
- if (TotalDownloadBytes == 0)
- Progress = (float)_lastDownloadCount / TotalDownloadCount;
- else
- Progress = (float)_lastDownloadBytes / TotalDownloadBytes;
+ Progress = CalculateProgress();
if (DownloadProgressChangedHandler != null)
{
@@ -280,6 +277,14 @@ namespace YooAsset
}
}
+ private float CalculateProgress()
+ {
+ if (TotalDownloadBytes == 0)
+ return (float)_lastDownloadCount / TotalDownloadCount;
+ else
+ return (float)_lastDownloadBytes / TotalDownloadBytes;
+ }
+
///
/// 合并其它下载器
///
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PackageBundle.cs b/Assets/YooAsset/Runtime/ResourcePackage/PackageBundle.cs
index 8749a540..a1c3a290 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/PackageBundle.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/PackageBundle.cs
@@ -162,10 +162,7 @@ namespace YooAsset
///
public bool HasAnyTags()
{
- if (Tags != null && Tags.Length > 0)
- return true;
- else
- return false;
+ return Tags != null && Tags.Length > 0;
}
///
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestHelper.cs b/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestHelper.cs
index d5aba346..7531af11 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestHelper.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/PackageManifestHelper.cs
@@ -20,17 +20,14 @@ namespace YooAsset
if (string.IsNullOrEmpty(hashValue))
return false;
- // 注意:兼容俩种验证方式
+ // 注意:兼容两种验证方式
string fileHash;
if (hashValue.Length == MD5HashLength)
fileHash = HashUtility.BytesMD5(fileData);
else
fileHash = HashUtility.BytesCRC32(fileData);
- if (fileHash == hashValue)
- return true;
- else
- return false;
+ return fileHash == hashValue;
}
///
@@ -160,29 +157,28 @@ namespace YooAsset
///
public static string GetRemoteBundleFileName(int nameStyle, string bundleName, string fileExtension, string fileHash)
{
- if (nameStyle == (int)EFileNameStyle.HashName)
+ EFileNameStyle style = (EFileNameStyle)nameStyle;
+ switch (style)
{
- return StringUtility.Format("{0}{1}", fileHash, fileExtension);
- }
- else if (nameStyle == (int)EFileNameStyle.BundleName)
- {
- return bundleName;
- }
- else if (nameStyle == (int)EFileNameStyle.BundleName_HashName)
- {
- if (string.IsNullOrEmpty(fileExtension))
- {
- return StringUtility.Format("{0}_{1}", bundleName, fileHash);
- }
- else
- {
- string fileName = bundleName.Remove(bundleName.LastIndexOf('.'));
- return StringUtility.Format("{0}_{1}{2}", fileName, fileHash, fileExtension);
- }
- }
- else
- {
- throw new NotImplementedException($"Invalid name style : {nameStyle}");
+ case EFileNameStyle.HashName:
+ return StringUtility.Format("{0}{1}", fileHash, fileExtension);
+
+ case EFileNameStyle.BundleName:
+ return bundleName;
+
+ case EFileNameStyle.BundleName_HashName:
+ if (string.IsNullOrEmpty(fileExtension))
+ {
+ return StringUtility.Format("{0}_{1}", bundleName, fileHash);
+ }
+ else
+ {
+ string fileName = bundleName.Remove(bundleName.LastIndexOf('.'));
+ return StringUtility.Format("{0}_{1}{2}", fileName, fileHash, fileExtension);
+ }
+
+ default:
+ throw new NotImplementedException($"Invalid name style : {nameStyle}");
}
}
}
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs
index a7bdecba..fcd93780 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs
@@ -889,18 +889,17 @@ namespace YooAsset
{
if (InitializeStatus != EOperationStatus.Succeed)
{
- if (InitializeStatus == EOperationStatus.None)
+ switch (InitializeStatus)
{
- throw new YooPackageException(PackageName, "Resource package not initialized.");
- }
- else if (InitializeStatus == EOperationStatus.Processing)
- {
- throw new YooPackageException(PackageName, "Resource package initialization not completed.");
- }
- else if (InitializeStatus == EOperationStatus.Failed)
- {
- string error = _initializeOp == null ? string.Empty : _initializeOp.Error;
- throw new YooPackageException(PackageName, $"Resource package initialization failed. Error: {error}");
+ case EOperationStatus.None:
+ throw new YooPackageException(PackageName, "Resource package not initialized.");
+
+ case EOperationStatus.Processing:
+ throw new YooPackageException(PackageName, "Resource package initialization not completed.");
+
+ case EOperationStatus.Failed:
+ string error = _initializeOp == null ? string.Empty : _initializeOp.Error;
+ throw new YooPackageException(PackageName, $"Resource package initialization failed. Error: {error}");
}
}