diff --git a/Assets/YooAsset/Runtime/CacheSystem/Operations/Internal/FindCacheFilesOperation.cs b/Assets/YooAsset/Runtime/CacheSystem/Operations/Internal/FindCacheFilesOperation.cs index f6bd2ef..d98bd95 100644 --- a/Assets/YooAsset/Runtime/CacheSystem/Operations/Internal/FindCacheFilesOperation.cs +++ b/Assets/YooAsset/Runtime/CacheSystem/Operations/Internal/FindCacheFilesOperation.cs @@ -45,7 +45,7 @@ namespace YooAsset { // BundleFiles { - string rootPath = PersistentTools.GetCachedBundleFileFolderPath(_packageName); + string rootPath = PersistentTools.GetPersistent(_packageName).SandboxCacheBundleFilesRoot; DirectoryInfo rootDirectory = new DirectoryInfo(rootPath); if (rootDirectory.Exists) { @@ -56,7 +56,7 @@ namespace YooAsset // RawFiles { - string rootPath = PersistentTools.GetCachedRawFileFolderPath(_packageName); + string rootPath = PersistentTools.GetPersistent(_packageName).SandboxCacheRawFilesRoot; DirectoryInfo rootDirectory = new DirectoryInfo(rootPath); if (rootDirectory.Exists) { diff --git a/Assets/YooAsset/Runtime/CacheSystem/Persistent.cs b/Assets/YooAsset/Runtime/CacheSystem/Persistent.cs new file mode 100644 index 0000000..b4ab6a1 --- /dev/null +++ b/Assets/YooAsset/Runtime/CacheSystem/Persistent.cs @@ -0,0 +1,163 @@ +using System.IO; + +namespace YooAsset +{ + internal class Persistent + { + private readonly string _packageName; + + public string BuildinRoot { private set; get; } + public string BuildinPackageRoot { private set; get; } + + public string SandboxRoot { private set; get; } + public string SandboxPackageRoot { private set; get; } + public string SandboxCacheBundleFilesRoot { private set; get; } + public string SandboxCacheRawFilesRoot { private set; get; } + public string SandboxManifestFilesRoot { private set; get; } + public string SandboxAppFootPrintFilePath { private set; get; } + + + public Persistent(string packageName) + { + _packageName = packageName; + } + + /// + /// 重写根路径 + /// + public void OverwriteRootDirectory(string buildinRoot, string sandboxRoot) + { + if (string.IsNullOrEmpty(buildinRoot)) + BuildinRoot = CreateDefaultBuildinRoot(); + else + BuildinRoot = buildinRoot; + + if (string.IsNullOrEmpty(sandboxRoot)) + SandboxRoot = CreateDefaultSandboxRoot(); + else + SandboxRoot = sandboxRoot; + + BuildinPackageRoot = PathUtility.Combine(BuildinRoot, _packageName); + SandboxPackageRoot = PathUtility.Combine(SandboxRoot, _packageName); + SandboxCacheBundleFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.CachedBundleFileFolder); + SandboxCacheRawFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.CachedRawFileFolder); + SandboxManifestFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.ManifestFolderName); + SandboxAppFootPrintFilePath = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.AppFootPrintFileName); + } + private static string CreateDefaultBuildinRoot() + { + return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettings.DefaultYooFolderName); + } + private static string CreateDefaultSandboxRoot() + { +#if UNITY_EDITOR + // 注意:为了方便调试查看,编辑器下把存储目录放到项目里。 + string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath); + projectPath = PathUtility.RegularPath(projectPath); + return PathUtility.Combine(projectPath, YooAssetSettings.DefaultYooFolderName); +#elif UNITY_STANDALONE + return PathUtility.Combine(UnityEngine.Application.dataPath, YooAssetSettings.DefaultYooFolderName); +#else + return PathUtility.Combine(UnityEngine.Application.persistentDataPath, YooAssetSettings.DefaultYooFolderName); +#endif + } + + + /// + /// 删除沙盒里的包裹目录 + /// + public void DeleteSandboxPackageFolder() + { + if (Directory.Exists(SandboxPackageRoot)) + Directory.Delete(SandboxPackageRoot, true); + } + + /// + /// 删除沙盒内的缓存文件夹 + /// + public void DeleteSandboxCacheFilesFolder() + { + // CacheBundleFiles + if (Directory.Exists(SandboxCacheBundleFilesRoot)) + Directory.Delete(SandboxCacheBundleFilesRoot, true); + + // CacheRawFiles + if (Directory.Exists(SandboxCacheRawFilesRoot)) + Directory.Delete(SandboxCacheRawFilesRoot, true); + } + + /// + /// 删除沙盒内的清单文件夹 + /// + public void DeleteSandboxManifestFilesFolder() + { + if (Directory.Exists(SandboxManifestFilesRoot)) + Directory.Delete(SandboxManifestFilesRoot, true); + } + + + /// + /// 获取沙盒内包裹的清单文件的路径 + /// + public string GetSandboxPackageManifestFilePath(string packageVersion) + { + string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, packageVersion); + return PathUtility.Combine(SandboxManifestFilesRoot, fileName); + } + + /// + /// 获取沙盒内包裹的哈希文件的路径 + /// + public string GetSandboxPackageHashFilePath(string packageVersion) + { + string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, packageVersion); + return PathUtility.Combine(SandboxManifestFilesRoot, fileName); + } + + /// + /// 获取沙盒内包裹的版本文件的路径 + /// + public string GetSandboxPackageVersionFilePath() + { + string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName); + return PathUtility.Combine(SandboxManifestFilesRoot, fileName); + } + + /// + /// 保存沙盒内默认的包裹版本 + /// + public void SaveSandboxPackageVersionFile(string version) + { + string filePath = GetSandboxPackageVersionFilePath(); + FileUtility.WriteAllText(filePath, version); + } + + + /// + /// 获取APP内包裹的清单文件的路径 + /// + public string GetBuildinPackageManifestFilePath(string packageVersion) + { + string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, packageVersion); + return PathUtility.Combine(BuildinPackageRoot, fileName); + } + + /// + /// 获取APP内包裹的哈希文件的路径 + /// + public string GetBuildinPackageHashFilePath(string packageVersion) + { + string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, packageVersion); + return PathUtility.Combine(BuildinPackageRoot, fileName); + } + + /// + /// 获取APP内包裹的版本文件的路径 + /// + public string GetBuildinPackageVersionFilePath() + { + string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName); + return PathUtility.Combine(BuildinPackageRoot, fileName); + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/CacheSystem/Persistent.cs.meta b/Assets/YooAsset/Runtime/CacheSystem/Persistent.cs.meta new file mode 100644 index 0000000..0ba0c6d --- /dev/null +++ b/Assets/YooAsset/Runtime/CacheSystem/Persistent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 62ee5fd2821fe85488efff3f8242b703 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/CacheSystem/PersistentTools.cs b/Assets/YooAsset/Runtime/CacheSystem/PersistentTools.cs index 25fbcf9..a0c2fb6 100644 --- a/Assets/YooAsset/Runtime/CacheSystem/PersistentTools.cs +++ b/Assets/YooAsset/Runtime/CacheSystem/PersistentTools.cs @@ -3,92 +3,31 @@ using System.Collections.Generic; namespace YooAsset { - internal static class PersistentTools + internal class PersistentTools { - private const string SandboxFolderName = "Sandbox"; - private const string CacheFolderName = "CacheFiles"; - private const string CachedBundleFileFolder = "BundleFiles"; - private const string CachedRawFileFolder = "RawFiles"; - private const string ManifestFolderName = "ManifestFiles"; - private const string AppFootPrintFileName = "ApplicationFootPrint.bytes"; - - private static string _buildinPath; - private static string _sandboxPath; - + private static readonly Dictionary _persitentDic = new Dictionary(100); /// - /// 重写内置跟路径 + /// 获取包裹的持久化类 /// - public static void OverwriteBuildinPath(string path) + public static Persistent GetPersistent(string packageName) { - _buildinPath = path; + if (_persitentDic.ContainsKey(packageName) == false) + throw new System.Exception("Should never get here !"); + return _persitentDic[packageName]; } /// - /// 重写沙盒跟路径 + /// 获取或创建包裹的持久化类 /// - public static void OverwriteSandboxPath(string path) + public static Persistent GetOrCreatePersistent(string packageName) { - _sandboxPath = path; - } - - /// - /// 获取沙盒文件夹路径 - /// - public static string GetPersistentRootPath() - { -#if UNITY_EDITOR - // 注意:为了方便调试查看,编辑器下把存储目录放到项目里 - if (string.IsNullOrEmpty(_sandboxPath)) + if (_persitentDic.ContainsKey(packageName) == false) { - string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath); - projectPath = PathUtility.RegularPath(projectPath); - _sandboxPath = PathUtility.Combine(projectPath, SandboxFolderName); + Persistent persistent = new Persistent(packageName); + _persitentDic.Add(packageName, persistent); } -#elif UNITY_STANDALONE - if (string.IsNullOrEmpty(_sandboxPath)) - { - _sandboxPath = PathUtility.Combine(UnityEngine.Application.dataPath, SandboxFolderName); - } -#else - if (string.IsNullOrEmpty(_sandboxPath)) - { - _sandboxPath = PathUtility.Combine(UnityEngine.Application.persistentDataPath, SandboxFolderName); - } -#endif - - return _sandboxPath; - } - - /// - /// 获取基于流文件夹的加载路径 - /// - public static string MakeStreamingLoadPath(string path) - { - if (string.IsNullOrEmpty(_buildinPath)) - { - _buildinPath = PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettings.StreamingAssetsBuildinFolder); - } - return PathUtility.Combine(_buildinPath, path); - } - - /// - /// 获取基于沙盒文件夹的加载路径 - /// - public static string MakePersistentLoadPath(string path) - { - string root = GetPersistentRootPath(); - return PathUtility.Combine(root, path); - } - public static string MakePersistentLoadPath(string path1, string path2) - { - string root = GetPersistentRootPath(); - return PathUtility.Combine(root, path1, path2); - } - public static string MakePersistentLoadPath(string path1, string path2, string path3) - { - string root = GetPersistentRootPath(); - return PathUtility.Combine(root, path1, path2, path3); + return _persitentDic[packageName]; } /// @@ -108,109 +47,5 @@ namespace YooAsset return path; #endif } - - - /// - /// 删除沙盒总目录 - /// - public static void DeleteSandbox() - { - string directoryPath = GetPersistentRootPath(); - if (Directory.Exists(directoryPath)) - Directory.Delete(directoryPath, true); - } - - /// - /// 删除沙盒内的缓存文件夹 - /// - public static void DeleteCacheFolder() - { - string root = MakePersistentLoadPath(CacheFolderName); - if (Directory.Exists(root)) - Directory.Delete(root, true); - } - - /// - /// 删除沙盒内的清单文件夹 - /// - public static void DeleteManifestFolder() - { - string root = MakePersistentLoadPath(ManifestFolderName); - if (Directory.Exists(root)) - Directory.Delete(root, true); - } - - - /// - /// 获取缓存的BundleFile文件夹路径 - /// - private readonly static Dictionary _cachedBundleFileFolder = new Dictionary(100); - public static string GetCachedBundleFileFolderPath(string packageName) - { - if (_cachedBundleFileFolder.TryGetValue(packageName, out string value) == false) - { - value = MakePersistentLoadPath(CacheFolderName, packageName, CachedBundleFileFolder); - _cachedBundleFileFolder.Add(packageName, value); - } - return value; - } - - /// - /// 获取缓存的RawFile文件夹路径 - /// - private readonly static Dictionary _cachedRawFileFolder = new Dictionary(100); - public static string GetCachedRawFileFolderPath(string packageName) - { - if (_cachedRawFileFolder.TryGetValue(packageName, out string value) == false) - { - value = MakePersistentLoadPath(CacheFolderName, packageName, CachedRawFileFolder); - _cachedRawFileFolder.Add(packageName, value); - } - return value; - } - - /// - /// 获取应用程序的水印文件路径 - /// - public static string GetAppFootPrintFilePath() - { - return MakePersistentLoadPath(AppFootPrintFileName); - } - - /// - /// 获取沙盒内清单文件的路径 - /// - public static string GetCacheManifestFilePath(string packageName, string packageVersion) - { - string fileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion); - return MakePersistentLoadPath(ManifestFolderName, fileName); - } - - /// - /// 获取沙盒内包裹的哈希文件的路径 - /// - public static string GetCachePackageHashFilePath(string packageName, string packageVersion) - { - string fileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion); - return MakePersistentLoadPath(ManifestFolderName, fileName); - } - - /// - /// 获取沙盒内包裹的版本文件的路径 - /// - public static string GetCachePackageVersionFilePath(string packageName) - { - string fileName = YooAssetSettingsData.GetPackageVersionFileName(packageName); - return MakePersistentLoadPath(ManifestFolderName, fileName); - } - - /// - /// 保存默认的包裹版本 - /// - public static void SaveCachePackageVersionFile(string packageName, string version) - { - string filePath = GetCachePackageVersionFilePath(packageName); - FileUtility.WriteAllText(filePath, version); - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/InitializationOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/InitializationOperation.cs index 32c2e66..66496ad 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/Operations/InitializationOperation.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/InitializationOperation.cs @@ -217,13 +217,13 @@ namespace YooAsset if (_steps == ESteps.CheckAppFootPrint) { var appFootPrint = new AppFootPrint(); - appFootPrint.Load(); + appFootPrint.Load(_packageName); // 如果水印发生变化,则说明覆盖安装后首次打开游戏 if (appFootPrint.IsDirty()) { - PersistentTools.DeleteManifestFolder(); - appFootPrint.Coverage(); + PersistentTools.GetPersistent(_packageName).DeleteSandboxManifestFilesFolder(); + appFootPrint.Coverage(_packageName); YooLogger.Log("Delete manifest files when application foot print dirty !"); } _steps = ESteps.QueryCachePackageVersion; @@ -374,16 +374,16 @@ namespace YooAsset /// /// 读取应用程序水印 /// - public void Load() + public void Load(string packageName) { - string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath(); + string footPrintFilePath = PersistentTools.GetPersistent(packageName).SandboxAppFootPrintFilePath; if (File.Exists(footPrintFilePath)) { _footPrint = FileUtility.ReadAllText(footPrintFilePath); } else { - Coverage(); + Coverage(packageName); } } @@ -402,14 +402,14 @@ namespace YooAsset /// /// 覆盖掉水印 /// - public void Coverage() + public void Coverage(string packageName) { #if UNITY_EDITOR _footPrint = Application.version; #else _footPrint = Application.buildGUID; #endif - string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath(); + string footPrintFilePath = PersistentTools.GetPersistent(packageName).SandboxAppFootPrintFilePath; FileUtility.WriteAllText(footPrintFilePath, _footPrint); YooLogger.Log($"Save application foot print : {_footPrint}"); } diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/DownloadManifestOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/DownloadManifestOperation.cs index 27d3546..13469d1 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/DownloadManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/DownloadManifestOperation.cs @@ -41,7 +41,7 @@ namespace YooAsset { if (_downloader1 == null) { - string savePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion); + string savePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion); string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion); string webURL = GetDownloadRequestURL(fileName); YooLogger.Log($"Beginning to download package hash file : {webURL}"); @@ -71,7 +71,7 @@ namespace YooAsset { if (_downloader2 == null) { - string savePath = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion); + string savePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageManifestFilePath(_packageVersion); string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion); string webURL = GetDownloadRequestURL(fileName); YooLogger.Log($"Beginning to download manifest file : {webURL}"); diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/LoadBuildinManifestOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/LoadBuildinManifestOperation.cs index 682aec9..0378bbb 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/LoadBuildinManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/LoadBuildinManifestOperation.cs @@ -41,8 +41,7 @@ namespace YooAsset { if (_downloader == null) { - string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion); - string filePath = PersistentTools.MakeStreamingLoadPath(fileName); + string filePath = PersistentTools.GetPersistent(_buildinPackageName).GetBuildinPackageManifestFilePath(_buildinPackageVersion); string url = PersistentTools.ConvertToWWWPath(filePath); _downloader = new UnityWebDataRequester(); _downloader.SendRequest(url); diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/LoadCacheManifestOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/LoadCacheManifestOperation.cs index dcfdb53..0ea054c 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/LoadCacheManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/LoadCacheManifestOperation.cs @@ -67,7 +67,7 @@ namespace YooAsset if (_steps == ESteps.VerifyFileHash) { - _manifestFilePath = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion); + _manifestFilePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageManifestFilePath(_packageVersion); if (File.Exists(_manifestFilePath) == false) { _steps = ESteps.Done; @@ -131,7 +131,7 @@ namespace YooAsset File.Delete(_manifestFilePath); } - string hashFilePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion); + string hashFilePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion); if (File.Exists(hashFilePath)) { File.Delete(hashFilePath); diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/QueryBuildinPackageVersionOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/QueryBuildinPackageVersionOperation.cs index be0d8ef..9c8687b 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/QueryBuildinPackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/QueryBuildinPackageVersionOperation.cs @@ -37,8 +37,7 @@ namespace YooAsset { if (_downloader == null) { - string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName); - string filePath = PersistentTools.MakeStreamingLoadPath(fileName); + string filePath = PersistentTools.GetPersistent(_packageName).GetBuildinPackageVersionFilePath(); string url = PersistentTools.ConvertToWWWPath(filePath); _downloader = new UnityWebDataRequester(); _downloader.SendRequest(url); diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/QueryCachePackageHashOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/QueryCachePackageHashOperation.cs index 62f00c5..5e1072c 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/QueryCachePackageHashOperation.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/QueryCachePackageHashOperation.cs @@ -37,7 +37,7 @@ namespace YooAsset if (_steps == ESteps.LoadCachePackageHashFile) { - string filePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion); + string filePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion); if (File.Exists(filePath) == false) { _steps = ESteps.Done; diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/QueryCachePackageVersionOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/QueryCachePackageVersionOperation.cs index d948c6a..fb231a4 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/QueryCachePackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/QueryCachePackageVersionOperation.cs @@ -35,7 +35,7 @@ namespace YooAsset if (_steps == ESteps.LoadCachePackageVersionFile) { - string filePath = PersistentTools.GetCachePackageVersionFilePath(_packageName); + string filePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageVersionFilePath(); if (File.Exists(filePath) == false) { _steps = ESteps.Done; diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/UnpackBuildinManifestOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/UnpackBuildinManifestOperation.cs index b000e4b..cba3b03 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/UnpackBuildinManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/UnpackBuildinManifestOperation.cs @@ -31,13 +31,13 @@ namespace YooAsset if (_steps == ESteps.None || _steps == ESteps.Done) return; - if(_steps == ESteps.UnpackManifestHashFile) + if (_steps == ESteps.UnpackManifestHashFile) { if (_downloader1 == null) { - string savePath = PersistentTools.GetCachePackageHashFilePath(_buildinPackageName, _buildinPackageVersion); - string fileName = YooAssetSettingsData.GetPackageHashFileName(_buildinPackageName, _buildinPackageVersion); - string filePath = PersistentTools.MakeStreamingLoadPath(fileName); + var persistent = PersistentTools.GetPersistent(_buildinPackageName); + string savePath = persistent.GetSandboxPackageHashFilePath(_buildinPackageVersion); + string filePath = persistent.GetBuildinPackageHashFilePath(_buildinPackageVersion); string url = PersistentTools.ConvertToWWWPath(filePath); _downloader1 = new UnityWebFileRequester(); _downloader1.SendRequest(url, savePath); @@ -64,9 +64,9 @@ namespace YooAsset { if (_downloader2 == null) { - string savePath = PersistentTools.GetCacheManifestFilePath(_buildinPackageName, _buildinPackageVersion); - string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion); - string filePath = PersistentTools.MakeStreamingLoadPath(fileName); + var persistent = PersistentTools.GetPersistent(_buildinPackageName); + string savePath = persistent.GetSandboxPackageManifestFilePath(_buildinPackageVersion); + string filePath = persistent.GetBuildinPackageManifestFilePath(_buildinPackageVersion); string url = PersistentTools.ConvertToWWWPath(filePath); _downloader2 = new UnityWebFileRequester(); _downloader2.SendRequest(url, savePath); diff --git a/Assets/YooAsset/Runtime/PackageSystem/PackageBundle.cs b/Assets/YooAsset/Runtime/PackageSystem/PackageBundle.cs index 60a9d8e..02addff 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/PackageBundle.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/PackageBundle.cs @@ -74,13 +74,13 @@ namespace YooAsset string folderName = FileHash.Substring(0, 2); if (IsRawFile) { - string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName); + string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheRawFilesRoot; _cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName); _cachedDataFilePath += _fileExtension; } else { - string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName); + string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheBundleFilesRoot; _cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName); } return _cachedDataFilePath; @@ -101,12 +101,12 @@ namespace YooAsset string folderName = FileHash.Substring(0, 2); if (IsRawFile) { - string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName); + string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheRawFilesRoot; _cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName); } else { - string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName); + string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheBundleFilesRoot; _cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName); } return _cachedInfoFilePath; @@ -140,7 +140,8 @@ namespace YooAsset if (string.IsNullOrEmpty(_streamingFilePath) == false) return _streamingFilePath; - _streamingFilePath = PersistentTools.MakeStreamingLoadPath(FileName); + string root = PersistentTools.GetPersistent(PackageName).BuildinPackageRoot; + _streamingFilePath = PathUtility.Combine(root, FileName); return _streamingFilePath; } } diff --git a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs index 627859d..e98912e 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs @@ -74,7 +74,9 @@ namespace YooAsset public void FlushManifestVersionFile() { if (_activeManifest != null) - PersistentTools.SaveCachePackageVersionFile(_packageName, _activeManifest.PackageVersion); + { + PersistentTools.GetPersistent(_packageName).SaveSandboxPackageVersionFile(_activeManifest.PackageVersion); + } } private bool IsBuildinPackageBundle(PackageBundle packageBundle) diff --git a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs index adc0564..69118b3 100644 --- a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs +++ b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs @@ -37,6 +37,31 @@ namespace YooAsset /// public const string CacheBundleInfoFileName = "__info"; + /// + /// 默认的YooAsset文件夹名称 + /// + public const string DefaultYooFolderName = "yoo"; + + /// + /// 缓存的资源文件的文件夹名称 + /// + public const string CachedBundleFileFolder = "CacheBundleFiles"; + + /// + /// 缓存的原生文件的文件夹名称 + /// + public const string CachedRawFileFolder = "CacheRawFiles"; + + /// + /// 缓存的清单文件的文件夹名称 + /// + public const string ManifestFolderName = "ManifestFiles"; + + /// + /// 记录应用程序版本的文件名称 + /// + public const string AppFootPrintFileName = "ApplicationFootPrint.bytes"; + /// /// 构建输出文件夹名称 @@ -47,10 +72,5 @@ namespace YooAsset /// 构建输出的报告文件 /// public const string ReportFileName = "BuildReport"; - - /// - /// 内置资源目录名称 - /// - public const string StreamingAssetsBuildinFolder = "BuildinFiles"; } } \ No newline at end of file