buildconfig工具优化

dev_chengFeng
jiaoyangna 2021-06-24 16:22:21 +08:00
parent 6b70f85740
commit 1690b59b67
1 changed files with 157 additions and 89 deletions

View File

@ -14,12 +14,15 @@ namespace GameEditor.FrameTool
{ {
string tempConfigPath; string tempConfigPath;
string configPath; string configPath;
string downloadConfigPath;
string previous; string previous;
Dictionary<string, object> dic; Dictionary<string, object> dic;
Dictionary<string, object> curDic; Dictionary<string, int> indexDic;
bool isFinish; //Dictionary<string, object> curDic;
//bool isFinish;
string addKey; string addKey;
string targetPath; string targetPath;
int index;
// Add menu named "My Window" to the Window menu // Add menu named "My Window" to the Window menu
[MenuItem("Build/Config")] [MenuItem("Build/Config")]
static void Init() static void Init()
@ -33,31 +36,50 @@ namespace GameEditor.FrameTool
void OnGUI() void OnGUI()
{ {
EditorGUILayout.BeginVertical(); EditorGUILayout.BeginVertical();
if (GUILayout.Button("加载config模板", GUILayout.ExpandWidth(false)))
EditorGUILayout.BeginHorizontal();
GUILayout.Label("加载config模板");
tempConfigPath = GUILayout.TextArea(tempConfigPath);
if (GUILayout.Button("Brown", GUILayout.ExpandWidth(false)))
{ {
dic.Clear(); dic.Clear();
tempConfigPath = EditorUtility.OpenFilePanel("Resource path", tempConfigPath,"*.*"); tempConfigPath = EditorUtility.OpenFilePanel("Resource path", tempConfigPath, "*.*");
EditorPrefs.SetString("IMPORTCCONFIG_SOURCESFOLDERPATH", tempConfigPath); EditorPrefs.SetString("IMPORTCCONFIG_SOURCESFOLDERPATH", tempConfigPath);
StreamReader sr = File.OpenText(tempConfigPath); StreamReader sr = File.OpenText(tempConfigPath);
SetConfigData(sr.ReadToEnd()); SetConfigData(sr.ReadToEnd());
} }
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
downloadConfigPath = GUILayout.TextArea(downloadConfigPath);
if (GUILayout.Button("下载config模板", GUILayout.ExpandWidth(false))) if (GUILayout.Button("下载config模板", GUILayout.ExpandWidth(false)))
{ {
isFinish = false; if (string.IsNullOrEmpty(downloadConfigPath))
{
return;
}
dic.Clear(); dic.Clear();
string path = "http://60.1.1.12/assetbundles/config.txt"; EditorPrefs.SetString("IMPORTCCONFIG_DownLOADCONFIGPATH", downloadConfigPath);
EditorCoroutineRunner.StartEditorCoroutine(DownLoadTempComfig(path)); EditorCoroutineRunner.StartEditorCoroutine(DownLoadTempComfig(downloadConfigPath));
} }
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
GUILayout.Label("加载数据");
configPath = GUILayout.TextArea(configPath);
if (GUILayout.Button("Brown", GUILayout.ExpandWidth(false)))
{
configPath = EditorUtility.OpenFilePanel("Resource path", configPath, "*.*");
EditorPrefs.SetString("IMPORTCCONFIG_DATAFOLDERPATH", configPath);
StreamReader sr = File.OpenText(configPath);
SetConfigData(sr.ReadToEnd());
}
EditorGUILayout.EndHorizontal();
if (dic != null && dic.Count > 0) if (dic != null && dic.Count > 0)
{ {
RefreshWindowShow(); index = 0;
} RefreshWindowShow2(dic);
if (isFinish)
{
if (curDic != null && curDic.Count > 0)
{
RefreshWindowShow1();
}
} }
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
targetPath = GUILayout.TextArea(targetPath); targetPath = GUILayout.TextArea(targetPath);
@ -71,7 +93,7 @@ namespace GameEditor.FrameTool
JsonData jsonData = new JsonData(); JsonData jsonData = new JsonData();
SetDicToJsonData(jsonData,dic); SetDicToJsonData(jsonData,dic);
string json = JsonMapper.ToJson(jsonData); string json = JsonMapper.ToJson(jsonData);
Debug.Log("jsonData:" + json); //Debug.Log("jsonData:" + json);
File.WriteAllText(targetPath, json, Encoding.UTF8); File.WriteAllText(targetPath, json, Encoding.UTF8);
} }
EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal();
@ -98,12 +120,14 @@ namespace GameEditor.FrameTool
void InitWindow() void InitWindow()
{ {
isFinish = true; //isFinish = true;
addKey = ""; addKey = "";
dic = new Dictionary<string, object>(); dic = new Dictionary<string, object>();
indexDic = new Dictionary<string, int>();
tempConfigPath = EditorPrefs.GetString("IMPORTCCONFIG_SOURCESFOLDERPATH"); tempConfigPath = EditorPrefs.GetString("IMPORTCCONFIG_SOURCESFOLDERPATH");
targetPath = EditorPrefs.GetString("IMPORTCCONFIG_TARGETFOLDERPATH"); targetPath = EditorPrefs.GetString("IMPORTCCONFIG_TARGETFOLDERPATH");
configPath = EditorPrefs.GetString("IMPORTCCONFIG_DATAFOLDERPATH"); configPath = EditorPrefs.GetString("IMPORTCCONFIG_DATAFOLDERPATH");
downloadConfigPath = EditorPrefs.GetString("IMPORTCCONFIG_DownLOADCONFIGPATH");
} }
void SetJsonDataToDic(IDictionary data,Dictionary<string,object> dicc) void SetJsonDataToDic(IDictionary data,Dictionary<string,object> dicc)
@ -111,7 +135,6 @@ namespace GameEditor.FrameTool
foreach (var item in data.Keys) foreach (var item in data.Keys)
{ {
string key = item.ToString(); string key = item.ToString();
//Debug.Log(string.Format("{0}", item));
try try
{ {
IDictionary localData = data[item] as IDictionary; IDictionary localData = data[item] as IDictionary;
@ -136,7 +159,7 @@ namespace GameEditor.FrameTool
{ {
foreach (KeyValuePair<string, object> keyValue in dicc) foreach (KeyValuePair<string, object> keyValue in dicc)
{ {
Debug.Log(string.Format("{0}", keyValue.Key)); //Debug.Log(string.Format("{0}", keyValue.Key));
try try
{ {
Dictionary<string, object> localData = keyValue.Value as Dictionary<string, object>; Dictionary<string, object> localData = keyValue.Value as Dictionary<string, object>;
@ -146,7 +169,7 @@ namespace GameEditor.FrameTool
} }
catch catch
{ {
Debug.Log(string.Format("{0}-{1}", keyValue.Key, keyValue.Value.ToString())); //Debug.Log(string.Format("{0}-{1}", keyValue.Key, keyValue.Value.ToString()));
jsonData[keyValue.Key] = keyValue.Value.ToString(); jsonData[keyValue.Key] = keyValue.Value.ToString();
} }
} }
@ -156,7 +179,7 @@ namespace GameEditor.FrameTool
{ {
foreach (KeyValuePair<string, object> keyValue in dicc) foreach (KeyValuePair<string, object> keyValue in dicc)
{ {
Debug.Log(string.Format("{0}", keyValue.Key)); //Debug.Log(string.Format("{0}", keyValue.Key));
try try
{ {
Dictionary<string, object> localData = keyValue.Value as Dictionary<string, object>; Dictionary<string, object> localData = keyValue.Value as Dictionary<string, object>;
@ -164,97 +187,142 @@ namespace GameEditor.FrameTool
} }
catch catch
{ {
Debug.Log(string.Format("{0}-{1}", keyValue.Key, keyValue.Value.ToString())); //Debug.Log(string.Format("{0}-{1}", keyValue.Key, keyValue.Value.ToString()));
} }
} }
} }
void SetConfigData(string strinfo) void SetConfigData(string strinfo)
{ {
Debug.Log(strinfo); //Debug.Log(strinfo);
JsonData modeInfo = JsonMapper.ToObject(strinfo); JsonData modeInfo = JsonMapper.ToObject(strinfo);
IDictionary data = modeInfo; IDictionary data = modeInfo;
SetJsonDataToDic(data,dic); SetJsonDataToDic(data,dic);
isFinish = true; //isFinish = true;
//GetDicData(dic); //GetDicData(dic);
} }
void RefreshWindowShow() //void RefreshWindowShow()
//{
// EditorGUILayout.BeginVertical();
// EditorGUILayout.BeginHorizontal();
// GUILayout.Label("加载数据");
// configPath = GUILayout.TextArea(configPath);
// if (GUILayout.Button("Brown", GUILayout.ExpandWidth(false)))
// {
// configPath = EditorUtility.OpenFilePanel("Resource path", configPath, "*.*");
// EditorPrefs.SetString("IMPORTCCONFIG_DATAFOLDERPATH", configPath);
// StreamReader sr = File.OpenText(configPath);
// SetConfigData(sr.ReadToEnd());
// }
// EditorGUILayout.EndHorizontal();
// EditorGUILayout.BeginHorizontal();
// foreach (string key in dic.Keys)
// {
// if (GUILayout.Button(key, GUILayout.ExpandWidth(false)))
// {
// curDic = dic[key] as Dictionary<string, object>;
// }
// }
// //if (isFinish)
// //{
// if (curDic != null && curDic.Count > 0)
// {
// addKey = GUILayout.TextField(addKey);
// if (GUILayout.Button("添加key", GUILayout.ExpandWidth(false)))
// {
// curDic.Add(addKey, new Dictionary<string, object>());
// }
// }
// //}
// EditorGUILayout.EndHorizontal();
// EditorGUILayout.EndVertical();
//}
//void RefreshWindowShow1()
//{
// EditorGUILayout.BeginVertical();
// for (int i = 0; i < curDic.Count; i++)
// {
// EditorGUILayout.BeginHorizontal();
// GUILayout.Space(30);
// var item = curDic.ElementAt(i);
// var item1 = (curDic[item.Key] as Dictionary<string, object>);
// GUILayout.Label(item.Key);
// addKey = GUILayout.TextField(addKey);
// if (GUILayout.Button("添加key", GUILayout.ExpandWidth(false)))
// {
// item1.Add(addKey, "");
// }
// if (GUILayout.Button("删除", GUILayout.ExpandWidth(false)))
// {
// curDic.Remove(item.Key);
// }
// EditorGUILayout.EndHorizontal();
// for (int j = 0; j < item1.Count; j++)
// {
// EditorGUILayout.BeginHorizontal();
// GUILayout.Space(60);
// var item2 = item1.ElementAt(j);
// GUILayout.Label(item2.Key);
// item1[item2.Key] = GUILayout.TextField(item1[item2.Key].ToString());
// if (GUILayout.Button("删除", GUILayout.ExpandWidth(false)))
// {
// item1.Remove(item2.Key);
// }
// EditorGUILayout.EndHorizontal();
// }
// }
// EditorGUILayout.EndVertical();
//}
void RefreshWindowShow2(Dictionary<string,object> dicc,string indexDicKey = "0")
{ {
EditorGUILayout.BeginVertical(); for (int i = 0; i < dicc.Count; i++)
EditorGUILayout.BeginHorizontal();
GUILayout.Label("加载数据");
configPath = GUILayout.TextArea(configPath);
if (GUILayout.Button("Brown", GUILayout.ExpandWidth(false)))
{ {
configPath = EditorUtility.OpenFilePanel("Resource path", configPath, "*.*"); var item = dicc.ElementAt(i);
EditorPrefs.SetString("IMPORTCCONFIG_DATAFOLDERPATH", configPath); if (!indexDic.ContainsKey(indexDicKey))
StreamReader sr = File.OpenText(configPath);
SetConfigData(sr.ReadToEnd());
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
foreach (string key in dic.Keys)
{
if (GUILayout.Button(key, GUILayout.ExpandWidth(false)))
{ {
curDic = dic[key] as Dictionary<string, object>; index = index + 1;
indexDic.Add(indexDicKey, index);
} }
} index = indexDic[indexDicKey];
if (isFinish) //Debug.Log(string.Format("{0}-{1}", item.Key, item.Value));
{ Dictionary<string, object> localData = item.Value as Dictionary<string, object>;
if (curDic != null && curDic.Count > 0) if (localData == null)
{
addKey = GUILayout.TextField(addKey);
if (GUILayout.Button("添加key", GUILayout.ExpandWidth(false)))
{
curDic.Add(addKey, new Dictionary<string, object>());
}
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.EndVertical();
}
void RefreshWindowShow1()
{
EditorGUILayout.BeginVertical();
for (int i = 0; i < curDic.Count; i++)
{
EditorGUILayout.BeginHorizontal();
GUILayout.Space(30);
var item = curDic.ElementAt(i);
var item1 = (curDic[item.Key] as Dictionary<string, object>);
GUILayout.Label(item.Key);
addKey = GUILayout.TextField(addKey);
if (GUILayout.Button("添加key", GUILayout.ExpandWidth(false)))
{
item1.Add(addKey, "");
}
if (GUILayout.Button("删除", GUILayout.ExpandWidth(false)))
{
curDic.Remove(item.Key);
}
EditorGUILayout.EndHorizontal();
for (int j = 0; j < item1.Count; j++)
{ {
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
GUILayout.Space(60); GUILayout.Space(30 * index);
var item2 = item1.ElementAt(j); GUILayout.Label(item.Key);
GUILayout.Label(item2.Key); dicc[item.Key] = GUILayout.TextField(dicc[item.Key].ToString());
item1[item2.Key] = GUILayout.TextField(item1[item2.Key].ToString());
if (GUILayout.Button("删除", GUILayout.ExpandWidth(false))) if (GUILayout.Button("删除", GUILayout.ExpandWidth(false)))
{ {
item1.Remove(item2.Key); dicc.Remove(item.Key);
} }
EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal();
} }
else
{
EditorGUILayout.BeginHorizontal();
GUILayout.Space(30 * index);
GUILayout.Label(item.Key);
addKey = GUILayout.TextField(addKey);
if (GUILayout.Button("添加key", GUILayout.ExpandWidth(false)))
{
localData.Add(addKey, "");
}
if (GUILayout.Button("删除", GUILayout.ExpandWidth(false)))
{
localData.Remove(item.Key);
}
EditorGUILayout.EndHorizontal();
RefreshWindowShow2(localData, item.Key);
}
} }
EditorGUILayout.EndVertical();
} }
} }
} }