diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
index 5914d58..f7b9782 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
@@ -130,11 +130,11 @@ namespace YooAsset
///
/// 异步加载原生文件
///
- public static RawFileOperation LoadRawFileAsync(string assetPath, string savePath)
+ public static RawFileOperation LoadRawFileAsync(string assetPath, string copyPath)
{
string bundleName = BundleServices.GetBundleName(assetPath);
BundleInfo bundleInfo = BundleServices.GetBundleInfo(bundleName);
- RawFileOperation operation = new RawFileOperation(bundleInfo, savePath);
+ RawFileOperation operation = new RawFileOperation(bundleInfo, copyPath);
OperationSystem.ProcessOperaiton(operation);
return operation;
}
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs
index d1e449e..13b6790 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs
@@ -18,6 +18,7 @@ namespace YooAsset
}
private ESteps _steps = ESteps.None;
+ private string _fileLoadPath;
private bool _isWaitForAsyncComplete = false;
private bool _isShowWaitForAsyncError = false;
private DownloaderBase _downloader;
@@ -38,18 +39,32 @@ namespace YooAsset
if (_steps == ESteps.None)
{
- // 检测加载地址是否为空
- if (string.IsNullOrEmpty(BundleFileInfo.LocalPath))
+ if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.None)
{
_steps = ESteps.Done;
Status = EStatus.Failed;
return;
}
- if (string.IsNullOrEmpty(BundleFileInfo.RemoteMainURL))
- _steps = ESteps.LoadFile;
- else
+ if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
+ {
_steps = ESteps.Download;
+ _fileLoadPath = BundleFileInfo.GetCacheLoadPath();
+ }
+ else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
+ {
+ _steps = ESteps.LoadFile;
+ _fileLoadPath = BundleFileInfo.GetStreamingLoadPath();
+ }
+ else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
+ {
+ _steps = ESteps.LoadFile;
+ _fileLoadPath = BundleFileInfo.GetCacheLoadPath();
+ }
+ else
+ {
+ throw new System.NotImplementedException(BundleFileInfo.LoadMode.ToString());
+ }
}
// 1. 从服务器下载
@@ -83,9 +98,9 @@ namespace YooAsset
{
#if UNITY_EDITOR
// 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
- if (System.IO.File.Exists(BundleFileInfo.LocalPath) == false)
+ if (System.IO.File.Exists(_fileLoadPath) == false)
{
- YooLogger.Warning($"Not found assetBundle file : {BundleFileInfo.LocalPath}");
+ YooLogger.Warning($"Not found assetBundle file : {_fileLoadPath}");
_steps = ESteps.Done;
Status = EStatus.Failed;
return;
@@ -96,20 +111,20 @@ namespace YooAsset
if (BundleFileInfo.IsEncrypted)
{
if (AssetSystem.DecryptionServices == null)
- throw new Exception($"{nameof(AssetBundleFileLoader)} need IDecryptServices : {BundleFileInfo.BundleName}");
+ throw new Exception($"{nameof(AssetBundleFileLoader)} need {nameof(IDecryptionServices)} : {BundleFileInfo.BundleName}");
ulong offset = AssetSystem.DecryptionServices.GetFileOffset(BundleFileInfo);
if (_isWaitForAsyncComplete)
- CacheBundle = AssetBundle.LoadFromFile(BundleFileInfo.LocalPath, 0, offset);
+ CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath, 0, offset);
else
- _cacheRequest = AssetBundle.LoadFromFileAsync(BundleFileInfo.LocalPath, 0, offset);
+ _cacheRequest = AssetBundle.LoadFromFileAsync(_fileLoadPath, 0, offset);
}
else
{
if (_isWaitForAsyncComplete)
- CacheBundle = AssetBundle.LoadFromFile(BundleFileInfo.LocalPath);
+ CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath);
else
- _cacheRequest = AssetBundle.LoadFromFileAsync(BundleFileInfo.LocalPath);
+ _cacheRequest = AssetBundle.LoadFromFileAsync(_fileLoadPath);
}
_steps = ESteps.CheckFile;
}
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs
index a3df0e4..8eb8d8c 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs
@@ -37,19 +37,22 @@ namespace YooAsset
if (_steps == ESteps.None)
{
- // 检测加载地址是否为空
- if (string.IsNullOrEmpty(BundleFileInfo.LocalPath))
+ if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.None)
{
_steps = ESteps.Done;
Status = EStatus.Failed;
return;
}
- if (string.IsNullOrEmpty(BundleFileInfo.RemoteMainURL))
- _webURL = BundleFileInfo.LocalPath;
+ if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
+ {
+ _steps = ESteps.LoadFile;
+ _webURL = BundleFileInfo.GetStreamingLoadPath();
+ }
else
- _webURL = BundleFileInfo.RemoteMainURL;
- _steps = ESteps.LoadFile;
+ {
+ throw new System.NotImplementedException(BundleFileInfo.LoadMode.ToString());
+ }
}
// 1. 从服务器或缓存中获取AssetBundle文件
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs b/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs
index e5f11f0..0fea447 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs
@@ -10,31 +10,40 @@ namespace YooAsset
Prepare,
DownloadFromWeb,
CheckDownloadFromWeb,
- CheckFile,
DownloadFromApk,
CheckDownloadFromApk,
+ CheckAndCopyFile,
Done,
}
private readonly BundleInfo _bundleInfo;
- private readonly string _savePath;
private ESteps _steps = ESteps.None;
private DownloaderBase _downloader;
private UnityWebFileRequester _fileRequester;
///
- /// 原生文件的存储路径
+ /// 原生文件的拷贝路径
///
- public string SavePath
+ public string CopyPath { private set; get; }
+
+ ///
+ /// 原生文件的缓存路径
+ ///
+ public string CachePath
{
- get { return _savePath; }
+ get
+ {
+ if (_bundleInfo == null)
+ return string.Empty;
+ return _bundleInfo.GetCacheLoadPath();
+ }
}
- internal RawFileOperation(BundleInfo bundleInfo, string savePath)
+ internal RawFileOperation(BundleInfo bundleInfo, string copyPath)
{
_bundleInfo = bundleInfo;
- _savePath = savePath;
+ CopyPath = copyPath;
}
internal override void Start()
{
@@ -48,19 +57,30 @@ namespace YooAsset
// 1. 准备工作
if (_steps == ESteps.Prepare)
{
- // 检测加载地址是否为空
- if (string.IsNullOrEmpty(_bundleInfo.LocalPath))
+ if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.None)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = "Local path is null or empty.";
+ Error = $"Bundle info is invalid : {_bundleInfo.BundleName}";
return;
}
- if (string.IsNullOrEmpty(_bundleInfo.RemoteMainURL))
- _steps = ESteps.CheckFile;
- else
+ if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
+ {
_steps = ESteps.DownloadFromWeb;
+ }
+ else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
+ {
+ _steps = ESteps.DownloadFromApk;
+ }
+ else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
+ {
+ _steps = ESteps.CheckAndCopyFile;
+ }
+ else
+ {
+ throw new System.NotImplementedException(_bundleInfo.LoadMode.ToString());
+ }
}
// 2. 从服务器下载
@@ -85,65 +105,20 @@ namespace YooAsset
}
else
{
- // 注意:当文件更新之后,需要删除旧文件
- if (File.Exists(_savePath))
- File.Delete(_savePath);
- _steps = ESteps.CheckFile;
+ _steps = ESteps.CheckAndCopyFile;
}
}
- // 4. 检测文件
- if (_steps == ESteps.CheckFile)
- {
- // 注意:如果原生文件已经存在,则验证其完整性
- if (File.Exists(_savePath))
- {
- bool result = DownloadSystem.CheckContentIntegrity(_savePath, _bundleInfo.SizeBytes, _bundleInfo.CRC);
- if (result)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeed;
- return;
- }
- else
- {
- File.Delete(_savePath);
- }
- }
-
- if (_bundleInfo.IsBuildinJarFile())
- {
- _steps = ESteps.DownloadFromApk;
- }
- else
- {
- try
- {
- File.Copy(_bundleInfo.LocalPath, _savePath, true);
- }
- catch (System.Exception e)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = e.ToString();
- return;
- }
-
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeed;
- }
- }
-
- // 5. 从APK拷贝文件
+ // 4. 从APK拷贝文件
if (_steps == ESteps.DownloadFromApk)
{
- string downloadURL = PathHelper.ConvertToWWWPath(_bundleInfo.LocalPath);
+ string downloadURL = PathHelper.ConvertToWWWPath(_bundleInfo.GetStreamingLoadPath());
_fileRequester = new UnityWebFileRequester();
- _fileRequester.SendRequest(downloadURL, _savePath);
+ _fileRequester.SendRequest(downloadURL, _bundleInfo.GetCacheLoadPath());
_steps = ESteps.CheckDownloadFromApk;
}
- // 6. 检测APK拷贝文件结果
+ // 5. 检测APK拷贝文件结果
if (_steps == ESteps.CheckDownloadFromApk)
{
if (_fileRequester.IsDone() == false)
@@ -157,11 +132,51 @@ namespace YooAsset
}
else
{
+ _steps = ESteps.CheckAndCopyFile;
+ }
+ _fileRequester.Dispose();
+ }
+
+ // 6. 检测并拷贝原生文件
+ if (_steps == ESteps.CheckAndCopyFile)
+ {
+ // 如果不需要保存文件
+ if (string.IsNullOrEmpty(CopyPath))
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeed;
+ return;
+ }
+
+ // 如果原生文件已经存在,则验证其完整性
+ if (File.Exists(CopyPath))
+ {
+ bool result = DownloadSystem.CheckContentIntegrity(CopyPath, _bundleInfo.SizeBytes, _bundleInfo.CRC);
+ if (result)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeed;
+ return;
+ }
+ else
+ {
+ File.Delete(CopyPath);
+ }
+ }
+
+ try
+ {
+ FileUtility.CreateFileDirectory(CopyPath);
+ File.Copy(_bundleInfo.GetCacheLoadPath(), CopyPath, true);
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
-
- _fileRequester.Dispose();
+ catch (System.Exception e)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = e.ToString();
+ }
}
}
@@ -170,9 +185,10 @@ namespace YooAsset
///
public byte[] GetFileData()
{
- if (File.Exists(_savePath) == false)
+ string cachePath = _bundleInfo.GetCacheLoadPath();
+ if (File.Exists(cachePath) == false)
return null;
- return File.ReadAllBytes(_savePath);
+ return File.ReadAllBytes(cachePath);
}
///
@@ -180,9 +196,10 @@ namespace YooAsset
///
public string GetFileText()
{
- if (File.Exists(_savePath) == false)
+ string cachePath = _bundleInfo.GetCacheLoadPath();
+ if (File.Exists(cachePath) == false)
return string.Empty;
- return File.ReadAllText(_savePath, System.Text.Encoding.UTF8);
+ return File.ReadAllText(cachePath, System.Text.Encoding.UTF8);
}
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs
index 8dc6d18..2b10ad7 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs
@@ -84,7 +84,7 @@ namespace YooAsset
// 创建新的下载器
{
YooLogger.Log($"Beginning to download file : {bundleInfo.BundleName} URL : {bundleInfo.RemoteMainURL}");
- FileUtility.CreateFileDirectory(bundleInfo.LocalPath);
+ FileUtility.CreateFileDirectory(bundleInfo.GetCacheLoadPath());
DownloaderBase newDownloader;
if (bundleInfo.SizeBytes >= _breakpointResumeFileSize)
newDownloader = new HttpDownloader(bundleInfo);
@@ -146,7 +146,7 @@ namespace YooAsset
// 验证文件完整性
public static bool CheckContentIntegrity(BundleInfo bundleInfo)
{
- return CheckContentIntegrity(bundleInfo.LocalPath, bundleInfo.SizeBytes, bundleInfo.CRC);
+ return CheckContentIntegrity(bundleInfo.GetCacheLoadPath(), bundleInfo.SizeBytes, bundleInfo.CRC);
}
public static bool CheckContentIntegrity(PatchBundle patchBundle)
{
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs
index 664e9e0..bdd34bd 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs
@@ -50,9 +50,6 @@ namespace YooAsset
}
public void SendRequest(int failedTryAgain, int timeout)
{
- if (string.IsNullOrEmpty(_bundleInfo.LocalPath))
- throw new System.ArgumentNullException();
-
if (_steps == ESteps.None)
{
_failedTryAgain = failedTryAgain;
@@ -62,7 +59,7 @@ namespace YooAsset
}
public abstract void Update();
public abstract void Abort();
-
+
///
/// 获取网络请求地址
///
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs
index 8b212f2..e8edeae 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs
@@ -42,7 +42,7 @@ namespace YooAsset
_requestURL = GetRequestURL();
_webRequest = new UnityWebRequest(_requestURL, UnityWebRequest.kHttpVerbGET);
- DownloadHandlerFile handler = new DownloadHandlerFile(_bundleInfo.LocalPath);
+ DownloadHandlerFile handler = new DownloadHandlerFile(_bundleInfo.GetCacheLoadPath());
handler.removeFileOnAbort = true;
_webRequest.downloadHandler = handler;
_webRequest.disposeDownloadHandlerOnDispose = true;
@@ -97,8 +97,9 @@ namespace YooAsset
{
ReportError();
- if (File.Exists(_bundleInfo.LocalPath))
- File.Delete(_bundleInfo.LocalPath);
+ string cacheFilePath = _bundleInfo.GetCacheLoadPath();
+ if (File.Exists(cacheFilePath))
+ File.Delete(cacheFilePath);
// 失败后重新尝试
if (_failedTryAgain > 0)
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/HttpDownloader.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/HttpDownloader.cs
index 7f46fe7..a7c3a00 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/HttpDownloader.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/HttpDownloader.cs
@@ -197,7 +197,7 @@ namespace YooAsset
_requestURL = GetRequestURL();
_threadDownloader = new ThreadDownloader();
- _threadDownloader.Run(_requestURL, _bundleInfo.LocalPath, _bundleInfo.Hash, _bundleInfo.CRC, _bundleInfo.SizeBytes, _timeout);
+ _threadDownloader.Run(_requestURL, _bundleInfo.GetCacheLoadPath(), _bundleInfo.Hash, _bundleInfo.CRC, _bundleInfo.SizeBytes, _timeout);
_steps = ESteps.CheckDownload;
}
diff --git a/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs b/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs
index 3160aee..8b5360b 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs
@@ -3,18 +3,25 @@ namespace YooAsset
{
public class BundleInfo
{
+ internal enum ELoadMode
+ {
+ None,
+ LoadFromStreaming,
+ LoadFromCache,
+ LoadFromRemote,
+ }
+
private readonly PatchBundle _patchBundle;
-
+ internal readonly ELoadMode LoadMode;
+
+ private string _streamingPath;
+ private string _cachePath;
+
///
/// 资源包名称
///
public string BundleName { private set; get; }
- ///
- /// 本地存储的路径
- ///
- public string LocalPath { private set; get; }
-
///
/// 远端下载地址
///
@@ -96,30 +103,57 @@ namespace YooAsset
}
+ ///
+ /// 获取流文件夹的加载路径
+ ///
+ public string GetStreamingLoadPath()
+ {
+ if (_patchBundle == null)
+ return string.Empty;
+
+ if (string.IsNullOrEmpty(_streamingPath))
+ _streamingPath = PathHelper.MakeStreamingLoadPath(_patchBundle.Hash);
+ return _streamingPath;
+ }
+
+ ///
+ /// 获取缓存文件夹的加载路径
+ ///
+ public string GetCacheLoadPath()
+ {
+ if (_patchBundle == null)
+ return string.Empty;
+
+ if (string.IsNullOrEmpty(_cachePath))
+ _cachePath = SandboxHelper.MakeSandboxCacheFilePath(_patchBundle.Hash);
+ return _cachePath;
+ }
+
+
private BundleInfo()
{
}
- internal BundleInfo(PatchBundle patchBundle, string localPath, string mainURL, string fallbackURL)
+ internal BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string mainURL, string fallbackURL)
{
_patchBundle = patchBundle;
+ LoadMode = loadMode;
BundleName = patchBundle.BundleName;
- LocalPath = localPath;
RemoteMainURL = mainURL;
RemoteFallbackURL = fallbackURL;
}
- internal BundleInfo(PatchBundle patchBundle, string localPath)
+ internal BundleInfo(PatchBundle patchBundle, ELoadMode loadMode)
{
_patchBundle = patchBundle;
+ LoadMode = loadMode;
BundleName = patchBundle.BundleName;
- LocalPath = localPath;
RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty;
}
- internal BundleInfo(string bundleName, string localPath)
+ internal BundleInfo(string bundleName)
{
_patchBundle = null;
+ LoadMode = ELoadMode.None;
BundleName = bundleName;
- LocalPath = localPath;
RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty;
}
@@ -127,9 +161,9 @@ namespace YooAsset
///
/// 是否为JAR包内文件
///
- public bool IsBuildinJarFile()
+ public static bool IsBuildinJarFile(string streamingPath)
{
- return LocalPath.StartsWith("jar:");
+ return streamingPath.StartsWith("jar:");
}
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorPlayModeImpl.cs
index 66ddf8d..36c0cb0 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorPlayModeImpl.cs
@@ -28,7 +28,7 @@ namespace YooAsset
BundleInfo IBundleServices.GetBundleInfo(string bundleName)
{
YooLogger.Warning($"Editor play mode can not get bundle info.");
- BundleInfo bundleInfo = new BundleInfo(bundleName, bundleName);
+ BundleInfo bundleInfo = new BundleInfo(bundleName);
return bundleInfo;
}
string IBundleServices.GetBundleName(string assetPath)
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
index 1da006c..c8482e7 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
@@ -196,10 +196,9 @@ namespace YooAsset
private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle)
{
// 注意:资源版本号只用于确定下载路径
- string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string remoteMainURL = GetPatchDownloadMainURL(patchBundle.Hash);
string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Hash);
- BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, remoteMainURL, remoteFallbackURL);
+ BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
return bundleInfo;
}
@@ -207,36 +206,34 @@ namespace YooAsset
BundleInfo IBundleServices.GetBundleInfo(string bundleName)
{
if (string.IsNullOrEmpty(bundleName))
- return new BundleInfo(string.Empty, string.Empty);
+ return new BundleInfo(string.Empty);
if (LocalPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
{
+ // 查询沙盒资源
+ if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
+ {
+ BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromCache);
+ return bundleInfo;
+ }
+
// 查询APP资源
if (AppPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle appPatchBundle))
{
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
{
- string appLoadPath = PathHelper.MakeStreamingLoadPath(appPatchBundle.Hash);
- BundleInfo bundleInfo = new BundleInfo(appPatchBundle, appLoadPath);
+ BundleInfo bundleInfo = new BundleInfo(appPatchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
return bundleInfo;
}
}
- // 查询沙盒资源
- if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
- {
- string sandboxLoadPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
- BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxLoadPath);
- return bundleInfo;
- }
-
// 从服务端下载
return ConvertToDownloadInfo(patchBundle);
}
else
{
YooLogger.Warning($"Not found bundle in patch manifest : {bundleName}");
- BundleInfo bundleInfo = new BundleInfo(bundleName, string.Empty);
+ BundleInfo bundleInfo = new BundleInfo(bundleName);
return bundleInfo;
}
}
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
index 9453c39..73b0bc2 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
@@ -42,18 +42,17 @@ namespace YooAsset
BundleInfo IBundleServices.GetBundleInfo(string bundleName)
{
if (string.IsNullOrEmpty(bundleName))
- return new BundleInfo(string.Empty, string.Empty);
+ return new BundleInfo(string.Empty);
if (AppPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
{
- string localPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash);
- BundleInfo bundleInfo = new BundleInfo(patchBundle, localPath);
+ BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
return bundleInfo;
}
else
{
YooLogger.Warning($"Not found bundle in patch manifest : {bundleName}");
- BundleInfo bundleInfo = new BundleInfo(bundleName, string.Empty);
+ BundleInfo bundleInfo = new BundleInfo(bundleName);
return bundleInfo;
}
}
diff --git a/Assets/YooAsset/Runtime/Utility/YooHelper.cs b/Assets/YooAsset/Runtime/Utility/YooHelper.cs
index f7f8a56..630979c 100644
--- a/Assets/YooAsset/Runtime/Utility/YooHelper.cs
+++ b/Assets/YooAsset/Runtime/Utility/YooHelper.cs
@@ -150,6 +150,7 @@ namespace YooAsset
///
public static List GetUnpackListByTags(PatchManifest appPatchManifest, string[] tags)
{
+ // 注意:离线运行模式也依赖下面逻辑,所以判断沙盒内文件是否存在不能通过缓存系统去验证。
List downloadList = new List(1000);
foreach (var patchBundle in appPatchManifest.BundleList)
{
@@ -162,19 +163,11 @@ namespace YooAsset
if (patchBundle.IsBuildin == false)
continue;
- // 如果是纯内置资源
- if (patchBundle.IsPureBuildin())
+ // 查询DLC资源
+ if (patchBundle.HasTag(tags))
{
downloadList.Add(patchBundle);
}
- else
- {
- // 查询DLC资源
- if (patchBundle.HasTag(tags))
- {
- downloadList.Add(patchBundle);
- }
- }
}
return ConvertToUnpackList(downloadList);
@@ -191,9 +184,10 @@ namespace YooAsset
}
private static BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
{
- string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
- string streamingLoadPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash);
- BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, streamingLoadPath, streamingLoadPath);
+ // 注意:我们把流加载路径指定为远端下载地址
+ string streamingPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash);
+ streamingPath = PathHelper.ConvertToWWWPath(streamingPath);
+ BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, streamingPath, streamingPath);
return bundleInfo;
}
}
diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs
index a4eac82..ea18703 100644
--- a/Assets/YooAsset/Runtime/YooAssets.cs
+++ b/Assets/YooAsset/Runtime/YooAssets.cs
@@ -364,10 +364,12 @@ namespace YooAsset
///
/// 异步加载原生文件
///
- public static RawFileOperation LoadRawFileAsync(string location, string savePath)
+ /// 资源的定位地址
+ /// 拷贝路径
+ public static RawFileOperation LoadRawFileAsync(string location, string copyPath = null)
{
string assetPath = _locationServices.ConvertLocationToAssetPath(_playMode, location);
- return AssetSystem.LoadRawFileAsync(assetPath, savePath);
+ return AssetSystem.LoadRawFileAsync(assetPath, copyPath);
}
@@ -375,7 +377,7 @@ namespace YooAsset
/// 同步加载资源对象
///
/// 资源类型
- /// 资源对象相对路径
+ /// 资源的定位地址
public static AssetOperationHandle LoadAssetSync(string location) where TObject : class
{
return LoadAssetInternal(location, typeof(TObject), true);
@@ -384,7 +386,7 @@ namespace YooAsset
///
/// 同步加载资源对象
///
- /// 资源对象相对路径
+ /// 资源的定位地址
/// 资源类型
public static AssetOperationHandle LoadAssetSync(string location, System.Type type)
{
@@ -395,7 +397,7 @@ namespace YooAsset
/// 同步加载子资源对象
///
/// 资源类型
- /// 资源对象相对路径
+ /// 资源的定位地址
public static SubAssetsOperationHandle LoadSubAssetsSync(string location)
{
return LoadSubAssetsInternal(location, typeof(TObject), true);
@@ -404,7 +406,7 @@ namespace YooAsset
///
/// 同步加载子资源对象
///
- /// 资源对象相对路径
+ /// 资源的定位地址
/// 子对象类型
public static SubAssetsOperationHandle LoadSubAssetsSync(string location, System.Type type)
{
@@ -416,7 +418,7 @@ namespace YooAsset
/// 异步加载资源对象
///
/// 资源类型
- /// 资源对象相对路径
+ /// 资源的定位地址
public static AssetOperationHandle LoadAssetAsync(string location)
{
return LoadAssetInternal(location, typeof(TObject), false);
@@ -425,7 +427,7 @@ namespace YooAsset
///
/// 异步加载资源对象
///
- /// 资源对象相对路径
+ /// 资源的定位地址
/// 资源类型
public static AssetOperationHandle LoadAssetAsync(string location, System.Type type)
{
@@ -436,7 +438,7 @@ namespace YooAsset
/// 异步加载子资源对象
///
/// 资源类型
- /// 资源对象相对路径
+ /// 资源的定位地址
public static SubAssetsOperationHandle LoadSubAssetsAsync(string location)
{
return LoadSubAssetsInternal(location, typeof(TObject), false);
@@ -445,7 +447,7 @@ namespace YooAsset
///
/// 异步加载子资源对象
///
- /// 资源对象相对路径
+ /// 资源的定位地址
/// 子对象类型
public static SubAssetsOperationHandle LoadSubAssetsAsync(string location, System.Type type)
{