Unity 拷贝Hierarchy中的物体路径
2022-09-23 本文已影响0人
114105lijia
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
namespace UnicomFramework.Editor
{
public class GameObjectCopyPath : UnityEditor.Editor
{
private static TextEditor textEditor = new TextEditor();
[MenuItem("GameObject/CopyPath _F12", priority = 12)]
private static void CopyPathOption()
{
if (Selection.activeGameObject)
{
string s = GetTransPath(Selection.activeGameObject.transform);
textEditor.text = s;
textEditor.OnFocus();
textEditor.Copy();
Debug.Log("[CopyPath]:" + s);
}
}
/// <summary>
/// 获得GameObject在Hierarchy中的完整路径
/// </summary>
public static string GetTransPath(Transform trans)
{
if (!trans.parent)
{
return trans.name;
}
return GetTransPath(trans.parent) + "/" + trans.name;
}
}
}
#endif