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();
|
}
|
}
|