using UnityEditor;
using UnityEngine;
public class CopyPath : Editor
{
private static readonly TextEditor CopyTool = new TextEditor();
[MenuItem("Tools/CopyPath #R", false)]
static void CopyPathPath()
{
Transform trans = Selection.activeTransform;
if (null == trans) return;
CopyTool.text = GetPath(trans);
CopyTool.SelectAll();
CopyTool.Copy();
Debug.Log(GetPath(trans));
}
public static string GetPath(Transform trans)
{
if (null == trans) return string.Empty;
if (null == trans.parent) return trans.name;
return GetPath(trans.parent) + "/" + trans.name;
}
}
Unity编辑器开发_拷贝Hierarchy层级路径
最新推荐文章于 2023-06-25 11:15:33 发布
这个博客介绍了一个Unity Editor脚本,用于在Unity编辑器中方便地复制所选Transform的完整路径。通过菜单项`Tools/CopyPath#R`,可以将Transform在场景层级中的路径复制到剪贴板,有助于快速引用或调试。
摘要由CSDN通过智能技术生成