Unity--- 资源路径问题

使用 System.IO.Path 这个API得到的路径,其实也是以"\"分隔路径的。
我们在windows下打开资源管理器,某个目录或文件的路径为:E:\uniuProject5.6.2\plan\配置表
使用Unity的API,打印Application.dataPath 时,打印出:E:/LgsTest/XDanceLearn/Art/Art/Assets,是以“/”为分隔符的

/// <summary>
    /// 格式化路径成Asset的标准格式
    /// </summary>
    /// <param name="filePath"></param>
    /// <returns></returns>
    public static string GetAssetPath(string filePath)
    {
        var newFilePath1 = filePath.Replace("\\", "/");
        var newFilePath2 = newFilePath1.Replace("//", "/").Trim();
        newFilePath2 = newFilePath2.Replace("///", "/").Trim();
        newFilePath2 = newFilePath2.Replace("\\\\", "/").Trim();
        return newFilePath2;
    }

 

posted @ 2018-11-09 09:58  小·糊涂仙  阅读(472)  评论(0编辑  收藏  举报