mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-25 10:11:51 +00:00
refactor : 重构代码
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 合并其它下载器
|
||||
/// </summary>
|
||||
|
||||
@@ -162,10 +162,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public bool HasAnyTags()
|
||||
{
|
||||
if (Tags != null && Tags.Length > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return Tags != null && Tags.Length > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -160,29 +157,28 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user