mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-27 11:10:11 +00:00
update runtime logic
优化字符串拼接方法。
This commit is contained in:
@@ -8,29 +8,19 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
internal static class PathHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取规范化的路径
|
||||
/// </summary>
|
||||
public static string GetRegularPath(string path)
|
||||
{
|
||||
return path.Replace('\\', '/').Replace("\\", "/"); //替换为Linux路径格式
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件所在的目录路径(Linux格式)
|
||||
/// </summary>
|
||||
public static string GetDirectory(string filePath)
|
||||
{
|
||||
string directory = Path.GetDirectoryName(filePath);
|
||||
return GetRegularPath(directory);
|
||||
}
|
||||
private static string _buildinPath;
|
||||
private static string _sandboxPath;
|
||||
|
||||
/// <summary>
|
||||
/// 获取基于流文件夹的加载路径
|
||||
/// </summary>
|
||||
public static string MakeStreamingLoadPath(string path)
|
||||
{
|
||||
return StringUtility.Format("{0}/{1}/{2}", UnityEngine.Application.streamingAssetsPath, YooAssetSettings.StreamingAssetsBuildinFolder, path);
|
||||
if (string.IsNullOrEmpty(_buildinPath))
|
||||
{
|
||||
_buildinPath = StringUtility.Format("{0}/{1}", UnityEngine.Application.streamingAssetsPath, YooAssetSettings.StreamingAssetsBuildinFolder);
|
||||
}
|
||||
return StringUtility.Format("{0}/{1}", _buildinPath, path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,23 +28,36 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static string MakePersistentLoadPath(string path)
|
||||
{
|
||||
string root = MakePersistentRootPath();
|
||||
string root = GetPersistentRootPath();
|
||||
return StringUtility.Format("{0}/{1}", root, path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒文件夹路径
|
||||
/// </summary>
|
||||
public static string MakePersistentRootPath()
|
||||
public static string GetPersistentRootPath()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里
|
||||
string projectPath = GetDirectory(UnityEngine.Application.dataPath);
|
||||
return StringUtility.Format("{0}/Sandbox", projectPath);
|
||||
if (string.IsNullOrEmpty(_sandboxPath))
|
||||
{
|
||||
string directory = Path.GetDirectoryName(UnityEngine.Application.dataPath);
|
||||
string projectPath = GetRegularPath(directory);
|
||||
_sandboxPath = StringUtility.Format("{0}/Sandbox", projectPath);
|
||||
}
|
||||
return _sandboxPath;
|
||||
#else
|
||||
return StringUtility.Format("{0}/Sandbox", UnityEngine.Application.persistentDataPath);
|
||||
if (string.IsNullOrEmpty(_sandboxPath))
|
||||
{
|
||||
_sandboxPath = StringUtility.Format("{0}/Sandbox", UnityEngine.Application.persistentDataPath);
|
||||
}
|
||||
return _sandboxPath;
|
||||
#endif
|
||||
}
|
||||
private static string GetRegularPath(string path)
|
||||
{
|
||||
return path.Replace('\\', '/').Replace("\\", "/"); //替换为Linux路径格式
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取WWW加载本地资源的路径
|
||||
|
||||
@@ -55,37 +55,6 @@ namespace YooAsset
|
||||
return _cacheBuilder.ToString();
|
||||
}
|
||||
|
||||
public static List<string> StringToStringList(string str, char separator)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
if (!String.IsNullOrEmpty(str))
|
||||
{
|
||||
string[] splits = str.Split(separator);
|
||||
foreach (string split in splits)
|
||||
{
|
||||
string value = split.Trim(); //移除首尾空格
|
||||
if (!String.IsNullOrEmpty(value))
|
||||
{
|
||||
result.Add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static bool StringToBool(string str)
|
||||
{
|
||||
int value = (int)Convert.ChangeType(str, typeof(int));
|
||||
return value > 0;
|
||||
}
|
||||
public static T NameToEnum<T>(string name)
|
||||
{
|
||||
if (Enum.IsDefined(typeof(T), name) == false)
|
||||
{
|
||||
throw new ArgumentException($"Enum {typeof(T)} is not defined name {name}");
|
||||
}
|
||||
return (T)Enum.Parse(typeof(T), name);
|
||||
}
|
||||
|
||||
public static string RemoveFirstChar(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
|
||||
Reference in New Issue
Block a user