using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; public class GetSelectObjPath : EditorWindow { static GameObject selectObj; string pathStr; // Start is called before the first frame update void Start() { } void OnGUI() { if (GUILayout.Button("获取路径")) { pathStr = ""; selectObj = Selection.activeGameObject; Transform pathObj = selectObj.transform; while(pathObj.parent != null) { if(pathStr == "") { pathStr = pathObj.name; } else { pathStr = pathObj.name + "/" + pathStr; } pathObj = pathObj.parent; } } GUILayout.Label("选中的目标路径:"); EditorGUILayout.TextField(pathStr); } [MenuItem("Tools/获取对象路径")] public static void ShowOrHide() { EditorWindow.GetWindow(typeof(GetSelectObjPath)); } }