using UnityEditor;
using UnityEngine;
public class CopyResourcePath : MonoBehaviour
{
[MenuItem("Assets/复制资源路径")]
private static void CopyPath()
{
var obj = Selection.activeObject;
if (obj == null)
{
Debug.LogWarning("未选中资源!");
return;
}
// 获取相对于 Resources 的路径
string path = AssetDatabase.GetAssetPath(obj);
int resourcesIndex = path.IndexOf("/Resources/");
if (resourcesIndex == -1)
{
Debug.LogWarning("所选资源不在Resources文件夹中!");
return;
}
path = path.Substring(resourcesIndex + 11); // 去掉 "Assets/Resources/" 部分
path = System.IO.Path.ChangeExtension(path, null); // 去掉文件扩展名
// 复制到剪贴板
EditorGUIUtility.systemCopyBuffer = path;
Debug.Log($"所选资源路径: {path}");
}
}
创建以上脚本后,直接在所选资源上 右击——复制资源路径,就能复制到路径,之后粘贴即可