| | |
| | | using UnityEditor; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.IO; |
| | | |
| | | public class GMQuickPlayingEditor : EditorWindow |
| | | { |
| | | private string searchText = ""; |
| | | private string commandText = ""; |
| | | private Vector2 scrollPosition; |
| | | private Vector2 reportScrollPosition; |
| | | private List<ItemConfig> searchResults = new List<ItemConfig>(); |
| | | private int itemCount = 1; |
| | | private bool isBattlePaused = false; |
| | | |
| | | // 战报相关 |
| | | private string reportFilePath = ""; |
| | | private string[] reportFiles = new string[0]; |
| | | private int selectedReportIndex = 0; |
| | | |
| | | [MenuItem("Tools/GM快捷工具 &9")] |
| | | public static void ShowWindow() |
| | | { |
| | | GetWindow<GMQuickPlayingEditor>("GM快捷工具"); |
| | | } |
| | | |
| | | private void OnEnable() |
| | | { |
| | | RefreshReportList(); |
| | | } |
| | | |
| | | private void OnGUI() |
| | |
| | | warningStyle.fontSize = 11; |
| | | EditorGUILayout.LabelField("⚠ 添加物品最好跟服务器确认过物品的存在后再添加", warningStyle); |
| | | |
| | | GUILayout.Space(10); |
| | | |
| | | // 战报浏览区域 |
| | | GUILayout.Label("战报浏览", EditorStyles.boldLabel); |
| | | GUILayout.BeginVertical("box"); |
| | | |
| | | GUILayout.BeginHorizontal(); |
| | | if (GUILayout.Button("刷新战报列表", GUILayout.Width(120))) |
| | | { |
| | | RefreshReportList(); |
| | | } |
| | | if (GUILayout.Button("打开战报文件夹", GUILayout.Width(120))) |
| | | { |
| | | OpenReportFolder(); |
| | | } |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | GUILayout.Space(5); |
| | | |
| | | if (reportFiles.Length > 0) |
| | | { |
| | | reportScrollPosition = GUILayout.BeginScrollView(reportScrollPosition, GUILayout.Height(150)); |
| | | |
| | | for (int i = 0; i < reportFiles.Length; i++) |
| | | { |
| | | GUILayout.BeginHorizontal("box"); |
| | | string fileName = Path.GetFileName(reportFiles[i]); |
| | | GUILayout.Label(fileName, GUILayout.Width(300)); |
| | | |
| | | if (GUILayout.Button("加载并Distribute", GUILayout.Width(60))) |
| | | { |
| | | LoadReport(reportFiles[i]); |
| | | } |
| | | |
| | | |
| | | GUILayout.EndHorizontal(); |
| | | } |
| | | |
| | | GUILayout.EndScrollView(); |
| | | } |
| | | else |
| | | { |
| | | GUILayout.Label("未找到战报文件(.bytes)"); |
| | | } |
| | | |
| | | GUILayout.EndVertical(); |
| | | |
| | | GUILayout.Space(10); |
| | | |
| | | // 暂停/开始战斗按钮 |
| | | GUILayout.BeginHorizontal(); |
| | | GUILayout.FlexibleSpace(); |
| | | string buttonText = isBattlePaused ? "开始当前战斗" : "暂停当前战斗"; |
| | | if (GUILayout.Button(buttonText, GUILayout.Width(120), GUILayout.Height(30))) |
| | | { |
| | | OnPauseBattle(); |
| | | } |
| | | GUILayout.FlexibleSpace(); |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | GUILayout.EndVertical(); |
| | | } |
| | | |
| | | private void RefreshReportList() |
| | | { |
| | | string reportFolder = Application.dataPath + "/../BattleReport/"; |
| | | if (Directory.Exists(reportFolder)) |
| | | { |
| | | reportFiles = Directory.GetFiles(reportFolder, "*.bytes"); |
| | | Debug.Log($"找到 {reportFiles.Length} 个战报文件"); |
| | | } |
| | | else |
| | | { |
| | | Directory.CreateDirectory(reportFolder); |
| | | reportFiles = new string[0]; |
| | | Debug.Log("创建战报文件夹: " + reportFolder); |
| | | } |
| | | } |
| | | |
| | | private void OpenReportFolder() |
| | | { |
| | | string reportFolder = Application.dataPath + "/../BattleReport/"; |
| | | if (!Directory.Exists(reportFolder)) |
| | | { |
| | | Directory.CreateDirectory(reportFolder); |
| | | } |
| | | EditorUtility.RevealInFinder(reportFolder); |
| | | } |
| | | |
| | | private void LoadReport(string filePath) |
| | | { |
| | | if (!File.Exists(filePath)) |
| | | { |
| | | Debug.LogError("战报文件不存在: " + filePath); |
| | | return; |
| | | } |
| | | |
| | | reportFilePath = filePath; |
| | | Debug.Log("已加载战报: " + Path.GetFileName(filePath)); |
| | | |
| | | HB430_tagSCTurnFightReport hB430_TagSCTurnFightReport = new HB430_tagSCTurnFightReport(); |
| | | byte[] vBytes = File.ReadAllBytes(filePath); |
| | | hB430_TagSCTurnFightReport.ReadFromBytes(vBytes); |
| | | PackageRegedit.Distribute(hB430_TagSCTurnFightReport); |
| | | } |
| | | |
| | | private string ExtractGuidFromFileName(string fileName) |
| | | { |
| | | // 从文件名中提取 GUID |
| | | // 格式: B430_ReportBytes_{GUID}_{DateTime} |
| | | string[] parts = fileName.Split('_'); |
| | | if (parts.Length >= 3) |
| | | { |
| | | return parts[2]; // 返回 GUID 部分 |
| | | } |
| | | return "unknown_guid"; |
| | | } |
| | | |
| | | private void OnSearchItem() |
| | |
| | | GMCmdManager.Instance.OnSendGMQuest(commandText); |
| | | GMCmdManager.Instance.SetRecordCmdlist(commandText); |
| | | } |
| | | |
| | | private void OnPauseBattle() |
| | | { |
| | | for (int i = 0; i < BattleConst.BattleWindows.Count; i++) |
| | | { |
| | | var win = UIManager.Instance.GetUI(BattleConst.BattleWindows[i].Name); |
| | | if (win != null && win.IsActive()) |
| | | { |
| | | // 使用反射获取 battleField 字段 |
| | | var battleFieldField = win.GetType().GetField("battleField", |
| | | System.Reflection.BindingFlags.NonPublic | |
| | | System.Reflection.BindingFlags.Instance); |
| | | |
| | | if (battleFieldField != null) |
| | | { |
| | | var battleField = battleFieldField.GetValue(win) as BattleField; |
| | | if (battleField != null) |
| | | { |
| | | battleField.IsPause = !battleField.IsPause; |
| | | isBattlePaused = battleField.IsPause; |
| | | Debug.Log($"战斗暂停状态切换: {battleField.IsPause}"); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | Debug.LogWarning("未找到激活的战斗窗口或 battleField 为空"); |
| | | } |
| | | } |