using UnityEngine; using TMPro; namespace Minigames.BirdPooper { /// /// On-screen debug display for Bird Pooper minigame diagnostics. /// Shows critical values that might differ between PC and mobile platforms. /// public class BirdPooperDebugDisplay : MonoBehaviour { [Header("References")] [SerializeField] private BirdPlayerController birdController; [SerializeField] private TextMeshProUGUI debugText; [Header("Settings")] [SerializeField] private bool showDebugDisplay = true; [SerializeField] private float updateInterval = 0.1f; // Update display every 0.1 seconds private float _nextUpdateTime; private int _frameCount; private float _minDeltaTime = float.MaxValue; private float _maxDeltaTime = 0f; private float _avgDeltaTime; private float _deltaTimeSum; private void Start() { if (debugText == null) { Debug.LogError("[BirdPooperDebugDisplay] Debug text reference not assigned!"); enabled = false; return; } if (birdController == null) { birdController = FindFirstObjectByType(); if (birdController == null) { Debug.LogError("[BirdPooperDebugDisplay] Could not find BirdPlayerController!"); enabled = false; return; } } debugText.gameObject.SetActive(showDebugDisplay); _nextUpdateTime = Time.time + updateInterval; } private void Update() { if (!showDebugDisplay || debugText == null) return; // Track deltaTime statistics _frameCount++; _deltaTimeSum += Time.deltaTime; if (Time.deltaTime < _minDeltaTime) _minDeltaTime = Time.deltaTime; if (Time.deltaTime > _maxDeltaTime) _maxDeltaTime = Time.deltaTime; _avgDeltaTime = _deltaTimeSum / _frameCount; // Update display at specified interval if (Time.time >= _nextUpdateTime) { UpdateDebugDisplay(); _nextUpdateTime = Time.time + updateInterval; } } private void UpdateDebugDisplay() { if (debugText == null) return; // Get settings from the bird controller via reflection (hacky but works for debug) var settingsField = typeof(BirdPlayerController).GetField("_settings", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); var settings = settingsField?.GetValue(birdController) as Core.Settings.IBirdPooperSettings; var velocityField = typeof(BirdPlayerController).GetField("_verticalVelocity", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); float velocity = velocityField != null ? (float)velocityField.GetValue(birdController) : 0f; var rbField = typeof(BirdPlayerController).GetField("_rb", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); var rb = rbField?.GetValue(birdController) as Rigidbody2D; // Calculate actual FPS float fps = _avgDeltaTime > 0 ? 1f / _avgDeltaTime : 0f; // Build debug string string debugInfo = "BIRD POOPER DEBUG\n"; debugInfo += "───────────\n"; debugInfo += $"PLATFORM: {Application.platform}\n"; debugInfo += $"TIME SCALE: {Time.timeScale:F2}\n"; debugInfo += $"TARGET FPS: {Application.targetFrameRate}\n"; debugInfo += $"ACTUAL FPS: {fps:F1}\n"; debugInfo += "───────────\n"; debugInfo += $"ΔTime: {Time.deltaTime:F4}s\n"; debugInfo += $"ΔTime Min: {_minDeltaTime:F4}s\n"; debugInfo += $"ΔTime Max: {_maxDeltaTime:F4}s\n"; debugInfo += $"ΔTime Avg: {_avgDeltaTime:F4}s\n"; debugInfo += $"Fixed ΔT: {Time.fixedDeltaTime:F4}s\n"; debugInfo += "───────────\n"; if (settings != null) { debugInfo += $"Gravity: {settings.Gravity}\n"; debugInfo += $"Flap Force: {settings.FlapForce}\n"; debugInfo += $"Max Fall: {settings.MaxFallSpeed}\n"; debugInfo += "───────────\n"; } debugInfo += $"Velocity: {velocity:F2}\n"; if (rb != null) { debugInfo += $"Position Y: {rb.position.y:F2}\n"; } debugInfo += $"Dead: {birdController.IsDead}\n"; debugText.text = debugInfo; } /// /// Toggle debug display visibility - can be called from UI button /// public void ToggleDisplay() { showDebugDisplay = !showDebugDisplay; if (debugText != null) { debugText.gameObject.SetActive(showDebugDisplay); } } } }