235 lines
6.9 KiB
C#
235 lines
6.9 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
/// <summary>
|
||
/// UI页面测试脚本 - 用于测试页面UI的显示、隐藏和状态管理
|
||
/// 帮助调试和验证UIManager的功能
|
||
/// </summary>
|
||
public class UIPageTest : MonoBehaviour
|
||
{
|
||
[Header("测试按钮")]
|
||
public Button testShowPageButton; // 测试显示页面按钮
|
||
public Button testHideUIButton; // 测试隐藏UI按钮
|
||
public Button testShowPageAgainButton; // 测试再次显示页面按钮
|
||
public Button testForceShowButton; // 测试强制显示按钮
|
||
public Button testResetStateButton; // 测试重置状态按钮
|
||
public Button testDebugStateButton; // 测试调试状态按钮
|
||
|
||
[Header("测试配置")]
|
||
[SerializeField] private string testUIName = "背包出售"; // 测试的UI名称
|
||
|
||
private UIManager uiManager;
|
||
|
||
private void Start()
|
||
{
|
||
// 获取UI管理器引用
|
||
uiManager = UIManager.Instance;
|
||
|
||
if (uiManager == null)
|
||
{
|
||
Debug.LogError("UIManager未找到!");
|
||
return;
|
||
}
|
||
|
||
// 绑定按钮事件
|
||
BindButtonEvents();
|
||
|
||
Debug.Log($"UI页面测试脚本已启动,测试UI: {testUIName}");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绑定按钮事件
|
||
/// </summary>
|
||
private void BindButtonEvents()
|
||
{
|
||
if (testShowPageButton != null)
|
||
{
|
||
testShowPageButton.onClick.AddListener(TestShowPage);
|
||
testShowPageButton.GetComponentInChildren<Text>().text = $"显示页面: {testUIName}";
|
||
}
|
||
|
||
if (testHideUIButton != null)
|
||
{
|
||
testHideUIButton.onClick.AddListener(TestHideUI);
|
||
testHideUIButton.GetComponentInChildren<Text>().text = $"隐藏UI: {testUIName}";
|
||
}
|
||
|
||
if (testShowPageAgainButton != null)
|
||
{
|
||
testShowPageAgainButton.onClick.AddListener(TestShowPageAgain);
|
||
testShowPageAgainButton.GetComponentInChildren<Text>().text = $"再次显示: {testUIName}";
|
||
}
|
||
|
||
if (testForceShowButton != null)
|
||
{
|
||
testForceShowButton.onClick.AddListener(TestForceShow);
|
||
testForceShowButton.GetComponentInChildren<Text>().text = $"强制显示: {testUIName}";
|
||
}
|
||
|
||
if (testResetStateButton != null)
|
||
{
|
||
testResetStateButton.onClick.AddListener(TestResetState);
|
||
testResetStateButton.GetComponentInChildren<Text>().text = $"重置状态: {testUIName}";
|
||
}
|
||
|
||
if (testDebugStateButton != null)
|
||
{
|
||
testDebugStateButton.onClick.AddListener(TestDebugState);
|
||
testDebugStateButton.GetComponentInChildren<Text>().text = "调试状态";
|
||
}
|
||
|
||
Debug.Log("所有测试按钮事件已绑定");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 测试显示页面
|
||
/// </summary>
|
||
public void TestShowPage()
|
||
{
|
||
Debug.Log($"=== 测试1: 显示页面 {testUIName} ===");
|
||
|
||
if (uiManager != null)
|
||
{
|
||
uiManager.ShowPage(testUIName);
|
||
|
||
// 检查状态
|
||
bool isVisible = uiManager.IsPageVisible(testUIName);
|
||
Debug.Log($"页面 {testUIName} 显示后状态: {isVisible}");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 测试隐藏UI
|
||
/// </summary>
|
||
public void TestHideUI()
|
||
{
|
||
Debug.Log($"=== 测试2: 隐藏UI {testUIName} ===");
|
||
|
||
if (uiManager != null)
|
||
{
|
||
uiManager.HideUI(testUIName);
|
||
|
||
// 检查状态
|
||
bool isVisible = uiManager.IsPageVisible(testUIName);
|
||
Debug.Log($"UI {testUIName} 隐藏后状态: {isVisible}");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 测试再次显示页面
|
||
/// </summary>
|
||
public void TestShowPageAgain()
|
||
{
|
||
Debug.Log($"=== 测试3: 再次显示页面 {testUIName} ===");
|
||
|
||
if (uiManager != null)
|
||
{
|
||
uiManager.ShowPage(testUIName);
|
||
|
||
// 检查状态
|
||
bool isVisible = uiManager.IsPageVisible(testUIName);
|
||
Debug.Log($"页面 {testUIName} 再次显示后状态: {isVisible}");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 测试强制显示页面
|
||
/// </summary>
|
||
public void TestForceShow()
|
||
{
|
||
Debug.Log($"=== 测试4: 强制显示页面 {testUIName} ===");
|
||
|
||
if (uiManager != null)
|
||
{
|
||
uiManager.ForceShowPage(testUIName);
|
||
|
||
// 检查状态
|
||
bool isVisible = uiManager.IsPageVisible(testUIName);
|
||
Debug.Log($"页面 {testUIName} 强制显示后状态: {isVisible}");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 测试重置状态
|
||
/// </summary>
|
||
public void TestResetState()
|
||
{
|
||
Debug.Log($"=== 测试5: 重置页面状态 {testUIName} ===");
|
||
|
||
if (uiManager != null)
|
||
{
|
||
uiManager.ResetPageUIState(testUIName);
|
||
|
||
// 检查状态
|
||
bool isVisible = uiManager.IsPageVisible(testUIName);
|
||
Debug.Log($"页面 {testUIName} 重置后状态: {isVisible}");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 测试调试状态
|
||
/// </summary>
|
||
public void TestDebugState()
|
||
{
|
||
Debug.Log($"=== 测试6: 调试所有UI状态 ===");
|
||
|
||
if (uiManager != null)
|
||
{
|
||
uiManager.DebugPrintAllUIStates();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 完整测试流程
|
||
/// </summary>
|
||
public void RunFullTest()
|
||
{
|
||
Debug.Log("=== 开始完整测试流程 ===");
|
||
|
||
TestShowPage();
|
||
|
||
// 等待一帧
|
||
StartCoroutine(RunTestSequence());
|
||
}
|
||
|
||
private System.Collections.IEnumerator RunTestSequence()
|
||
{
|
||
yield return new WaitForSeconds(1f);
|
||
TestHideUI();
|
||
|
||
yield return new WaitForSeconds(1f);
|
||
TestShowPageAgain();
|
||
|
||
yield return new WaitForSeconds(1f);
|
||
TestDebugState();
|
||
|
||
Debug.Log("=== 完整测试流程结束 ===");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清理按钮事件
|
||
/// </summary>
|
||
private void OnDestroy()
|
||
{
|
||
if (testShowPageButton != null)
|
||
testShowPageButton.onClick.RemoveListener(TestShowPage);
|
||
|
||
if (testHideUIButton != null)
|
||
testHideUIButton.onClick.RemoveListener(TestHideUI);
|
||
|
||
if (testShowPageAgainButton != null)
|
||
testShowPageAgainButton.onClick.RemoveListener(TestShowPageAgain);
|
||
|
||
if (testForceShowButton != null)
|
||
testForceShowButton.onClick.RemoveListener(TestForceShow);
|
||
|
||
if (testResetStateButton != null)
|
||
testResetStateButton.onClick.RemoveListener(TestResetState);
|
||
|
||
if (testDebugStateButton != null)
|
||
testDebugStateButton.onClick.RemoveListener(TestDebugState);
|
||
|
||
Debug.Log("UI页面测试脚本已清理");
|
||
}
|
||
}
|