diff --git a/Assets/YooAsset/Runtime/CacheSystem/PersistentTools.cs b/Assets/YooAsset/Runtime/CacheSystem/PersistentTools.cs index 407da3f..1a9941b 100644 --- a/Assets/YooAsset/Runtime/CacheSystem/PersistentTools.cs +++ b/Assets/YooAsset/Runtime/CacheSystem/PersistentTools.cs @@ -5,6 +5,7 @@ namespace YooAsset { internal static class PersistentTools { + private const string SandboxFolderName = "Sandbox"; private const string CacheFolderName = "CacheFiles"; private const string CachedBundleFileFolder = "BundleFiles"; private const string CachedRawFileFolder = "RawFiles"; @@ -33,27 +34,23 @@ namespace YooAsset if (string.IsNullOrEmpty(_sandboxPath)) { string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath); - _sandboxPath = Path.Combine(projectPath, "Sandbox"); + projectPath = PathUtility.RegularPath(projectPath); + _sandboxPath = PathUtility.Combine(projectPath, SandboxFolderName); } #elif UNITY_STANDALONE if (string.IsNullOrEmpty(_sandboxPath)) { - _sandboxPath = Path.Combine(UnityEngine.Application.dataPath, "Sandbox"); + _sandboxPath = PathUtility.Combine(UnityEngine.Application.dataPath, SandboxFolderName); } #else if (string.IsNullOrEmpty(_sandboxPath)) { - _sandboxPath = Path.Combine(UnityEngine.Application.persistentDataPath, "Sandbox"); + _sandboxPath = PathUtility.Combine(UnityEngine.Application.persistentDataPath, SandboxFolderName); } #endif return _sandboxPath; } - private static string GetRegularPath(string path) - { - return path.Replace('\\', '/').Replace("\\", "/"); //替换为Linux路径格式 - } - /// /// 获取基于流文件夹的加载路径 @@ -62,9 +59,9 @@ namespace YooAsset { if (string.IsNullOrEmpty(_buildinPath)) { - _buildinPath = Path.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettings.StreamingAssetsBuildinFolder); + _buildinPath = PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettings.StreamingAssetsBuildinFolder); } - return Path.Combine(_buildinPath, path); + return PathUtility.Combine(_buildinPath, path); } /// @@ -73,17 +70,17 @@ namespace YooAsset public static string MakePersistentLoadPath(string path) { string root = GetPersistentRootPath(); - return Path.Combine(root, path); + return PathUtility.Combine(root, path); } public static string MakePersistentLoadPath(string path1, string path2) { string root = GetPersistentRootPath(); - return Path.Combine(root, path1, path2); + return PathUtility.Combine(root, path1, path2); } public static string MakePersistentLoadPath(string path1, string path2, string path3) { string root = GetPersistentRootPath(); - return Path.Combine(root, path1, path2, path3); + return PathUtility.Combine(root, path1, path2, path3); } /// diff --git a/Assets/YooAsset/Runtime/PackageSystem/PackageBundle.cs b/Assets/YooAsset/Runtime/PackageSystem/PackageBundle.cs index 2dac595..60a9d8e 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/PackageBundle.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/PackageBundle.cs @@ -75,13 +75,13 @@ namespace YooAsset if (IsRawFile) { string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName); - _cachedDataFilePath = System.IO.Path.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName); + _cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName); _cachedDataFilePath += _fileExtension; } else { string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName); - _cachedDataFilePath = System.IO.Path.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName); + _cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName); } return _cachedDataFilePath; } @@ -102,12 +102,12 @@ namespace YooAsset if (IsRawFile) { string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName); - _cachedInfoFilePath = System.IO.Path.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName); + _cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName); } else { string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName); - _cachedInfoFilePath = System.IO.Path.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName); + _cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName); } return _cachedInfoFilePath; } diff --git a/Assets/YooAsset/Runtime/PackageSystem/PackageManifest.cs b/Assets/YooAsset/Runtime/PackageSystem/PackageManifest.cs index 78bc911..a2d4948 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/PackageManifest.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/PackageManifest.cs @@ -114,7 +114,7 @@ namespace YooAsset // 添加无后缀名路径的映射 if (Path.HasExtension(location)) { - string locationWithoutExtension = StringUtility.RemoveExtension(location); + string locationWithoutExtension = PathUtility.RemoveExtension(location); if (AssetPathMapping.ContainsKey(locationWithoutExtension)) YooLogger.Warning($"AssetPath have existed : {locationWithoutExtension}"); else diff --git a/Assets/YooAsset/Runtime/Utility/YooUtility.cs b/Assets/YooAsset/Runtime/Utility/YooUtility.cs index ddde6dd..f1dba37 100644 --- a/Assets/YooAsset/Runtime/Utility/YooUtility.cs +++ b/Assets/YooAsset/Runtime/Utility/YooUtility.cs @@ -7,6 +7,60 @@ using System.Security.Cryptography; namespace YooAsset { + /// + /// 路径工具类 + /// + internal static class PathUtility + { + /// + /// 路径归一化 + /// 注意:替换为Linux路径格式 + /// + public static string RegularPath(string path) + { + return path.Replace('\\', '/').Replace("\\", "/"); + } + + /// + /// 移除路径里的后缀名 + /// + public static string RemoveExtension(string str) + { + if (string.IsNullOrEmpty(str)) + return str; + + int index = str.LastIndexOf("."); + if (index == -1) + return str; + else + return str.Remove(index); //"assets/config/test.unity3d" --> "assets/config/test" + } + + /// + /// 合并路径 + /// + public static string Combine(string path1, string path2) + { + return StringUtility.Format("{0}/{1}", path1, path2); + } + + /// + /// 合并路径 + /// + public static string Combine(string path1, string path2, string path3) + { + return StringUtility.Format("{0}/{1}/{2}", path1, path2, path3); + } + + /// + /// 合并路径 + /// + public static string Combine(string path1, string path2, string path3, string path4) + { + return StringUtility.Format("{0}/{1}/{2}/{3}", path1, path2, path3, path4); + } + } + /// /// 字符串工具类 /// @@ -54,30 +108,6 @@ namespace YooAsset _cacheBuilder.AppendFormat(format, args); return _cacheBuilder.ToString(); } - - public static string RemoveFirstChar(string str) - { - if (string.IsNullOrEmpty(str)) - return str; - return str.Substring(1); - } - public static string RemoveLastChar(string str) - { - if (string.IsNullOrEmpty(str)) - return str; - return str.Substring(0, str.Length - 1); - } - public static string RemoveExtension(string str) - { - if (string.IsNullOrEmpty(str)) - return str; - - int index = str.LastIndexOf("."); - if (index == -1) - return str; - else - return str.Remove(index); //"assets/config/test.unity3d" --> "assets/config/test" - } } ///