GetSelectObjPath.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. public class GetSelectObjPath : EditorWindow
  6. {
  7. static GameObject selectObj;
  8. string pathStr;
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. }
  13. void OnGUI()
  14. {
  15. if (GUILayout.Button("获取路径"))
  16. {
  17. pathStr = "";
  18. selectObj = Selection.activeGameObject;
  19. Transform pathObj = selectObj.transform;
  20. while(pathObj.parent != null)
  21. {
  22. if(pathStr == "")
  23. {
  24. pathStr = pathObj.name;
  25. }
  26. else
  27. {
  28. pathStr = pathObj.name + "/" + pathStr;
  29. }
  30. pathObj = pathObj.parent;
  31. }
  32. }
  33. GUILayout.Label("选中的目标路径:");
  34. EditorGUILayout.TextField(pathStr);
  35. }
  36. [MenuItem("Tools/获取对象路径")]
  37. public static void ShowOrHide()
  38. {
  39. EditorWindow.GetWindow(typeof(GetSelectObjPath));
  40. }
  41. }