miduo_client/Assets/Scripts/Editor/GameEditor/FrameTool/ConfigWindowNew.cs

165 lines
5.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 Debug = UnityEngine.Debug;
using LitJson;
namespace GameEditor.FrameTool {
public class ConfigWindowNew : EditorWindow
{
static string excelPath; //模板config 路径
static string m_ExcelPath; //config 路径
Dictionary<string, Object> dic; //模板config字典
Dictionary<string, Object> m_dic; //config字典
// Add menu named "My Window" to the Window menu
[MenuItem("Build/ConfigNew")]
static void Init()
{
m_ExcelPath = EditorPrefs.GetString("ConfigWindowNew_m_ExcelPath");
excelPath = EditorPrefs.GetString("ConfigWindowNew_ExcelPath");
// Get existing open window or if none, make a new one:
ConfigWindowNew window = (ConfigWindowNew)EditorWindow.GetWindow(typeof(ConfigWindowNew));
window.Show();
}
void OnGUI()
{
EditorGUILayout.BeginVertical();
EditorGUILayout.Space();
EditorGUILayout.LabelField("Config模板路径");
EditorGUILayout.BeginHorizontal();
excelPath = EditorGUILayout.TextField("", excelPath);
if (GUILayout.Button("Browse", GUILayout.ExpandWidth(false)))
{
excelPath = EditorUtility.OpenFilePanel("Resource path", excelPath, "");
EditorPrefs.SetString("IMPORTSPINE_SOURCESFOLDERPATH", excelPath);
LoadTempConfigFile(excelPath);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
EditorGUILayout.LabelField("Config文件路径");
EditorGUILayout.BeginHorizontal();
m_ExcelPath = EditorGUILayout.TextField("", m_ExcelPath);
if (GUILayout.Button("Browse", GUILayout.ExpandWidth(false)))
{
m_ExcelPath = EditorUtility.OpenFilePanel("Resource path", m_ExcelPath,"");
EditorPrefs.SetString("IMPORTSPINE_SOURCESFOLDERPATH", m_ExcelPath);
LoadConfigFile(m_ExcelPath);
}
EditorGUILayout.EndHorizontal();
if (m_dic != null)
{
InitGuiLayout(m_dic);
}
else if(dic != null)
{
InitGuiLayout(dic);
}
EditorGUILayout.EndVertical();
}
void InitGuiLayout(Dictionary<string, Object> localDic)
{
EditorGUILayout.BeginVertical();
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("新建"))
{
Debug.Log("新建");
}
if (GUILayout.Button("保存"))
{
Debug.Log("保存");
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.EndVertical();
}
void LoadTempConfigFile(string path)
{
dic = new Dictionary<string, Object>();
StreamReader sr = File.OpenText(path);
if (sr != null)
{
string strinfo = sr.ReadToEnd();
Debug.Log(strinfo);
ReadJson(strinfo);
}
}
static void ReadJson(string strinfo)
{
var data = JsonMapper.ToObject<Hashtable>(strinfo);
foreach (DictionaryEntry de in data)
{
Debug.Log(string.Format("{0}-{1}", de.Key, de.Value));
if (de.Value as string != null)
{
Debug.Log(string.Format("de.Value{0}", (de.Value as string)));
}
}
}
static void LoadConfigFile(string m_ExcelPath)
{
}
static string shellPath;
public static void OpenDirectory(string path)
{
if (string.IsNullOrEmpty(path)) return;
if (!Directory.Exists(path))
{
UnityEngine.Debug.LogError("No Directory: " + path);
return;
}
//Application.dataPath 只能在主线程中获取
int lastIndex = Application.dataPath.LastIndexOf("/");
shellPath = Application.dataPath.Substring(0, lastIndex) + "/Shell/";
// 新开线程防止锁死
Thread newThread = new Thread(new ParameterizedThreadStart(CmdOpenDirectory));
newThread.Start(path);
}
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();
}
}
}