52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
using UnityEditor;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
public class PrefabReset : EditorWindow
|
|||
|
|
{
|
|||
|
|
[MenuItem("Tools/PrefabReset Tool")]
|
|||
|
|
public static void ShowWindow()
|
|||
|
|
{
|
|||
|
|
EditorWindow.GetWindow(typeof(PrefabReset));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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()
|
|||
|
|
{
|
|||
|
|
dicNodes = JsonTools.DicFromJson<string, string>(jsonText);
|
|||
|
|
foreach (string key in dicNodes.Keys)
|
|||
|
|
{
|
|||
|
|
GameObject obj = GameObject.Find(key);
|
|||
|
|
if (obj == null)
|
|||
|
|
{
|
|||
|
|
obj = Instantiate(new GameObject());
|
|||
|
|
obj.name = key;
|
|||
|
|
obj.transform.parent = GameObject.Find(key.Substring(0, 2)).transform;
|
|||
|
|
}
|
|||
|
|
string[] subobjs = dicNodes[key].Split('|');
|
|||
|
|
foreach (string keysub in subobjs)
|
|||
|
|
{
|
|||
|
|
GameObject tmp = GameObject.Find(keysub);
|
|||
|
|
if(tmp != null)
|
|||
|
|
{
|
|||
|
|
tmp.transform.parent = obj.transform;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|