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; namespace GameEditor.FrameTool { public class ConfigWindow : EditorWindow { string m_ExcelPath; private void OnEnable() { m_ExcelPath = EditorPrefs.GetString("m_ExcelPath"); } // 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(); window.InitWindow(); } void InitWindow() { InitSize(); InitGames(); } /// /// 初始化大小 /// void InitSize() { minSize = new Vector2(300, 400); maxSize = new Vector2(300, 650); } /// /// 初始化游戏 /// void InitGames() { } void OnGUI() { EditorGUILayout.BeginVertical(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Config文件路径:"); EditorGUILayout.BeginHorizontal(); m_ExcelPath = EditorGUILayout.TextField("", m_ExcelPath); if (GUILayout.Button("加载", GUILayout.Width(60f))) { } 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)) { 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(); } } }