46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
public class PrefabGenerate : EditorWindow
|
|
{
|
|
[MenuItem("Tools/PrefabGenerate Tool")]
|
|
public static void ShowWindow()
|
|
{
|
|
EditorWindow.GetWindow(typeof(PrefabGenerate));
|
|
}
|
|
|
|
string jsonText;
|
|
|
|
void OnGUI()
|
|
{
|
|
GUILayout.Label("Generate Prefab Tool", EditorStyles.boldLabel); //在编辑器窗口中显示标题
|
|
jsonText = EditorGUILayout.TextField("Json:", jsonText); //添加文本框,以便用户输入前缀
|
|
if (GUILayout.Button("Generate Prefab String"))
|
|
{
|
|
GeneratePrefab(); //添加一个按钮,以便用户单击以开始对选择的物体进行重命名
|
|
}
|
|
}
|
|
|
|
Dictionary<string, string> dicNodes = new Dictionary<string, string>();
|
|
|
|
private void GeneratePrefab()
|
|
{
|
|
if (Selection.gameObjects.Length > 0)
|
|
{
|
|
foreach (var item in Selection.gameObjects.OrderBy(obj=>obj.name))
|
|
{
|
|
List<string> sub = new List<string>();
|
|
for (int i = 0; i < item.transform.childCount; i++)
|
|
{
|
|
sub.Add(item.transform.GetChild(i).name);
|
|
}
|
|
dicNodes.Add(item.name, string.Join("|", sub));
|
|
}
|
|
|
|
jsonText = JsonTools.DicToJson(dicNodes);
|
|
}
|
|
}
|
|
} |