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); //<2F>ڱ༭<DAB1><E0BCAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
|||
|
|
jsonText = EditorGUILayout.TextField("Json:", jsonText); //<2F><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ǰ
|
|||
|
|
if (GUILayout.Button("Generate Prefab String"))
|
|||
|
|
{
|
|||
|
|
GeneratePrefab(); //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD>Ա<EFBFBD><D4B1>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ<EFBFBD>ʼ<EFBFBD><CABC>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|