加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 02:45:58 所属栏目:Windows 来源:网络整理
导读: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 ; GameObjec
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’& -AltLEFT/RIGHT/UP/DOWN - Arrow keysF1 … F2 - F keysHOME,END,PGUP,PGDN字母键 - _ + 字母(如:_g代表按键)还可以几种合并

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读