57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
|
using UnityEditor;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class SelectedPrefabTool : EditorWindow
|
||
|
{
|
||
|
[MenuItem("工具/预制体路径查找工具", false, 4)]
|
||
|
public static void ShowWindow()
|
||
|
{
|
||
|
EditorWindow.GetWindow(typeof(SelectedPrefabTool), false, "预制体路径查找工具");
|
||
|
}
|
||
|
|
||
|
private void OnGUI()
|
||
|
{
|
||
|
GameObject selectedPrefab = Selection.activeGameObject;
|
||
|
if (selectedPrefab != null && PrefabUtility.IsPartOfAnyPrefab(selectedPrefab))
|
||
|
{
|
||
|
GUILayout.Label("当前选中预制体: " + GetPrefabPath(selectedPrefab));
|
||
|
|
||
|
GUILayout.Space(10);
|
||
|
|
||
|
GUILayout.Label("该预制体子物体路径:");
|
||
|
GUILayout.BeginVertical();
|
||
|
|
||
|
Transform[] childs = selectedPrefab.GetComponentsInChildren<Transform>();
|
||
|
|
||
|
foreach (Transform child in childs)
|
||
|
{
|
||
|
GUILayout.Label(GetChildPath(child));
|
||
|
}
|
||
|
|
||
|
GUILayout.EndVertical();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
GUILayout.Label("当前没有选中预制体!");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private string GetPrefabPath(GameObject prefab)
|
||
|
{
|
||
|
string path = AssetDatabase.GetAssetPath(prefab);
|
||
|
return path;
|
||
|
}
|
||
|
|
||
|
private string GetChildPath(Transform child)
|
||
|
{
|
||
|
string path = child.name;
|
||
|
Transform parent = child.parent;
|
||
|
while (parent != null)
|
||
|
{
|
||
|
path = parent.name + "/" + path;
|
||
|
parent = parent.parent;
|
||
|
}
|
||
|
return path;
|
||
|
}
|
||
|
}
|