12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 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));
- }
- }
|