使用步骤
1.创建脚本继承自Editor
代码如下(示例):
public class CEditor:Editor
{
[MenuItem("GameObject/CopyHierarchyPath", false, 11)]
public static void CopyHierarchy()
{
GameObject go = Selection.activeGameObject;
string path = go.GetRPath();
path = path.Replace("Canvas (Environment)/", "");
GUIUtility.systemCopyBuffer = path;
}
}
//写了一个拓展方法用来找到上级Transform的名字
public static class Ex
{
public static string GetRPath(this GameObject go)
{
GameObject current = go;
string path = current.name;
while (null != current.transform.parent)
{
current = current.transform.parent.gameObject;
path = current.name + "/" + path;
}
return path;
}
}
2.点击右键效果,路径就会复制到剪切板