要点速记
-
命令添加到右键菜单
[MenuItem("Assets/Copy Asset Path")]
或
[MenuItem("Assets/Copy Asset Path",priority = 0)]
(priority值决定命令在菜单中的排序) -
获取选中文件或者夹
AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0])
-
获取的路径写入系统剪贴板
GUIUtility.systemCopyBuffer = path;
案例
1 [MenuItem("Assets/Copy Asset Path")] 2 static void CopyAssetPath() 3 { 4 string path = ""; 5 if (Selection.assetGUIDs!=null && Selection.assetGUIDs.Length==1) 6 { 7 path = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]); 8 } 9 GUIUtility.systemCopyBuffer = path; 10 }