无论是Lua开发,还是unity开发,现在主流的做法都要Find节点的相对路径,对应量比较多的情况下,这也是一个很繁琐的工作,所以一个复制路径工具还是很有必要的。
复制节点路径
public static void CopyGameObjectNode()
{
if (Selection.activeGameObject == null)
{
return;
}
string path = string.Empty;
PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
if (prefabStage != null)
{
path = GetFullPath(Selection.activeGameObject, prefabStage.prefabContentsRoot.name);
}
else
{
path = GetFullPath(Selection.activeGameObject, "UIRoot");
}
TextEditor te = new TextEditor();
te.text = path;
te.SelectAll();
te.Copy();
}
private static string GetFullPath(GameObject go, string rootName)
{
return (go.transform.parent != null && go.transform.parent.name != rootName)
? GetFullPath(go.transform.parent.gameObject, rootName) + "/" + go.name
: go.name;
}