[MenuItem("编辑器工具/复制Hierarchy上选中的GameObject的路径")]
public static void CopySelectedAssetPath()
{
if(Selection.activeGameObject != null)
{
string path = GetPath(Selection.activeGameObject.transform);
EditorGUIUtility.systemCopyBuffer = path;
Debug.Log(path);
}
else
{
EditorGUIUtility.systemCopyBuffer = "";
}
}
private static string GetPath(Transform current)
{
if (current.parent == null)
return "/" + current.name;
return GetPath(current.parent.transform) + "/" + current.name;
}
Unity 编辑器扩展 复制当前Hierarchy上选中的GameObject的路径
于 2024-10-11 13:41:40 首次发布