using System.IO; using UnityEngine; /// /// 路径帮助类 /// public class PathHelper { /// /// 根目录 /// public static readonly string m_AssetRootPath = Application.dataPath; /// /// 只读根目录(streamingAssetsPath) /// public static readonly string m_ReadOnlyPath = Application.streamingAssetsPath; /// /// 可读可写根目录(persistentDataPath) /// public static readonly string m_WriteAndReadPath = Application.persistentDataPath; /// /// 获取标准路径 /// /// /// public static string GetStandardPath(string _path) { if (string.IsNullOrEmpty(_path)) { return string.Empty; } return _path.Trim().Replace("\\", "/"); } /// /// 获取指定路径 /// /// /// public static string GetSpecifiedPath(string _path) { if (string.IsNullOrEmpty(_path)) { return null; } string result = #if UNITY_STANDALONE_WIN GetStandardPath(m_ReadOnlyPath + "/" + _path); #else GetStandardPath(m_WriteAndReadPath + "/" + _path); #endif return result; } /// /// 获取文件后缀 /// /// 带有后缀的文件名 /// 返回带点的文件后缀 public static string GetFileSuffix(string _fileName) { if(string.IsNullOrEmpty(_fileName)) { return string.Empty; } return "." + _fileName.Split('.')[1]; } /// /// 根据路径获取文件扩展名 /// /// /// public static string GetExtensionBasedOnPath(string _path) { if (string.IsNullOrEmpty(_path)) { return string.Empty; } return Path.GetFileName(_path); } /// /// 获取文件名 /// /// 带有后缀的文件名 /// public static string GetFileName(string _fileName) { if (string.IsNullOrEmpty(_fileName)) { return string.Empty; } return _fileName.Split('.')[0]; } /// /// 根据路径获取不带扩展名的文件名 /// /// /// public static string GetFileNameWithoutExtensionOnPath(string _path) { if (string.IsNullOrEmpty(_path)) { return string.Empty; } return Path.GetFileNameWithoutExtension(_path); } /// /// 根据路径获取文件名,带扩展名 /// /// /// public static string GetFileNameBasedOnPath(string _path) { if (string.IsNullOrEmpty(_path)) { return string.Empty; } return Path.GetFileName(_path); } /// /// 合并路径 /// /// /// public static string CombineFilePath(params string[] _paths) { if (_paths.Length <= 0) { return null; } string result = ""; for (int i = 0; i < _paths.Length; i++) { result = Path.Combine(result, _paths[i]); } return result; } }