320 lines
8.7 KiB
C#
320 lines
8.7 KiB
C#
using UnityEditor;
|
||
using UnityEngine;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using Cysharp.Threading.Tasks;
|
||
using System;
|
||
using AutoConfig;
|
||
using Luban.Editor;
|
||
using UnityEngine.Networking;
|
||
|
||
public class ConfigInfo
|
||
{
|
||
public string Name;
|
||
public string DocID;
|
||
public bool Check;
|
||
}
|
||
|
||
public class DownloadConfigData
|
||
{
|
||
public string excelName;
|
||
public bool isDone
|
||
{
|
||
get
|
||
{
|
||
return downloader.isFinished;
|
||
}
|
||
}
|
||
public WPExcelDownloader downloader;
|
||
}
|
||
|
||
public class ConfigWindow : EditorWindow
|
||
{
|
||
|
||
private bool ExportClient;
|
||
private bool ExportServer;
|
||
private bool NeedDownload;
|
||
private bool _isGenMixKey;
|
||
|
||
private bool _isDownloading;
|
||
|
||
private Vector2 scrollPosition = Vector2.zero;
|
||
private Vector2 _scrollPositionDownload = Vector2.zero;
|
||
|
||
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 const string DATA_STRING_LOCALIZE_CN = "Assets/Config/Data/Localize/CN";
|
||
public const string DATA_STRING_LOCALIZE_EN = "Assets/Config/Data/Localize/EN";
|
||
|
||
/// <summary>
|
||
/// 0 未知
|
||
/// 1 checking
|
||
/// 2 ok
|
||
/// 3 failed
|
||
/// </summary>
|
||
private int _authState = 0;
|
||
|
||
public static void ShowWindow()
|
||
{
|
||
|
||
var window = GetWindow<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._authState = 0;
|
||
window.InitData();
|
||
window.Show();
|
||
window.Focus();
|
||
|
||
}
|
||
|
||
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;
|
||
//
|
||
// m_Configs.Add(ci);
|
||
// }
|
||
// m_Configs.Sort((a,
|
||
// b) => a.Name.CompareTo(b.Name));
|
||
// }
|
||
// else
|
||
// {
|
||
// Debug.LogError($"配置文件不存在,path={combiePath}");
|
||
// }
|
||
|
||
ExportClient = true;
|
||
ExportServer = false;
|
||
_isGenMixKey = false;
|
||
|
||
NeedDownload = false;
|
||
|
||
cookie = EditorPrefs.GetString("ConfCookie", "");
|
||
}
|
||
|
||
void OnGUI()
|
||
{
|
||
// if (m_Configs == null)
|
||
// {
|
||
// InitData();
|
||
// }
|
||
_OnGUIContent();
|
||
}
|
||
|
||
private async void _StartChecking()
|
||
{
|
||
if (string.IsNullOrEmpty(cookie)) return;
|
||
_authState = 1;
|
||
|
||
var downLoader = new WPExcelDownloader("AConfigList.xlsx",
|
||
"e3_AXoAQAavAFIi9riMuy9Q5CMxcHei1", cookie);//e3_AQIA8QbmAKEFwoGRFPhT9uizRsOaA
|
||
Debug.Log("开始检查授权");
|
||
|
||
var checkResult = await downLoader.OnlyCheck();
|
||
if (checkResult)
|
||
{
|
||
Debug.Log("授权成功");
|
||
_authState = 2;
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("授权失败");
|
||
_authState = 3;
|
||
}
|
||
}
|
||
|
||
|
||
private void _ShowSIDConfig()
|
||
{
|
||
cookie = EditorGUILayout.TextField("Cookie:", cookie);
|
||
GUILayout.BeginHorizontal();
|
||
if (GUILayout.Button("重新检查授权"))
|
||
{
|
||
_StartChecking();
|
||
}
|
||
if (GUILayout.Button("打开授权网页"))
|
||
{
|
||
_OpenAuthWindow();
|
||
}
|
||
GUILayout.EndHorizontal();
|
||
}
|
||
|
||
private void _OpenAuthWindow()
|
||
{
|
||
var url = "https://doc.weixin.qq.com/sheet/e3_AXoAQAavAFI2YSsTvvuQ9aS06iieP";
|
||
Application.OpenURL(url);
|
||
}
|
||
|
||
private void _ShowAuthState()
|
||
{
|
||
switch (_authState)
|
||
{
|
||
case 0:
|
||
// 未知
|
||
if (string.IsNullOrEmpty(cookie))
|
||
{
|
||
// 未配置
|
||
EditorGUILayout.HelpBox("请先配置sid和cookie", MessageType.Error);
|
||
|
||
_ShowSIDConfig();
|
||
}
|
||
else
|
||
{
|
||
// 已配置
|
||
_ShowSIDConfig();
|
||
_StartChecking();
|
||
}
|
||
break;
|
||
case 1:
|
||
EditorGUILayout.HelpBox("检查授权中", MessageType.Warning);
|
||
|
||
_ShowSIDConfig();
|
||
break;
|
||
case 2:
|
||
EditorGUILayout.HelpBox("授权成功", MessageType.Info);
|
||
|
||
_ShowSIDConfig();
|
||
break;
|
||
|
||
case 3:
|
||
EditorGUILayout.HelpBox("授权失败", MessageType.Error);
|
||
|
||
_ShowSIDConfig();
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void _ShowGenBtn()
|
||
{
|
||
|
||
}
|
||
|
||
private void _OnGUIContent()
|
||
{
|
||
|
||
GUILayout.Space(10);
|
||
EditorGUILayout.BeginHorizontal();
|
||
ExportClient = EditorGUILayout.ToggleLeft("导出客户端", ExportClient);
|
||
ExportServer = EditorGUILayout.ToggleLeft("导出服务端", ExportServer);
|
||
EditorGUILayout.EndHorizontal();
|
||
|
||
GUILayout.Space(10);
|
||
EditorGUILayout.BeginHorizontal();
|
||
_isGenMixKey = EditorGUILayout.ToggleLeft("导出时生成MixKey", _isGenMixKey);
|
||
EditorGUILayout.EndHorizontal();
|
||
|
||
GUILayout.BeginHorizontal();
|
||
|
||
if (GUILayout.Button("开始导出", GUILayout.Height(40)))
|
||
{
|
||
_DoExport();
|
||
}
|
||
if (GUILayout.Button("打开Excel路径", GUILayout.Height(40)))
|
||
{
|
||
Application.OpenURL("file://" + ConfigTools.CONFIG_DIR);
|
||
}
|
||
|
||
GUILayout.EndHorizontal();
|
||
|
||
GUILayout.Space(10);
|
||
if (GUILayout.Button("生成MixKey配置"))
|
||
{
|
||
_GenMixKeyConfig();
|
||
//GenMixKeyTool.ReplaceMixKey();
|
||
}
|
||
|
||
}
|
||
|
||
private void _DoExport()
|
||
{
|
||
|
||
if (ExportClient)
|
||
{
|
||
var lubanAsset = AssetDatabase.LoadAssetAtPath<LubanExportConfig>("Assets/Editor/Tools/Luban_Client.asset");
|
||
var lubanLocalizeCNAsset = AssetDatabase.LoadAssetAtPath<LubanExportConfig>("Assets/Editor/Tools/Luban_Client_CN.asset");
|
||
var lubanLocalizeENAsset = AssetDatabase.LoadAssetAtPath<LubanExportConfig>("Assets/Editor/Tools/Luban_Client_EN.asset");
|
||
var genSuccess = lubanAsset.Gen();
|
||
var genCNSuccess = lubanLocalizeCNAsset.Gen();
|
||
var genENSuccess = lubanLocalizeENAsset.Gen();
|
||
_ClearLocalizeDir();
|
||
|
||
if (genSuccess && _isGenMixKey)
|
||
{
|
||
_GenMixKeyConfig();
|
||
}
|
||
}
|
||
|
||
if (ExportServer)
|
||
{
|
||
var lubanAsset = AssetDatabase.LoadAssetAtPath<LubanExportConfig>("Assets/Editor/Tools/Luban_Server.asset");
|
||
lubanAsset.Gen();
|
||
}
|
||
|
||
}
|
||
|
||
private void _GenMixKeyConfig()
|
||
{
|
||
//GenMixKeyTool.GenMixKeyFile();
|
||
MixKeyGenJson.IsGenJsonProcess = true;
|
||
GenMixKeyTool.GenMixKeyJson();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清理本地化生成的无用json文件
|
||
/// </summary>
|
||
private void _ClearLocalizeDir()
|
||
{
|
||
if (Directory.Exists(DATA_STRING_LOCALIZE_CN))
|
||
{
|
||
foreach (var file in Directory.GetFileSystemEntries(DATA_STRING_LOCALIZE_CN))
|
||
{
|
||
if (!file.Contains("stringcfg"))
|
||
{
|
||
File.Delete(file);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (Directory.Exists(DATA_STRING_LOCALIZE_EN))
|
||
{
|
||
foreach (var file in Directory.GetFileSystemEntries(DATA_STRING_LOCALIZE_EN))
|
||
{
|
||
if (!file.Contains("stringcfg"))
|
||
{
|
||
File.Delete(file);
|
||
}
|
||
}
|
||
}
|
||
|
||
AssetDatabase.Refresh();
|
||
}
|
||
}
|