286 lines
7.5 KiB
C#
286 lines
7.5 KiB
C#
using UnityEditor;
|
||
using UnityEngine;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using Cysharp.Threading.Tasks;
|
||
using System;
|
||
using Luban.Editor;
|
||
|
||
public class ConfigInfo
|
||
{
|
||
public string Name;
|
||
public string DocID;
|
||
public bool Check;
|
||
public bool IsDownloadOK;
|
||
public bool IsError;
|
||
}
|
||
|
||
public class ConfigWindow : EditorWindow
|
||
{
|
||
|
||
|
||
|
||
|
||
|
||
private List<ConfigInfo> m_Configs;
|
||
|
||
private bool ExportClient;
|
||
private bool ExportServer;
|
||
private bool NeedDownload;
|
||
|
||
private Vector2 scrollPosition = Vector2.zero;
|
||
|
||
private string sid;
|
||
private string cookie;
|
||
const string DATA_TABLE_ASSEMBLY_REFERENCE_PATH = "Assets/Code/Scripts/Gameplay/DataTable/FrameWork.asmref";
|
||
const string DATA_TABLE_OUTSIDE_ASSEMBLY_REFERENCE_PATH = "Assets/Code/Scripts/Gameplay/FrameWork.asmref";
|
||
public static void ShowWindow()
|
||
{
|
||
try
|
||
{
|
||
ConfigWindow window = GetWindow(typeof(ConfigWindow)) as ConfigWindow;
|
||
window.titleContent = new GUIContent("自动化配置工具");
|
||
window.maximized = false;
|
||
window.minSize = new Vector2(300, 300);
|
||
|
||
int width = 600;
|
||
int height = 400;
|
||
var x = (Screen.currentResolution.width - width) / 2;
|
||
var y = (Screen.currentResolution.height - height) / 2;
|
||
Rect centerRect = new Rect(x, y, width, height);
|
||
window.position = centerRect;
|
||
|
||
window.InitData();
|
||
window.Show();
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Debug.LogError("ShowWindow catch exception, msg=" + e.Message);
|
||
}
|
||
}
|
||
|
||
public void InitData()
|
||
{
|
||
var dir = new DirectoryInfo(ConfigTools.CONFIG_DIR);
|
||
var combiePath = dir.FullName + "Datas/AConfigList.xlsx";
|
||
|
||
// var configPath = ConfigTools.CONFIG_DIR + "/config_list.txt";
|
||
// var lines = File.ReadAllLines(configPath);
|
||
|
||
m_Configs = new List<ConfigInfo>();
|
||
|
||
if (File.Exists(combiePath))
|
||
{
|
||
var excelDataList = ReadExcelList.ReadList(combiePath);
|
||
for (var i = 0; i < excelDataList.Count; i++)
|
||
{
|
||
var lineData = excelDataList[i];
|
||
var docName = lineData.excelName;
|
||
var docId = lineData.docId;
|
||
|
||
ConfigInfo ci = new ConfigInfo();
|
||
ci.Name = docName;
|
||
ci.DocID = docId;
|
||
ci.Check = true;
|
||
ci.IsDownloadOK = false;
|
||
|
||
m_Configs.Add(ci);
|
||
}
|
||
}
|
||
else {
|
||
Debug.LogError($"配置文件不存在,path={combiePath}");
|
||
}
|
||
|
||
|
||
|
||
ExportClient = true;
|
||
ExportServer = false;
|
||
|
||
NeedDownload = true;
|
||
|
||
sid = PlayerPrefs.GetString("ConfSid", "");
|
||
cookie = PlayerPrefs.GetString("ConfCookie", "");
|
||
}
|
||
|
||
void OnGUI()
|
||
{
|
||
try {
|
||
OnGUIContent();
|
||
}
|
||
catch
|
||
{
|
||
EditorGUILayout.LabelField("请关闭窗口重新打开");
|
||
}
|
||
|
||
}
|
||
|
||
void OnGUIContent()
|
||
{
|
||
|
||
GUILayout.Space(10);
|
||
|
||
sid = EditorGUILayout.TextField("SID:", sid);
|
||
cookie = EditorGUILayout.TextField("Cookie:", cookie);
|
||
|
||
if (GUILayout.Button("刷新Config List"))
|
||
{
|
||
PlayerPrefs.SetString("ConfSid", sid);
|
||
PlayerPrefs.SetString("ConfCookie", cookie);
|
||
|
||
ConfigTools.DownloadConfig();
|
||
InitData();
|
||
}
|
||
|
||
GUILayout.Space(10);
|
||
|
||
GUILayout.Label("配置列表:", EditorStyles.boldLabel);
|
||
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
|
||
for (int i = 0; i < m_Configs.Count; i++)
|
||
{
|
||
var name = m_Configs[i].Name;
|
||
if (m_Configs[i].Check)
|
||
{
|
||
if (m_Configs[i].IsDownloadOK)
|
||
name += "\t[下载成功]";
|
||
else if (m_Configs[i].IsError)
|
||
name += "\t[下载失败]";
|
||
}
|
||
|
||
m_Configs[i].Check = EditorGUILayout.ToggleLeft(name, m_Configs[i].Check);
|
||
}
|
||
EditorGUILayout.EndScrollView();
|
||
|
||
GUILayout.Space(10);
|
||
GUILayout.BeginHorizontal();
|
||
bool exportC = EditorGUILayout.ToggleLeft("导出客户端", ExportClient);
|
||
if (exportC != ExportClient)
|
||
{
|
||
if (exportC)
|
||
ExportServer = false;
|
||
|
||
ExportClient = exportC;
|
||
}
|
||
|
||
bool exportS = EditorGUILayout.ToggleLeft("导出服务器", ExportServer);
|
||
if (exportS != ExportServer)
|
||
{
|
||
if (exportS)
|
||
ExportClient = false;
|
||
|
||
ExportServer = exportS;
|
||
}
|
||
|
||
GUILayout.EndHorizontal();
|
||
GUILayout.Space(10);
|
||
NeedDownload = EditorGUILayout.ToggleLeft("下载选中配置", NeedDownload);
|
||
GUILayout.Space(10);
|
||
GUILayout.BeginHorizontal();
|
||
|
||
if (GUILayout.Button("全选"))
|
||
{
|
||
for (int i = 0; i < m_Configs.Count; i++)
|
||
{
|
||
m_Configs[i].Check = true;
|
||
}
|
||
}
|
||
|
||
if (GUILayout.Button("全不选"))
|
||
{
|
||
for (int i = 0; i < m_Configs.Count; i++)
|
||
{
|
||
m_Configs[i].Check = false;
|
||
}
|
||
}
|
||
|
||
GUILayout.EndHorizontal();
|
||
|
||
GUILayout.Space(10);
|
||
|
||
GUILayout.BeginHorizontal();
|
||
|
||
string buttonName = "开始";
|
||
|
||
if (NeedDownload)
|
||
{
|
||
buttonName += " 【下载配置】";
|
||
}
|
||
|
||
if (ExportClient)
|
||
{
|
||
buttonName += " 【导出到 Client】";
|
||
}
|
||
|
||
if (ExportServer)
|
||
{
|
||
buttonName += " 【导出到 Server】";
|
||
}
|
||
|
||
if (GUILayout.Button(buttonName))
|
||
{
|
||
if (string.IsNullOrEmpty(sid) || string.IsNullOrEmpty(cookie)) {
|
||
EditorUtility.DisplayDialog("配置工具", "请先配置sid和cookie", "OK");
|
||
return;
|
||
}
|
||
|
||
PlayerPrefs.SetString("ConfSid", sid);
|
||
PlayerPrefs.SetString("ConfCookie", cookie);
|
||
|
||
_AsyncAction();
|
||
}
|
||
|
||
GUILayout.EndHorizontal();
|
||
}
|
||
private void MoveDataTableAssemblyReference(bool isOut)
|
||
{
|
||
if (isOut)
|
||
AssetDatabase.MoveAsset(DATA_TABLE_ASSEMBLY_REFERENCE_PATH, DATA_TABLE_OUTSIDE_ASSEMBLY_REFERENCE_PATH);
|
||
else
|
||
AssetDatabase.MoveAsset(DATA_TABLE_OUTSIDE_ASSEMBLY_REFERENCE_PATH, DATA_TABLE_ASSEMBLY_REFERENCE_PATH);
|
||
}
|
||
private async void _AsyncAction()
|
||
{
|
||
MoveDataTableAssemblyReference(true);
|
||
try
|
||
{
|
||
bool needDownload = false;
|
||
for (int i = 0; i < m_Configs.Count; i++)
|
||
{
|
||
m_Configs[i].IsDownloadOK = false;
|
||
|
||
if (m_Configs[i].Check)
|
||
needDownload = true;
|
||
}
|
||
|
||
if (needDownload && NeedDownload)
|
||
{
|
||
await AutoConfig.DownloadConfig.AutoProcessConfig(m_Configs);
|
||
}
|
||
else
|
||
{
|
||
Debug.Log("当前没有需要下载的配置,已跳过");
|
||
}
|
||
|
||
await UniTask.Delay(100);
|
||
|
||
if (ExportClient)
|
||
{
|
||
var lubanAsset = AssetDatabase.LoadAssetAtPath<LubanExportConfig>("Assets/PhxhSDK/ThirdParty/Luban/Editor/Luban_Client.asset");
|
||
lubanAsset.Gen();
|
||
}
|
||
|
||
if (ExportServer)
|
||
ConfigTools.ConfigExportServer();
|
||
}
|
||
finally
|
||
{
|
||
MoveDataTableAssemblyReference(false);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
}
|