using UnityEngine; namespace GameFramework { /// /// 调试工具 —— 在 Gameplay 场景中显示"胜利"和"失败"按钮, /// 点击后直接触发 GameManager.Win() 或 GameManager.GameOver()。 /// 测试完成后删除此脚本。 /// public class DebugResultButtons : MonoBehaviour { private string _debugLog = ""; private void OnGUI() { // 左上角显示调试信息(大字体,黄色) GUIStyle debugStyle = new GUIStyle(GUI.skin.label); debugStyle.fontSize = 18; debugStyle.normal.textColor = Color.yellow; debugStyle.fontStyle = FontStyle.Bold; // 调试信息背景 GUI.Box(new Rect(5, 5, 500, 85), ""); GUI.Label(new Rect(10, 10, 480, 25), $"GameManager.Instance: {(GameManager.Instance != null ? "【存在】" : "【null - 缺失!】")}", debugStyle); GUI.Label(new Rect(10, 35, 480, 25), $"GameState: {GameManager.GameState}", debugStyle); if (!string.IsNullOrEmpty(_debugLog)) { GUIStyle logStyle = new GUIStyle(GUI.skin.label); logStyle.fontSize = 16; logStyle.normal.textColor = Color.green; logStyle.fontStyle = FontStyle.Bold; GUI.Label(new Rect(10, 60, 580, 25), _debugLog, logStyle); } // 右上角显示两个按钮 float x = Screen.width - 220; float y = 10; GUIStyle style = new GUIStyle(GUI.skin.button); style.fontSize = 20; style.fontStyle = FontStyle.Bold; // 胜利按钮(绿色) GUI.backgroundColor = new Color(0.2f, 0.8f, 0.2f, 0.9f); if (GUI.Button(new Rect(x, y, 100, 50), "胜利", style)) { if (GameManager.Instance == null) { _debugLog = "[错误] GameManager.Instance 为 null!"; Debug.LogError("[DebugResultButtons] GameManager.Instance 为 null!"); } else { _debugLog = $"[调用] Win() - 时间: {Time.time:F2}"; Debug.Log("[DebugResultButtons] 调用 GameManager.Win()"); GameManager.Win(); } } // 失败按钮(红色) GUI.backgroundColor = new Color(0.8f, 0.2f, 0.2f, 0.9f); if (GUI.Button(new Rect(x + 110, y, 100, 50), "失败", style)) { if (GameManager.Instance == null) { _debugLog = "[错误] GameManager.Instance 为 null!"; Debug.LogError("[DebugResultButtons] GameManager.Instance 为 null!"); } else { _debugLog = $"[调用] GameOver() - 时间: {Time.time:F2}"; Debug.Log("[DebugResultButtons] 调用 GameManager.GameOver()"); GameManager.GameOver(); } } // 重置颜色 GUI.backgroundColor = Color.white; } } }