prefab 在场景中 , 用这个方法可以获取它的磁盘路径:
[MenuItem("Gq_Tools/↓获取prefab路径")]
public static void SaveDecalParameters()
{
var objs = Selection.objects;
var obj = objs[0] as GameObject;
Object parentObject = PrefabUtility.GetCorrespondingObjectFromSource<Object>(obj);
string resourcePath = AssetDatabase.GetAssetPath(parentObject);
// 获取prefab的资源路径
Debug.Log("_resourcePath:" + resourcePath);
DoSaveDecalParameters(obj, resourcePath);
}
/// 根据传过来的参数(bundlename) 查询这个prefab文件在磁盘上的位置
var assetBundlePath = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundle(fileNameLower);
//根据prefab名称, 加载asset 资源为object , 再找出asset路径, 再根据资源路径查找依赖项
string asdf = pathName;
Object _object = UnityEditor.AssetDatabase.LoadAssetAtPath(asdf, typeof(Object));
var sePath = UnityEditor.AssetDatabase.GetAssetPath(_object);
var ssa = UnityEditor.AssetDatabase.GetDependencies(sePath);
foreach (var pathNameO in ssa)
{
Debug.Log("assetBundlePath:::" + pathNameO);
semangFile(pathNameO);
}