代码
public static string GetSelectedPathOrFallback()
{
string path = "Assets";
foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
{
path = AssetDatabase.GetAssetPath(obj);
if (!string.IsNullOrEmpty(path) && File.Exists(path))
{
//如果是目录获得目录名,如果是文件获得文件所在的目录名
path = Path.GetDirectoryName(path);
break;
}
}
return path;
}