导表工具添加
parent
7dbd376327
commit
fcda2d9d1d
|
|
@ -1,5 +1,6 @@
|
|||
using GameCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using UnityEditor;
|
||||
|
|
@ -7,6 +8,153 @@ using UnityEngine;
|
|||
|
||||
namespace GameEditor.Core.DataConfig
|
||||
{
|
||||
|
||||
public class ConfigExportWindow:EditorWindow
|
||||
{
|
||||
static string m_ExcelPath;
|
||||
static string m_Bench;
|
||||
static string[] m_Files;
|
||||
static bool[] m_Choose;
|
||||
|
||||
[MenuItem("Data Config/Export")]
|
||||
private static void ShowConfigWin()
|
||||
{
|
||||
m_ExcelPath = EditorPrefs.GetString("m_ExcelPath");
|
||||
m_Bench = EditorPrefs.GetString("m_Bench");
|
||||
|
||||
LoadDic();
|
||||
|
||||
var win = GetWindow<ConfigExportWindow>();
|
||||
win.titleContent = new GUIContent("Export");
|
||||
win.Show();
|
||||
}
|
||||
|
||||
|
||||
private static void LoadDic()
|
||||
{
|
||||
|
||||
m_Files = Directory.GetDirectories(m_ExcelPath, "*", SearchOption.TopDirectoryOnly);
|
||||
m_Choose = new bool[m_Files.Length];
|
||||
|
||||
for (int i = 0; i < m_Files.Length; i++)
|
||||
{
|
||||
m_Choose[i] = m_Files[i] == m_Bench;
|
||||
}
|
||||
|
||||
}
|
||||
private static void SaveLocalConfig()
|
||||
{
|
||||
for (int i = 0; i < m_Files.Length; i++)
|
||||
{
|
||||
if (m_Choose[i])
|
||||
{
|
||||
m_Bench = m_Files[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 保存数据
|
||||
EditorPrefs.SetString("m_ExcelPath", m_ExcelPath);
|
||||
EditorPrefs.SetString("m_Bench", m_Bench);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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("/");
|
||||
string 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();
|
||||
}
|
||||
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("数据表svn工程路径:");
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_ExcelPath = EditorGUILayout.TextField("", m_ExcelPath);
|
||||
if (GUILayout.Button("重新加载", GUILayout.Width(60f)))
|
||||
{
|
||||
LoadDic();
|
||||
}
|
||||
if (GUILayout.Button("打开目录", GUILayout.Width(60f)))
|
||||
{
|
||||
OpenDirectory(m_ExcelPath);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("请选择分支:");
|
||||
if(m_Files.Length != 0)
|
||||
{
|
||||
for (int i = 0; i < m_Files.Length; i++)
|
||||
{
|
||||
m_Choose[i] = EditorGUILayout.ToggleLeft(m_Files[i], m_Choose[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
EditorGUILayout.LabelField("未找到分支");
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
|
||||
if (GUILayout.Button("一键导表", GUILayout.Height(40f)))
|
||||
{
|
||||
SaveLocalConfig();
|
||||
// 导表
|
||||
DataConfigWindow.excelALLConfig(false, m_Bench + "/base_data");
|
||||
}
|
||||
if (GUILayout.Button("快速导表", GUILayout.Height(40f)))
|
||||
{
|
||||
// 保存数据
|
||||
SaveLocalConfig();
|
||||
// 导表
|
||||
DataConfigWindow.excelALLConfig(true, m_Bench + "/base_data");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class DataConfigWindow : EditorWindow
|
||||
{
|
||||
[MenuItem("Data Config/Window")]
|
||||
|
|
@ -35,11 +183,16 @@ namespace GameEditor.Core.DataConfig
|
|||
return inUse;
|
||||
}
|
||||
|
||||
private static void excelALLConfig(bool isIncrement)
|
||||
public static void excelALLConfig(bool isIncrement, string path)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(DataConfigSetting.execlDir) && Directory.Exists(DataConfigSetting.execlDir))
|
||||
if(path == "")
|
||||
{
|
||||
string[] files = Directory.GetFiles(DataConfigSetting.execlDir, "*.*", SearchOption.AllDirectories);
|
||||
path = DataConfigSetting.execlDir;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(path) && Directory.Exists(path))
|
||||
{
|
||||
string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
|
||||
DataConfigSetting setting = new DataConfigSetting();
|
||||
|
||||
object lockObj = new object();
|
||||
|
|
@ -85,7 +238,7 @@ namespace GameEditor.Core.DataConfig
|
|||
string luaPath = string.Format("{0}/{1}.lua", setting.clientOutputDir, luaName);
|
||||
if (File.Exists(luaPath))
|
||||
{
|
||||
Debug.LogError("有表被移除!正在清理Lua文件:" + luaName);
|
||||
UnityEngine.Debug.LogError("有表被移除!正在清理Lua文件:" + luaName);
|
||||
File.Delete(luaPath);
|
||||
}
|
||||
}
|
||||
|
|
@ -96,7 +249,7 @@ namespace GameEditor.Core.DataConfig
|
|||
AssetDatabase.Refresh();
|
||||
|
||||
time.Stop();
|
||||
Debug.LogError("耗时:" + time.ElapsedMilliseconds);
|
||||
UnityEngine.Debug.LogError("耗时:" + time.ElapsedMilliseconds);
|
||||
|
||||
EditorUtil.ShowSureDialog("配置表数据导入完毕!");
|
||||
}
|
||||
|
|
@ -109,7 +262,7 @@ namespace GameEditor.Core.DataConfig
|
|||
{
|
||||
if (IsFileInUse(item))
|
||||
{
|
||||
Debug.LogError("该表正在编辑,无法导出!:" + item);
|
||||
UnityEngine.Debug.LogError("该表正在编辑,无法导出!:" + item);
|
||||
lock (lockObj)
|
||||
{
|
||||
if (record.ContainsKey(item))
|
||||
|
|
@ -148,15 +301,15 @@ namespace GameEditor.Core.DataConfig
|
|||
}
|
||||
|
||||
[MenuItem("Data Config/一键导表")]
|
||||
private static void ExcelALLConfig()
|
||||
public static void ExcelALLConfig()
|
||||
{
|
||||
excelALLConfig(false);
|
||||
excelALLConfig(false, DataConfigSetting.execlDir);
|
||||
}
|
||||
|
||||
[MenuItem("Data Config/变化导表")]
|
||||
private static void ExcelChangeConfig()
|
||||
public static void ExcelChangeConfig()
|
||||
{
|
||||
excelALLConfig(true);
|
||||
excelALLConfig(true, DataConfigSetting.execlDir);
|
||||
}
|
||||
|
||||
private static void exportSheet(DataConfigSetting setting, string path, bool isIncrement)
|
||||
|
|
@ -184,23 +337,23 @@ namespace GameEditor.Core.DataConfig
|
|||
{
|
||||
if (isIncrement)
|
||||
{
|
||||
Debug.Log("该表有改动!正在导表:" + sheet.name);
|
||||
UnityEngine.Debug.Log("该表有改动!正在导表:" + sheet.name);
|
||||
}
|
||||
new DataToOptimizeLuaExporter(sheet, setting).Export();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("前端没有数据导出");
|
||||
UnityEngine.Debug.LogError("前端没有数据导出");
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.Log(e);
|
||||
UnityEngine.Debug.Log(e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("该表为纯后端表,无需导出!" + sheet.name);
|
||||
UnityEngine.Debug.Log("该表为纯后端表,无需导出!" + sheet.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue