update runtime code

main
hevinci 2023-06-13 16:41:27 +08:00
parent cf532a84ef
commit cd43d0775d
4 changed files with 69 additions and 42 deletions

View File

@ -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路径格式
}
/// <summary>
/// 获取基于流文件夹的加载路径
@ -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);
}
/// <summary>
@ -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);
}
/// <summary>

View File

@ -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;
}

View File

@ -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

View File

@ -7,6 +7,60 @@ using System.Security.Cryptography;
namespace YooAsset
{
/// <summary>
/// 路径工具类
/// </summary>
internal static class PathUtility
{
/// <summary>
/// 路径归一化
/// 注意替换为Linux路径格式
/// </summary>
public static string RegularPath(string path)
{
return path.Replace('\\', '/').Replace("\\", "/");
}
/// <summary>
/// 移除路径里的后缀名
/// </summary>
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"
}
/// <summary>
/// 合并路径
/// </summary>
public static string Combine(string path1, string path2)
{
return StringUtility.Format("{0}/{1}", path1, path2);
}
/// <summary>
/// 合并路径
/// </summary>
public static string Combine(string path1, string path2, string path3)
{
return StringUtility.Format("{0}/{1}/{2}", path1, path2, path3);
}
/// <summary>
/// 合并路径
/// </summary>
public static string Combine(string path1, string path2, string path3, string path4)
{
return StringUtility.Format("{0}/{1}/{2}/{3}", path1, path2, path3, path4);
}
}
/// <summary>
/// 字符串工具类
/// </summary>
@ -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"
}
}
/// <summary>