// 相对路径指的是Assets下
public static string GetAssetPath(string assetName, bool isAbsolutePath = false)
{
var guids = AssetDatabase.FindAssets(assetName);
if (guids.Length > 0)
{
var relativePath = AssetDatabase.GUIDToAssetPath(guids[0]);
var path = isAbsolutePath ? Path.Join(Directory.GetCurrentDirectory(), relativePath) : relativePath;
return path;
}
else
{
Debug.Log("Assets下没有该文件:" + assetName);
return string.Empty;
}
}
网友评论