Unity 提取编辑器Assets下文件夹或文件绝对路径

在这里插入图片描述
在这里插入图片描述
复制的路径会保存到操作系统的剪贴板中,使用Ctrl + V 即可粘贴。

using UnityEditor;
using UnityEngine;

namespace ZYF
{
    
    
    public class ProjectCopyPath : MonoBehaviour {
    
    
        [MenuItem("Assets/复制绝对路径", priority = 19)]
        static void CopyTransPath()
        {
    
    
            string path = "";
            if (Selection.assetGUIDs != null && Selection.assetGUIDs.Length == 1)
            {
    
    
                path = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]);
            }
            //去除开头
            string pAssets = Application.streamingAssetsPath.Replace("StreamingAssets", "");
            pAssets = pAssets.Replace("/Assets","");
            string fPath = pAssets + path;
            GUIUtility.systemCopyBuffer = fPath;
            Debug.Log("<color=#ff00ff><size=25>已复制绝对路径:</size></color>"+fPath);
        }
	
    } 

}

猜你喜欢

转载自blog.csdn.net/qq_26318597/article/details/123227452