Unity复制GameObject路径到剪切板
/// <summary>
/// 添加Hierarychy中的右键菜单
/// 说明:"GameObject/"下[priority小于等于49]的按钮会出现在Hierarychy的右键菜单中
/// </summary>
public class HierarchyEditor
{
private static readonly TextEditor CopyTool = new TextEditor();
/// <summary>
/// 将一个GameObject在Hierarchy中的完整路径拷贝的剪切板
/// </summary>
[MenuItem("GameObject/Copy Path", priority = 20)]
static void CopyTransPath()
{
Transform trans = Selection.activeTransform;
if(null == trans) return;
CopyTool.text = GetTransPath(trans);
CopyTool.SelectAll();
CopyTool.Copy();
}
/// <summary>
/// 获得GameObject在Hierarchy中的完整路径
/// </summary>
public static string GetTransPath(Transform trans)
{
if (null == trans) return string.Empty;
if (null == trans.parent) return trans.name;
return GetTransPath(trans.parent) + "/" + trans.name;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
转载来源:http://www.jianshu.com/p/19dac8d94f29 (opens new window)
上次更新: 2023/10/16, 17:53:06