From 1f07411dde9a80d881b14a105487aeaeed9b55b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Tue, 17 Dec 2024 15:27:36 +0800 Subject: [PATCH] fix #293 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Default Yoo Folder Name 可配空 --- .../AssetBundleBuilderHelper.cs | 2 +- .../FileSystem/CacheSystem/CacheHelper.cs | 25 ---- .../CacheSystem/CacheHelper.cs.meta | 11 -- .../DefaultBuildinFileSystem.cs | 23 ++-- .../DefaultBuildinFileSystemBuild.cs | 7 +- .../Operation/DBFSInitializeOperation.cs | 3 +- .../LoadBuildinCatalogFileOperation.cs | 2 +- .../DefaultCacheFileSystem.cs | 12 +- .../DefaultWebServerFileSystem.cs | 14 +-- .../Operation/DWSFSInitializeOperation.cs | 3 +- .../Runtime/Settings/YooAssetSettingsData.cs | 113 +++++++++++++++++- 11 files changed, 146 insertions(+), 69 deletions(-) delete mode 100644 Assets/YooAsset/Runtime/FileSystem/CacheSystem/CacheHelper.cs delete mode 100644 Assets/YooAsset/Runtime/FileSystem/CacheSystem/CacheHelper.cs.meta diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs index b222318d..020c2162 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs @@ -22,7 +22,7 @@ namespace YooAsset.Editor /// public static string GetStreamingAssetsRoot() { - return $"{Application.dataPath}/StreamingAssets/{YooAssetSettingsData.Setting.DefaultYooFolderName}/"; + return YooAssetSettingsData.GetYooEditorBuildinRoot(); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/CacheSystem/CacheHelper.cs b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/CacheHelper.cs deleted file mode 100644 index d984476a..00000000 --- a/Assets/YooAsset/Runtime/FileSystem/CacheSystem/CacheHelper.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.IO; - -namespace YooAsset -{ - internal class CacheHelper - { - /// - /// 获取默认的缓存根目录 - /// - public static string GetDefaultCacheRoot() - { -#if UNITY_EDITOR - // 注意:为了方便调试查看,编辑器下把存储目录放到项目里。 - string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath); - projectPath = PathUtility.RegularPath(projectPath); - return PathUtility.Combine(projectPath, YooAssetSettingsData.Setting.DefaultYooFolderName); -#elif UNITY_STANDALONE - return PathUtility.Combine(UnityEngine.Application.dataPath, YooAssetSettingsData.Setting.DefaultYooFolderName); -#else - return PathUtility.Combine(UnityEngine.Application.persistentDataPath, YooAssetSettingsData.Setting.DefaultYooFolderName); -#endif - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/CacheSystem/CacheHelper.cs.meta b/Assets/YooAsset/Runtime/FileSystem/CacheSystem/CacheHelper.cs.meta deleted file mode 100644 index a2091cde..00000000 --- a/Assets/YooAsset/Runtime/FileSystem/CacheSystem/CacheHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: cbc12d398555ced46b201626eec6825e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs index 97890425..1856e574 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs @@ -181,7 +181,7 @@ namespace YooAsset PackageName = packageName; if (string.IsNullOrEmpty(rootDirectory)) - rootDirectory = GetDefaultRoot(); + rootDirectory = GetDefaultBuildinRoot(); _packageRoot = PathUtility.Combine(rootDirectory, packageName); @@ -292,9 +292,9 @@ namespace YooAsset } #region 内部方法 - protected string GetDefaultRoot() + protected string GetDefaultBuildinRoot() { - return PathUtility.Combine(Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName); + return YooAssetSettingsData.GetYooMobileBuildinRoot(); } public string GetBuildinFileLoadPath(PackageBundle bundle) { @@ -305,30 +305,25 @@ namespace YooAsset } return filePath; } - public string GetBuildinCatalogFileLoadPath() - { - string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName); - return PathUtility.Combine(YooAssetSettingsData.Setting.DefaultYooFolderName, PackageName, fileName); - } public string GetBuildinPackageVersionFilePath() { string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName); - return PathUtility.Combine(FileRoot, fileName); + return PathUtility.Combine(_packageRoot, fileName); } public string GetBuildinPackageHashFilePath(string packageVersion) { string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion); - return PathUtility.Combine(FileRoot, fileName); + return PathUtility.Combine(_packageRoot, fileName); } public string GetBuildinPackageManifestFilePath(string packageVersion) { string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion); - return PathUtility.Combine(FileRoot, fileName); + return PathUtility.Combine(_packageRoot, fileName); } - public string GetStreamingAssetsPackageRoot() + public string GetCatalogFileLoadPath() { - string rootPath = PathUtility.Combine(Application.dataPath, "StreamingAssets", YooAssetSettingsData.Setting.DefaultYooFolderName); - return PathUtility.Combine(rootPath, PackageName); + string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName); + return YooAssetSettingsData.GetYooResourcesLoadPath(PackageName, fileName); } /// diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystemBuild.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystemBuild.cs index f6fdfa70..647e4ea9 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystemBuild.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystemBuild.cs @@ -17,12 +17,12 @@ namespace YooAsset { YooLogger.Log("Begin to create catalog file !"); - string savePath = $"Assets/Resources/{YooAssetSettingsData.Setting.DefaultYooFolderName}"; + string savePath = YooAssetSettingsData.GetYooResourcesFullPath(); DirectoryInfo saveDirectory = new DirectoryInfo(savePath); if (saveDirectory.Exists) saveDirectory.Delete(true); - string rootPath = $"{Application.dataPath}/StreamingAssets/{YooAssetSettingsData.Setting.DefaultYooFolderName}"; + string rootPath = YooAssetSettingsData.GetYooEditorBuildinRoot(); DirectoryInfo rootDirectory = new DirectoryInfo(rootPath); if (rootDirectory.Exists == false) { @@ -105,7 +105,8 @@ namespace YooAsset } } - string saveFilePath = $"Assets/Resources/{YooAssetSettingsData.Setting.DefaultYooFolderName}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}"; + string fullPath = YooAssetSettingsData.GetYooResourcesFullPath(); + string saveFilePath = $"{fullPath}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}"; FileUtility.CreateFileDirectory(saveFilePath); UnityEditor.AssetDatabase.CreateAsset(buildinFileCatalog, saveFilePath); diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSInitializeOperation.cs index 3369fddf..0cdbfdb3 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSInitializeOperation.cs @@ -65,7 +65,8 @@ namespace YooAsset #if UNITY_EDITOR // 兼容性初始化 // 说明:内置文件系统在编辑器下运行时需要动态生成 - string packageRoot = _fileSystem.GetStreamingAssetsPackageRoot(); + string buildinRoot = YooAssetSettingsData.GetYooEditorBuildinRoot(); + string packageRoot = PathUtility.Combine(buildinRoot, _fileSystem.PackageName); DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot); #endif diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/internal/LoadBuildinCatalogFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/internal/LoadBuildinCatalogFileOperation.cs index 7b3bf54c..427dca8a 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/internal/LoadBuildinCatalogFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/internal/LoadBuildinCatalogFileOperation.cs @@ -30,7 +30,7 @@ namespace YooAsset if (_steps == ESteps.LoadCatalog) { - string catalogFilePath = _fileSystem.GetBuildinCatalogFileLoadPath(); + string catalogFilePath = _fileSystem.GetCatalogFileLoadPath(); var catalog = Resources.Load(catalogFilePath); if (catalog == null) { diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs index 59c997ce..6c5b63ab 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs @@ -255,7 +255,7 @@ namespace YooAsset PackageName = packageName; if (string.IsNullOrEmpty(rootDirectory)) - rootDirectory = CacheHelper.GetDefaultCacheRoot(); + rootDirectory = GetDefaultCacheRoot(); _packageRoot = PathUtility.Combine(rootDirectory, packageName); _cacheFileRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.SaveFilesFolderName); @@ -520,6 +520,16 @@ namespace YooAsset #endregion #region 内部方法 + public string GetDefaultCacheRoot() + { +#if UNITY_EDITOR + return YooAssetSettingsData.GetYooEditorCacheRoot(); +#elif UNITY_STANDALONE + return YooAssetSettingsData.GetYooStandaloneCacheRoot(); +#else + return YooAssetSettingsData.GetYooMobileCacheRoot(); +#endif + } public string GetCacheFileLoadPath(PackageBundle bundle) { return GetDataFilePath(bundle); diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/DefaultWebServerFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/DefaultWebServerFileSystem.cs index 2cdfde80..1a6e0b13 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/DefaultWebServerFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/DefaultWebServerFileSystem.cs @@ -163,8 +163,7 @@ namespace YooAsset #region 内部方法 protected string GetDefaultWebRoot() { - string path = PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName); - return path; + return YooAssetSettingsData.GetYooWebBuildinRoot(); } public string GetWebFileLoadPath(PackageBundle bundle) { @@ -175,11 +174,6 @@ namespace YooAsset } return filePath; } - public string GetCatalogFileLoadPath() - { - string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName); - return PathUtility.Combine(YooAssetSettingsData.Setting.DefaultYooFolderName, PackageName, fileName); - } public string GetWebPackageVersionFilePath() { string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName); @@ -195,10 +189,10 @@ namespace YooAsset string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion); return PathUtility.Combine(FileRoot, fileName); } - public string GetStreamingAssetsPackageRoot() + public string GetCatalogFileLoadPath() { - string rootPath = PathUtility.Combine(Application.dataPath, "StreamingAssets", YooAssetSettingsData.Setting.DefaultYooFolderName); - return PathUtility.Combine(rootPath, PackageName); + string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName); + return YooAssetSettingsData.GetYooResourcesLoadPath(PackageName, fileName); } /// diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSInitializeOperation.cs index f9c2df46..113fb822 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSInitializeOperation.cs @@ -35,7 +35,8 @@ namespace YooAsset #if UNITY_EDITOR // 兼容性初始化 // 说明:内置文件系统在编辑器下运行时需要动态生成 - string packageRoot = _fileSystem.GetStreamingAssetsPackageRoot(); + string buildinRoot = YooAssetSettingsData.GetYooEditorBuildinRoot(); + string packageRoot = PathUtility.Combine(buildinRoot, _fileSystem.PackageName); DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot); #endif diff --git a/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs b/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs index 9a897ee0..742e2444 100644 --- a/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs +++ b/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System.IO; +using UnityEngine; namespace YooAsset { @@ -71,5 +72,115 @@ namespace YooAsset { return $"{Setting.ManifestFileName}_{packageName}.version"; } + + #region 路径相关 + /// + /// 获取YOO的Resources目录的加载路径 + /// + public static string GetYooResourcesLoadPath(string packageName, string fileName) + { + if (string.IsNullOrEmpty(Setting.DefaultYooFolderName)) + return PathUtility.Combine(packageName, fileName); + else + return PathUtility.Combine(Setting.DefaultYooFolderName, packageName, fileName); + } + + /// + /// 获取YOO的Resources目录的全路径 + /// + public static string GetYooResourcesFullPath() + { + if (string.IsNullOrEmpty(Setting.DefaultYooFolderName)) + return $"Assets/Resources"; + else + return $"Assets/Resources/{Setting.DefaultYooFolderName}"; + } + + /// + /// 获取YOO的编辑器下内置文件根目录 + /// + public static string GetYooEditorBuildinRoot() + { + if (string.IsNullOrEmpty(Setting.DefaultYooFolderName)) + return PathUtility.Combine(Application.dataPath, "StreamingAssets"); + else + return PathUtility.Combine(Application.dataPath, "StreamingAssets", Setting.DefaultYooFolderName); + } + + /// + /// 获取YOO的PC端内置文件根目录 + /// + public static string GetYooStandaloneBuildinRoot() + { + if (string.IsNullOrEmpty(Setting.DefaultYooFolderName)) + return Application.streamingAssetsPath; + else + return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName); + } + + /// + /// 获取YOO的移动端内置文件根目录 + /// + public static string GetYooMobileBuildinRoot() + { + if (string.IsNullOrEmpty(Setting.DefaultYooFolderName)) + return Application.streamingAssetsPath; + else + return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName); + } + + /// + /// 获取YOO的Web端内置文件根目录 + /// + public static string GetYooWebBuildinRoot() + { + if (string.IsNullOrEmpty(Setting.DefaultYooFolderName)) + return Application.streamingAssetsPath; + else + return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName); + } + + /// + /// 获取YOO的编辑器下缓存文件根目录 + /// + public static string GetYooEditorCacheRoot() + { + if (string.IsNullOrEmpty(Setting.DefaultYooFolderName)) + { + string projectPath = Path.GetDirectoryName(Application.dataPath); + projectPath = PathUtility.RegularPath(projectPath); + return projectPath; + } + else + { + // 注意:为了方便调试查看,编辑器下把存储目录放到项目根目录下。 + string projectPath = Path.GetDirectoryName(Application.dataPath); + projectPath = PathUtility.RegularPath(projectPath); + return PathUtility.Combine(projectPath, Setting.DefaultYooFolderName); + } + } + + /// + /// 获取YOO的PC端缓存文件根目录 + /// + public static string GetYooStandaloneCacheRoot() + { + if (string.IsNullOrEmpty(Setting.DefaultYooFolderName)) + return Application.dataPath; + else + return PathUtility.Combine(Application.dataPath, Setting.DefaultYooFolderName); + } + + /// + /// 获取YOO的移动端缓存文件根目录 + /// + public static string GetYooMobileCacheRoot() + { + if (string.IsNullOrEmpty(Setting.DefaultYooFolderName)) + return Application.persistentDataPath; + else + return PathUtility.Combine(Application.persistentDataPath, Setting.DefaultYooFolderName); + } + #endregion } } \ No newline at end of file