| New file |
| | |
| | | using UnityEngine; |
| | | using UnityEditor; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | |
| | | public class GMQuickPlayingEditor : EditorWindow |
| | | { |
| | | private string searchText = ""; |
| | | private string commandText = ""; |
| | | private Vector2 scrollPosition; |
| | | private List<ItemConfig> searchResults = new List<ItemConfig>(); |
| | | private int itemCount = 1; |
| | | |
| | | [MenuItem("Tools/GM快捷工具 &9")] |
| | | public static void ShowWindow() |
| | | { |
| | | GetWindow<GMQuickPlayingEditor>("GM快捷工具"); |
| | | } |
| | | |
| | | private void OnGUI() |
| | | { |
| | | GUILayout.BeginVertical("box"); |
| | | |
| | | // 搜索栏 |
| | | GUILayout.Label("物品搜索", EditorStyles.boldLabel); |
| | | GUILayout.BeginHorizontal(); |
| | | searchText = EditorGUILayout.TextField("搜索:", searchText); |
| | | if (GUILayout.Button("查询物品", GUILayout.Width(80))) |
| | | { |
| | | OnSearchItem(); |
| | | } |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | GUILayout.Space(10); |
| | | |
| | | // 搜索结果显示区域 |
| | | GUILayout.BeginHorizontal(); |
| | | GUILayout.Label($"搜索结果 ({searchResults.Count})", EditorStyles.boldLabel); |
| | | GUILayout.FlexibleSpace(); |
| | | if (GUILayout.Button("清空列表", GUILayout.Width(80))) |
| | | { |
| | | searchResults.Clear(); |
| | | } |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Height(200)); |
| | | GUILayout.BeginVertical("box"); |
| | | |
| | | if (searchResults.Count > 0) |
| | | { |
| | | foreach (var item in searchResults) |
| | | { |
| | | GUILayout.BeginHorizontal("box"); |
| | | GUILayout.Label($"ID: {item.ID}", GUILayout.Width(80)); |
| | | GUILayout.Label($"名称: {item.ItemName}", GUILayout.Width(150)); |
| | | GUILayout.Label($"等级: {item.LV}", GUILayout.Width(60)); |
| | | if (GUILayout.Button("选择", GUILayout.Width(60))) |
| | | { |
| | | OnSelectItem(item); |
| | | } |
| | | GUILayout.EndHorizontal(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | GUILayout.Label("搜索结果将在这里显示..."); |
| | | } |
| | | |
| | | GUILayout.EndVertical(); |
| | | GUILayout.EndScrollView(); |
| | | |
| | | GUILayout.Space(10); |
| | | |
| | | // 数量输入 |
| | | GUILayout.BeginHorizontal(); |
| | | GUILayout.Label("物品数量:", GUILayout.Width(80)); |
| | | itemCount = EditorGUILayout.IntField(itemCount, GUILayout.Width(100)); |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | GUILayout.Space(10); |
| | | |
| | | // GM命令编辑区域 |
| | | GUILayout.Label("GM命令", EditorStyles.boldLabel); |
| | | GUILayout.BeginVertical("box"); |
| | | commandText = EditorGUILayout.TextArea(commandText, GUILayout.Height(60)); |
| | | GUILayout.EndVertical(); |
| | | |
| | | GUILayout.Space(5); |
| | | |
| | | // 发送命令按钮 |
| | | GUILayout.BeginHorizontal(); |
| | | GUILayout.FlexibleSpace(); |
| | | if (GUILayout.Button("发送命令", GUILayout.Width(100), GUILayout.Height(30))) |
| | | { |
| | | OnSendCommand(); |
| | | } |
| | | if (GUILayout.Button("清空", GUILayout.Width(60), GUILayout.Height(30))) |
| | | { |
| | | commandText = ""; |
| | | } |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | GUILayout.Space(10); |
| | | |
| | | // 提示信息 |
| | | GUIStyle warningStyle = new GUIStyle(EditorStyles.helpBox); |
| | | warningStyle.normal.textColor = new Color(1f, 0.6f, 0f); |
| | | warningStyle.fontSize = 11; |
| | | EditorGUILayout.LabelField("⚠ 添加物品最好跟服务器确认过物品的存在后再添加", warningStyle); |
| | | |
| | | GUILayout.EndVertical(); |
| | | } |
| | | |
| | | private void OnSearchItem() |
| | | { |
| | | searchResults.Clear(); |
| | | |
| | | if (string.IsNullOrEmpty(searchText)) |
| | | { |
| | | Debug.Log("搜索文本为空"); |
| | | return; |
| | | } |
| | | |
| | | // 遍历 ItemConfig.dic 进行模糊搜索 |
| | | foreach (var kvp in ItemConfig.dic) |
| | | { |
| | | var item = kvp.Value; |
| | | if (!string.IsNullOrEmpty(item.ItemName) && |
| | | item.ItemName.Contains(searchText)) |
| | | { |
| | | searchResults.Add(item); |
| | | } |
| | | } |
| | | |
| | | // 按 ID 排序 |
| | | searchResults = searchResults.OrderBy(x => x.ID).ToList(); |
| | | |
| | | Debug.Log($"搜索物品: {searchText}, 找到 {searchResults.Count} 个结果"); |
| | | } |
| | | |
| | | private void OnSelectItem(ItemConfig item) |
| | | { |
| | | Debug.Log($"选择物品: {item.ItemName} (ID: {item.ID})"); |
| | | commandText = $"MakeItemCount {item.ID} {itemCount}"; |
| | | } |
| | | |
| | | private void OnSendCommand() |
| | | { |
| | | if (string.IsNullOrEmpty(commandText)) |
| | | { |
| | | Debug.LogWarning("命令为空,无法发送"); |
| | | return; |
| | | } |
| | | |
| | | Debug.Log("发送命令: " + commandText); |
| | | GMCmdManager.Instance.OnSendGMQuest(commandText); |
| | | GMCmdManager.Instance.SetRecordCmdlist(commandText); |
| | | } |
| | | } |