三国卡牌客户端基础资源仓库
yyl
4 天以前 cec146fc3fe287928e075c79ece20a20a9b16b20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
 
public class WindowTool : EditorWindow
{
    private string windowName = "";
    private int selectedUIIndex = -1;
    private List<string> uiNameList = new List<string>();
 
    [MenuItem("Tools/WindowTool")]
    public static void ShowWindow()
    {
        GetWindow<WindowTool>("WindowTool");
    }
 
    private void OnGUI()
    {
        EditorGUILayout.LabelField("窗口名称", EditorStyles.boldLabel);
 
        // 监听TextField变化
        string newWindowName = EditorGUILayout.TextField("windowName", windowName);
        if (newWindowName != windowName)
        {
            windowName = newWindowName;
            selectedUIIndex = -1; // 手动输入时取消选中
        }
 
        // 获取UIManager中的界面列表
        if (UIManager.Instance != null && UIManager.Instance.uiDict != null)
        {
            uiNameList.Clear();
            foreach (var kv in UIManager.Instance.uiDict)
            {
                uiNameList.Add(kv.Key);
            }
 
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("UI界面列表", EditorStyles.boldLabel);
 
            int clickedIndex = GUILayout.SelectionGrid(selectedUIIndex, uiNameList.ToArray(), 1);
 
            // 只要点击就覆盖windowName
            if (clickedIndex >= 0 && clickedIndex < uiNameList.Count)
            {
                selectedUIIndex = clickedIndex;
                windowName = uiNameList[selectedUIIndex];
            }
        }
        else
        {
            EditorGUILayout.HelpBox("UIManager.Instance 或 uiDict 未初始化", MessageType.Warning);
        }
 
        EditorGUILayout.Space();
 
        // 保留原有的打开和关闭按钮
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("打开"))
        {
            // 打开窗口逻辑
            UIManager.Instance.OpenWindow(windowName);
        }
        if (GUILayout.Button("关闭"))
        {
            // 关闭窗口逻辑
            UIManager.Instance.CloseWindow(windowName);
        }
        if (GUILayout.Button("关闭所有窗口再打开BattleWin"))
        {
            foreach (var win in uiNameList)
            {
                UIManager.Instance.CloseWindow(win);
            }
 
            UIManager.Instance.OpenWindow("BattleWin");
        }
 
        EditorGUILayout.EndHorizontal();
    }
}