Unity---在Hierarchy视图中将选中的对象的层级目录复制到剪切板

using UnityEditor;
using UnityEngine;

public class ObjPathCopyTool : ScriptableObject
{
    [MenuItem("Custom/Copy path %Q")]    //自定义快捷键
    static void CopyPath()
    {
        Object[] objs = Selection.objects;
        if (objs.Length < 1)
            return;

        GameObject obj = objs[0] as GameObject;
        if (!obj)
            return;

        string path = obj.name;
        Transform parent = obj.transform.parent;
        while (parent)
        {
            path = string.Format("{0}/{1}", parent.name, path);
            parent = parent.parent;
        }

        Debug.Log(path);
        CopyString(path);
    }

    //将字符串赋值到剪切板
    static void CopyString(string str)
    {
        TextEditor te = new TextEditor();
        te.text = str;
        te.SelectAll();
        te.Copy();
    }

}

Unity自定义快捷:

% - CTRL on Windows / CMD on OSX
‘# - Shift’
& -Alt
LEFT/RIGHT/UP/DOWN - Arrow keys
F1 … F2 - F keys
HOME,END,PGUP,PGDN
字母键 - _ + 字母(如:_g代表按键)
还可以几种合并

原文地址:https://www.cnblogs.com/luguoshuai/p/10689553.html