diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs
index 04405170..879a804b 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs
@@ -61,8 +61,7 @@ namespace YooAsset
// 1. 从服务器或缓存中获取AssetBundle文件
if (_steps == ESteps.LoadFile)
{
- string hash = StringUtility.RemoveExtension(MainBundleInfo.Hash);
- _webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_webURL, Hash128.Parse(hash));
+ _webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_webURL, Hash128.Parse(MainBundleInfo.Hash));
_webRequest.SendWebRequest();
_steps = ESteps.CheckFile;
}
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs b/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs
index 69376ee6..aae52a21 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs
@@ -240,7 +240,7 @@ namespace YooAsset
{
if (DownloadSystem.CheckContentIntegrity(GetCachePath(), _bundleInfo.SizeBytes, _bundleInfo.CRC))
{
- DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName);
+ DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.FileName);
_steps = ESteps.CheckAndCopyFile;
}
else
@@ -423,7 +423,7 @@ namespace YooAsset
{
if (DownloadSystem.CheckContentIntegrity(GetCachePath(), _bundleInfo.SizeBytes, _bundleInfo.CRC))
{
- DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName);
+ DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.FileName);
_steps = ESteps.CheckAndCopyFile;
}
else
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs
index 17402b7a..67eeeb7d 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs
@@ -88,7 +88,7 @@ namespace YooAsset
// 创建新的下载器
{
- YooLogger.Log($"Beginning to download file : {bundleInfo.BundleName} URL : {bundleInfo.RemoteMainURL}");
+ YooLogger.Log($"Beginning to download file : {bundleInfo.FileName} URL : {bundleInfo.RemoteMainURL}");
FileUtility.CreateFileDirectory(bundleInfo.GetCacheLoadPath());
DownloaderBase newDownloader;
if (bundleInfo.SizeBytes >= _breakpointResumeFileSize)
@@ -117,16 +117,16 @@ namespace YooAsset
{
if (_cachedHashList.ContainsKey(hash))
{
- string filePath = SandboxHelper.MakeCacheFilePath(hash);
+ string fileName = _cachedHashList[hash];
+ string filePath = SandboxHelper.MakeCacheFilePath(fileName);
if (File.Exists(filePath))
{
return true;
}
else
{
- string bundleName = _cachedHashList[hash];
_cachedHashList.Remove(hash);
- YooLogger.Error($"Cache file is missing : {bundleName} Hash : {hash}");
+ YooLogger.Error($"Cache file is missing : {fileName}");
return false;
}
}
@@ -139,12 +139,12 @@ namespace YooAsset
///
/// 缓存验证过的文件
///
- public static void CacheVerifyFile(string hash, string bundleName)
+ public static void CacheVerifyFile(string hash, string fileName)
{
if (_cachedHashList.ContainsKey(hash) == false)
{
- YooLogger.Log($"Cache verify file : {bundleName} Hash : {hash}");
- _cachedHashList.Add(hash, bundleName);
+ YooLogger.Log($"Cache verify file : {fileName}");
+ _cachedHashList.Add(hash, fileName);
}
}
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs
index 60a75149..e29c7b7e 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs
@@ -80,8 +80,7 @@ namespace YooAsset
// 检查文件完整性
if (hasError == false)
{
- // 注意:如果文件验证失败需要删除文件
-
+ // 注意:如果文件验证失败需要删除文件
if (DownloadSystem.CheckContentIntegrity(_bundleInfo.GetCacheLoadPath(), _bundleInfo.SizeBytes, _bundleInfo.CRC) == false)
{
hasError = true;
@@ -92,7 +91,7 @@ namespace YooAsset
if (hasError == false)
{
_steps = ESteps.Succeed;
- DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName);
+ DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.FileName);
}
else
{
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/HttpDownloader.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/HttpDownloader.cs
index 69401a9b..b3408c62 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/HttpDownloader.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/HttpDownloader.cs
@@ -21,7 +21,7 @@ namespace YooAsset
private bool _running = true;
private string _url;
private string _savePath;
- private string _fileHash;
+ private string _fileName;
private string _fileCRC;
private long _fileSize;
private int _timeout;
@@ -50,11 +50,11 @@ namespace YooAsset
///
/// 开始下载
///
- public void Run(string url, string savePath, string fileHash, string fileCRC, long fileSize, int timeout)
+ public void Run(string url, string savePath, string fileName, string fileCRC, long fileSize, int timeout)
{
_url = url;
_savePath = savePath;
- _fileHash = fileHash;
+ _fileName = fileName;
_fileCRC = fileCRC;
_fileSize = fileSize;
_timeout = timeout;
@@ -159,14 +159,14 @@ namespace YooAsset
bool verfiyResult = DownloadSystem.CheckContentIntegrity(_savePath, _fileSize, _fileCRC);
if (verfiyResult == false)
{
- Error = $"Verify download content failed : {_fileHash}";
+ Error = $"Verify download content failed : {_fileName}";
if (File.Exists(_savePath))
File.Delete(_savePath);
}
}
else
{
- Error = $"Download content is incomplete : {_fileHash}";
+ Error = $"Download content is incomplete : {_fileName}";
}
IsDone = true;
@@ -197,7 +197,7 @@ namespace YooAsset
_requestURL = GetRequestURL();
_threadDownloader = new ThreadDownloader();
- _threadDownloader.Run(_requestURL, _bundleInfo.GetCacheLoadPath(), _bundleInfo.Hash, _bundleInfo.CRC, _bundleInfo.SizeBytes, _timeout);
+ _threadDownloader.Run(_requestURL, _bundleInfo.GetCacheLoadPath(), _bundleInfo.FileName, _bundleInfo.CRC, _bundleInfo.SizeBytes, _timeout);
_steps = ESteps.CheckDownload;
}
@@ -226,7 +226,7 @@ namespace YooAsset
}
else
{
- DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName);
+ DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.FileName);
_steps = ESteps.Succeed;
}
}
diff --git a/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs b/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs
index 4032cf5b..ac664e09 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs
@@ -23,6 +23,11 @@ namespace YooAsset
///
public string BundleName { private set; get; }
+ ///
+ /// 文件名称
+ ///
+ public string FileName { private set; get; }
+
///
/// 远端下载地址
///
@@ -51,7 +56,7 @@ namespace YooAsset
return _patchBundle.Hash;
}
}
-
+
///
/// 校验的CRC
///
@@ -128,6 +133,7 @@ namespace YooAsset
_patchBundle = patchBundle;
LoadMode = loadMode;
BundleName = patchBundle.BundleName;
+ FileName = patchBundle.FileName;
RemoteMainURL = mainURL;
RemoteFallbackURL = fallbackURL;
EditorAssetPath = string.Empty;
@@ -137,6 +143,7 @@ namespace YooAsset
_patchBundle = patchBundle;
LoadMode = loadMode;
BundleName = patchBundle.BundleName;
+ FileName = patchBundle.FileName;
RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty;
EditorAssetPath = editorAssetPath;
@@ -146,6 +153,7 @@ namespace YooAsset
_patchBundle = patchBundle;
LoadMode = loadMode;
BundleName = patchBundle.BundleName;
+ FileName = patchBundle.FileName;
RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty;
EditorAssetPath = string.Empty;
@@ -160,7 +168,7 @@ namespace YooAsset
return string.Empty;
if (string.IsNullOrEmpty(_streamingPath))
- _streamingPath = PathHelper.MakeStreamingLoadPath(_patchBundle.Hash);
+ _streamingPath = PathHelper.MakeStreamingLoadPath(_patchBundle.FileName);
return _streamingPath;
}
@@ -173,7 +181,7 @@ namespace YooAsset
return string.Empty;
if (string.IsNullOrEmpty(_cachePath))
- _cachePath = SandboxHelper.MakeCacheFilePath(_patchBundle.Hash);
+ _cachePath = SandboxHelper.MakeCacheFilePath(_patchBundle.FileName);
return _cachePath;
}
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs
index 8571e945..faaa38b5 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs
@@ -391,7 +391,7 @@ namespace YooAsset
// 注意:在弱联网模式下,我们需要验证指定资源版本的所有资源完整性
if (weaklyUpdate)
{
- string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
+ string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.FileName);
if (File.Exists(filePath))
_waitingList.Add(patchBundle);
else
@@ -399,7 +399,7 @@ namespace YooAsset
}
else
{
- string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
+ string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.FileName);
if (File.Exists(filePath))
_waitingList.Add(patchBundle);
}
@@ -451,7 +451,7 @@ namespace YooAsset
private bool RunThread(PatchBundle patchBundle)
{
- string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
+ string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.FileName);
ThreadInfo info = new ThreadInfo(filePath, patchBundle);
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), info);
}
@@ -467,7 +467,7 @@ namespace YooAsset
if (info.Result)
{
VerifySuccessCount++;
- DownloadSystem.CacheVerifyFile(info.Bundle.Hash, info.Bundle.BundleName);
+ DownloadSystem.CacheVerifyFile(info.Bundle.Hash, info.Bundle.FileName);
}
else
{
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs
index 4fcb9962..49aaad99 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs
@@ -211,7 +211,7 @@ namespace YooAsset
// 注意:通过比对文件大小做快速的文件校验!
// 注意:在初始化的时候会去做最终校验!
- string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
+ string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.FileName);
if (File.Exists(filePath))
{
long fileSize = FileUtility.GetFileSize(filePath);
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs
index a343fa9a..6211ee46 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs
@@ -26,6 +26,11 @@ namespace YooAsset
///
public long SizeBytes;
+ ///
+ /// 名字样式
+ ///
+ public byte NameStyle;
+
///
/// 资源包的分类标签
///
@@ -52,14 +57,55 @@ namespace YooAsset
///
public bool IsRawFile { private set; get; }
+ ///
+ /// 文件名称
+ ///
+ public string FileName
+ {
+ get
+ {
+ if (_fileName != null)
+ return _fileName;
+
+ if (NameStyle == 1)
+ {
+ _fileName = Hash;
+ }
+ else if (NameStyle == 2)
+ {
+ string tempFileExtension = System.IO.Path.GetExtension(BundleName);
+ _fileName = $"{Hash}{tempFileExtension}";
+ }
+ else if (NameStyle == 3)
+ {
+ string tempFileExtension = System.IO.Path.GetExtension(BundleName);
+ string tempBundleName = BundleName.Replace('/', '_').Replace(tempFileExtension, "");
+ _fileName = $"{tempBundleName}_{Hash}";
+ }
+ else if (NameStyle == 4)
+ {
+ string tempFileExtension = System.IO.Path.GetExtension(BundleName);
+ string tempBundleName = BundleName.Replace('/', '_').Replace(tempFileExtension, "");
+ _fileName = $"{tempBundleName}_{Hash}{tempFileExtension}";
+ }
+ else
+ {
+ throw new NotImplementedException();
+ }
+
+ return _fileName;
+ }
+ }
+ private string _fileName = null;
- public PatchBundle(string bundleName, string hash, string crc, long sizeBytes, string[] tags)
+ public PatchBundle(string bundleName, string hash, string crc, long sizeBytes, byte nameStyle, string[] tags)
{
BundleName = bundleName;
Hash = hash;
CRC = crc;
SizeBytes = sizeBytes;
+ NameStyle = nameStyle;
Tags = tags;
}
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
index 396a1bba..242c3ced 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
@@ -102,7 +102,7 @@ namespace YooAsset
bool used = false;
foreach (var patchBundle in LocalPatchManifest.BundleList)
{
- if (fileInfo.Name == patchBundle.Hash)
+ if (fileInfo.Name == patchBundle.FileName)
{
used = true;
break;
@@ -333,9 +333,8 @@ namespace YooAsset
}
public BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle)
{
- // 注意:资源版本号只用于确定下载路径
- string remoteMainURL = GetPatchDownloadMainURL(patchBundle.Hash);
- string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Hash);
+ string remoteMainURL = GetPatchDownloadMainURL(patchBundle.FileName);
+ string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.FileName);
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
return bundleInfo;
}
@@ -354,7 +353,7 @@ namespace YooAsset
public BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
{
// 注意:我们把流加载路径指定为远端下载地址
- string streamingPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash);
+ string streamingPath = PathHelper.MakeStreamingLoadPath(patchBundle.FileName);
streamingPath = PathHelper.ConvertToWWWPath(streamingPath);
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, streamingPath, streamingPath);
return bundleInfo;