buildconfig 修改提交
parent
24c2de4c6d
commit
97da91abc3
|
@ -1,129 +1,259 @@
|
|||
using System.Collections;
|
||||
using LitJson;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GameEditor.Core;
|
||||
using GameEditor.GameEditor.PlayerBuilder;
|
||||
using GameLogic;
|
||||
using System.Diagnostics;
|
||||
using ResUpdate;
|
||||
using System.Threading;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace GameEditor.FrameTool {
|
||||
public class ConfigWindow : EditorWindow
|
||||
namespace GameEditor.FrameTool
|
||||
{
|
||||
public class ConfigWindowNew : EditorWindow
|
||||
{
|
||||
|
||||
string m_ExcelPath;
|
||||
private void OnEnable()
|
||||
{
|
||||
m_ExcelPath = EditorPrefs.GetString("m_ExcelPath");
|
||||
}
|
||||
|
||||
string tempConfigPath;
|
||||
string configPath;
|
||||
string previous;
|
||||
Dictionary<string, object> dic;
|
||||
Dictionary<string, object> curDic;
|
||||
bool isFinish;
|
||||
string addKey;
|
||||
string targetPath;
|
||||
// Add menu named "My Window" to the Window menu
|
||||
[MenuItem("Build/Config")]
|
||||
static void Init()
|
||||
{
|
||||
|
||||
// Get existing open window or if none, make a new one:
|
||||
ConfigWindow window = (ConfigWindow)EditorWindow.GetWindow(typeof(ConfigWindow));
|
||||
window.Show();
|
||||
ConfigWindowNew window = (ConfigWindowNew)EditorWindow.GetWindow(typeof(ConfigWindowNew));
|
||||
window.InitWindow();
|
||||
|
||||
}
|
||||
|
||||
void InitWindow()
|
||||
{
|
||||
InitSize();
|
||||
InitGames();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化大小
|
||||
/// </summary>
|
||||
void InitSize()
|
||||
{
|
||||
minSize = new Vector2(300, 400);
|
||||
maxSize = new Vector2(300, 650);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化游戏
|
||||
/// </summary>
|
||||
void InitGames()
|
||||
{
|
||||
window.Show();
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Config文件路径:");
|
||||
if (GUILayout.Button("加载config模板", GUILayout.ExpandWidth(false)))
|
||||
{
|
||||
dic.Clear();
|
||||
tempConfigPath = EditorUtility.OpenFilePanel("Resource path", tempConfigPath,"*.*");
|
||||
EditorPrefs.SetString("IMPORTCCONFIG_SOURCESFOLDERPATH", tempConfigPath);
|
||||
StreamReader sr = File.OpenText(tempConfigPath);
|
||||
SetConfigData(sr.ReadToEnd());
|
||||
}
|
||||
if (GUILayout.Button("下载config模板", GUILayout.ExpandWidth(false)))
|
||||
{
|
||||
isFinish = false;
|
||||
dic.Clear();
|
||||
string path = "http://60.1.1.12/assetbundles/config.txt";
|
||||
EditorCoroutineRunner.StartEditorCoroutine(DownLoadTempComfig(path));
|
||||
}
|
||||
if (dic != null && dic.Count > 0)
|
||||
{
|
||||
RefreshWindowShow();
|
||||
}
|
||||
if (isFinish)
|
||||
{
|
||||
if (curDic != null && curDic.Count > 0)
|
||||
{
|
||||
RefreshWindowShow1();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
targetPath = GUILayout.TextArea(targetPath);
|
||||
if (GUILayout.Button("Brown", GUILayout.ExpandWidth(false)))
|
||||
{
|
||||
targetPath = EditorUtility.OpenFilePanel("Resource path", targetPath, "*.*");
|
||||
EditorPrefs.SetString("IMPORTCCONFIG_TARGETFOLDERPATH", targetPath);
|
||||
}
|
||||
if (GUILayout.Button("保存数据", GUILayout.ExpandWidth(false)))
|
||||
{
|
||||
JsonData jsonData = new JsonData();
|
||||
SetDicToJsonData(jsonData,dic);
|
||||
string json = JsonMapper.ToJson(jsonData);
|
||||
Debug.Log("jsonData:" + json);
|
||||
File.WriteAllText(targetPath, json, Encoding.UTF8);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
IEnumerator DownLoadTempComfig(string path)
|
||||
{
|
||||
UnityWebRequest request0 = UnityWebRequest.Get(path);
|
||||
request0.downloadHandler = new DownloadHandlerBuffer();
|
||||
yield return request0.SendWebRequest();
|
||||
while (!request0.isDone)
|
||||
{
|
||||
yield return 1;
|
||||
}
|
||||
if (request0.isNetworkError || request0.isHttpError)
|
||||
{
|
||||
Debug.Log(request0.error);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetConfigData(request0.downloadHandler.text);
|
||||
}
|
||||
}
|
||||
|
||||
void InitWindow()
|
||||
{
|
||||
isFinish = true;
|
||||
addKey = "";
|
||||
dic = new Dictionary<string, object>();
|
||||
tempConfigPath = EditorPrefs.GetString("IMPORTCCONFIG_SOURCESFOLDERPATH");
|
||||
targetPath = EditorPrefs.GetString("IMPORTCCONFIG_TARGETFOLDERPATH");
|
||||
configPath = EditorPrefs.GetString("IMPORTCCONFIG_DATAFOLDERPATH");
|
||||
}
|
||||
|
||||
void SetJsonDataToDic(IDictionary data,Dictionary<string,object> dicc)
|
||||
{
|
||||
foreach (var item in data.Keys)
|
||||
{
|
||||
string key = item.ToString();
|
||||
//Debug.Log(string.Format("{0}", item));
|
||||
try
|
||||
{
|
||||
IDictionary localData = data[item] as IDictionary;
|
||||
if (!dicc.ContainsKey(key))
|
||||
{
|
||||
dicc.Add(key, new Dictionary<string, object>());
|
||||
}
|
||||
SetJsonDataToDic(localData, dicc[key] as Dictionary<string, object>);
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (dicc.ContainsKey(key))
|
||||
{
|
||||
dicc.Remove(key);
|
||||
}
|
||||
dicc.Add(key, data[item]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetDicToJsonData(JsonData jsonData, Dictionary<string, object> dicc)
|
||||
{
|
||||
foreach (KeyValuePair<string, object> keyValue in dicc)
|
||||
{
|
||||
Debug.Log(string.Format("{0}", keyValue.Key));
|
||||
try
|
||||
{
|
||||
Dictionary<string, object> localData = keyValue.Value as Dictionary<string, object>;
|
||||
string key = keyValue.Key;
|
||||
jsonData[keyValue.Key] = new JsonData();
|
||||
SetDicToJsonData(jsonData[keyValue.Key], localData);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log(string.Format("{0}-{1}", keyValue.Key, keyValue.Value.ToString()));
|
||||
jsonData[keyValue.Key] = keyValue.Value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GetDicData(Dictionary<string, object> dicc)
|
||||
{
|
||||
foreach (KeyValuePair<string, object> keyValue in dicc)
|
||||
{
|
||||
Debug.Log(string.Format("{0}", keyValue.Key));
|
||||
try
|
||||
{
|
||||
Dictionary<string, object> localData = keyValue.Value as Dictionary<string, object>;
|
||||
GetDicData(localData);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log(string.Format("{0}-{1}", keyValue.Key, keyValue.Value.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetConfigData(string strinfo)
|
||||
{
|
||||
Debug.Log(strinfo);
|
||||
JsonData modeInfo = JsonMapper.ToObject(strinfo);
|
||||
IDictionary data = modeInfo;
|
||||
SetJsonDataToDic(data,dic);
|
||||
isFinish = true;
|
||||
//GetDicData(dic);
|
||||
}
|
||||
|
||||
void RefreshWindowShow()
|
||||
{
|
||||
EditorGUILayout.BeginVertical();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_ExcelPath = EditorGUILayout.TextField("", m_ExcelPath);
|
||||
if (GUILayout.Button("加载", GUILayout.Width(60f)))
|
||||
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());
|
||||
}
|
||||
if (GUILayout.Button("打开目录", GUILayout.Width(60f)))
|
||||
{
|
||||
OpenDirectory(m_ExcelPath);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
|
||||
//if (excelArr != null && excelArr.Length > 0)
|
||||
//{
|
||||
// excelIndex = EditorGUILayout.Popup("选择excel文件:", excelIndex, excelArr);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
static string shellPath;
|
||||
public static void OpenDirectory(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path)) return;
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
foreach (string key in dic.Keys)
|
||||
{
|
||||
UnityEngine.Debug.LogError("No Directory: " + path);
|
||||
return;
|
||||
if (GUILayout.Button(key, GUILayout.ExpandWidth(false)))
|
||||
{
|
||||
curDic = dic[key] as Dictionary<string, object>;
|
||||
}
|
||||
}
|
||||
|
||||
//Application.dataPath 只能在主线程中获取
|
||||
int lastIndex = Application.dataPath.LastIndexOf("/");
|
||||
shellPath = Application.dataPath.Substring(0, lastIndex) + "/Shell/";
|
||||
|
||||
// 新开线程防止锁死
|
||||
Thread newThread = new Thread(new ParameterizedThreadStart(CmdOpenDirectory));
|
||||
newThread.Start(path);
|
||||
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();
|
||||
}
|
||||
private static void CmdOpenDirectory(object obj)
|
||||
{
|
||||
Process p = new Process();
|
||||
#if UNITY_EDITOR_WIN
|
||||
p.StartInfo.FileName = "cmd.exe";
|
||||
p.StartInfo.Arguments = "/c start " + obj.ToString();
|
||||
#elif UNITY_EDITOR_OSX
|
||||
p.StartInfo.FileName = "bash";
|
||||
string shPath = shellPath + "openDir.sh";
|
||||
p.StartInfo.Arguments = shPath + " " + obj.ToString();
|
||||
#endif
|
||||
//UnityEngine.Debug.Log(p.StartInfo.Arguments);
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.RedirectStandardInput = true;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.StartInfo.RedirectStandardError = true;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.Start();
|
||||
|
||||
p.WaitForExit();
|
||||
p.Close();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace GameEditor.FrameTool
|
||||
{
|
||||
public class EditorCoroutine : IEnumerator
|
||||
{
|
||||
private Stack<IEnumerator> executionStack;
|
||||
|
||||
public EditorCoroutine(IEnumerator iterator)
|
||||
{
|
||||
this.executionStack = new Stack<IEnumerator>();
|
||||
this.executionStack.Push(iterator);
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
IEnumerator i = this.executionStack.Peek();
|
||||
|
||||
if (i.MoveNext())
|
||||
{
|
||||
object result = i.Current;
|
||||
if (result != null && result is IEnumerator)
|
||||
{
|
||||
this.executionStack.Push((IEnumerator)result);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.executionStack.Count > 1)
|
||||
{
|
||||
this.executionStack.Pop();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
throw new System.NotSupportedException("This Operation Is Not Supported.");
|
||||
}
|
||||
|
||||
public object Current
|
||||
{
|
||||
get { return this.executionStack.Peek().Current; }
|
||||
}
|
||||
|
||||
public bool Find(IEnumerator iterator)
|
||||
{
|
||||
return this.executionStack.Contains(iterator);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class EditorCoroutineRunner
|
||||
{
|
||||
private static List<EditorCoroutine> editorCoroutineList;
|
||||
private static List<IEnumerator> buffer;
|
||||
|
||||
public static IEnumerator StartEditorCoroutine(IEnumerator iterator)
|
||||
{
|
||||
if (editorCoroutineList == null)
|
||||
{
|
||||
editorCoroutineList = new List<EditorCoroutine>();
|
||||
}
|
||||
if (buffer == null)
|
||||
{
|
||||
buffer = new List<IEnumerator>();
|
||||
}
|
||||
if (editorCoroutineList.Count == 0)
|
||||
{
|
||||
EditorApplication.update += Update;
|
||||
}
|
||||
|
||||
buffer.Add(iterator);
|
||||
|
||||
return iterator;
|
||||
}
|
||||
|
||||
private static bool Find(IEnumerator iterator)
|
||||
{
|
||||
foreach (EditorCoroutine editorCoroutine in editorCoroutineList)
|
||||
{
|
||||
if (editorCoroutine.Find(iterator))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void Update()
|
||||
{
|
||||
editorCoroutineList.RemoveAll
|
||||
(
|
||||
coroutine => { return coroutine.MoveNext() == false; }
|
||||
);
|
||||
|
||||
|
||||
if (buffer.Count > 0)
|
||||
{
|
||||
foreach (IEnumerator iterator in buffer)
|
||||
{
|
||||
if (!Find(iterator))
|
||||
{
|
||||
editorCoroutineList.Add(new EditorCoroutine(iterator));
|
||||
}
|
||||
}
|
||||
|
||||
buffer.Clear();
|
||||
}
|
||||
|
||||
if (editorCoroutineList.Count == 0)
|
||||
{
|
||||
EditorApplication.update -= Update;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a901a51b0e61d1644aa7f3a58a8226da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue