using UnityEngine; using UnityEngine.UIElements; using System; using System.Collections; public class MapLocationDebugger : MonoBehaviour { [Header("Debug Controls")] public KeyCode debugKey = KeyCode.F9; public KeyCode toggleLegendKey = KeyCode.F10; public KeyCode toggleNamesKey = KeyCode.F11; public KeyCode refreshKey = KeyCode.F12; private MapSceneLegendUI legendUI; private MapLocationNameDisplay nameDisplay; private GeographicFeatureManager featureManager; void Start() { RefreshComponentReferences(); PrintDebugKeys(); } void RefreshComponentReferences() { legendUI = FindFirstObjectByType(); nameDisplay = FindFirstObjectByType(); featureManager = FindFirstObjectByType(); Debug.Log($"MapLocationDebugger: Found Legend UI: {legendUI != null}"); Debug.Log($"MapLocationDebugger: Found Name Display: {nameDisplay != null}"); Debug.Log($"MapLocationDebugger: Found Feature Manager: {featureManager != null}"); // If we can't find them, let's see what GameObjects exist if (nameDisplay == null || featureManager == null) { Debug.Log("=== SEARCHING FOR MISSING COMPONENTS ==="); var allObjects = FindObjectsByType(FindObjectsSortMode.None); foreach (var obj in allObjects) { if (obj is MapLocationNameDisplay || obj is GeographicFeatureManager) { Debug.Log($"Found {obj.GetType().Name} on GameObject: {obj.gameObject.name}"); } } Debug.Log("=== END SEARCH ==="); } } void Update() { if (Input.GetKeyDown(debugKey)) { PrintDetailedDebugInfo(); } if (Input.GetKeyDown(toggleLegendKey)) { if (legendUI != null) { legendUI.ToggleLegend(); Debug.Log("MapLocationDebugger: Toggled legend"); } } if (Input.GetKeyDown(toggleNamesKey)) { if (nameDisplay != null) { nameDisplay.showSettlementNames = !nameDisplay.showSettlementNames; nameDisplay.RefreshLocationNames(); Debug.Log($"MapLocationDebugger: Settlement names: {nameDisplay.showSettlementNames}"); } } if (Input.GetKeyDown(refreshKey)) { if (nameDisplay != null) { nameDisplay.RefreshLocationNames(); Debug.Log("MapLocationDebugger: Refreshed location names"); // Print immediate debug info StartCoroutine(PrintLabelsAfterDelay()); } } } System.Collections.IEnumerator PrintLabelsAfterDelay() { yield return new WaitForSeconds(0.1f); // Wait for refresh to complete if (nameDisplay != null) { var uiDoc = nameDisplay.GetComponent(); if (uiDoc?.rootVisualElement != null) { var mapContainer = uiDoc.rootVisualElement.Q("map-container"); if (mapContainer != null) { Debug.Log($"=== LABEL DEBUG: Container has {mapContainer.childCount} children ==="); for (int i = 0; i < Math.Min(10, mapContainer.childCount); i++) { var child = mapContainer.ElementAt(i); if (child is Label label) { var left = label.style.left.value.value; var top = label.style.top.value.value; var color = label.style.color.value; Debug.Log($"Label {i}: '{label.text}' at ({left:F1}, {top:F1}) color={color} visible={label.style.display.value}"); } } } } } } void PrintDebugKeys() { Debug.Log("=== MAP LOCATION DEBUGGER ==="); Debug.Log($"Press {debugKey} for detailed debug info"); Debug.Log($"Press {toggleLegendKey} to toggle legend"); Debug.Log($"Press {toggleNamesKey} to toggle settlement names"); Debug.Log($"Press {refreshKey} to refresh names"); Debug.Log("============================"); } void PrintDetailedDebugInfo() { // Refresh component references in case they were created after Start RefreshComponentReferences(); Debug.Log("=== DETAILED DEBUG INFO ==="); // Legend UI Info if (legendUI != null) { var uiDoc = legendUI.GetComponent(); Debug.Log($"Legend UI Document: {uiDoc != null}"); if (uiDoc != null) { Debug.Log($"Root Element: {uiDoc.rootVisualElement != null}"); if (uiDoc.rootVisualElement != null) { var legendContainer = uiDoc.rootVisualElement.Q("map-legend-container"); Debug.Log($"Legend Container Found: {legendContainer != null}"); if (legendContainer != null) { Debug.Log($"Legend Visible: {legendContainer.style.display.value}"); Debug.Log($"Legend Position: {legendContainer.style.position.value}"); Debug.Log($"Legend Size: {legendContainer.resolvedStyle.width}x{legendContainer.resolvedStyle.height}"); } } } } else { Debug.LogWarning("Legend UI not found!"); } // Name Display Info if (nameDisplay != null) { var uiDoc = nameDisplay.GetComponent(); Debug.Log($"Name Display UI Document: {uiDoc != null}"); if (uiDoc != null) { Debug.Log($"Root Element: {uiDoc.rootVisualElement != null}"); if (uiDoc.rootVisualElement != null) { var mapContainer = uiDoc.rootVisualElement.Q("map-container"); Debug.Log($"Map Container Found: {mapContainer != null}"); if (mapContainer != null) { Debug.Log($"Map Container Children: {mapContainer.childCount}"); Debug.Log($"Map Container Size: {mapContainer.resolvedStyle.width}x{mapContainer.resolvedStyle.height}"); Debug.Log($"Map Container World Bound: {mapContainer.worldBound}"); // List some children for debugging for (int i = 0; i < Math.Min(5, mapContainer.childCount); i++) { var child = mapContainer.ElementAt(i); if (child is Label label) { Debug.Log($" Child {i}: Label '{label.text}' at ({label.style.left.value.value:F1}, {label.style.top.value.value:F1}) - Color: {label.style.color.value}"); } } } } } Debug.Log($"Settlement Names Enabled: {nameDisplay.showSettlementNames}"); Debug.Log($"Forest Names Enabled: {nameDisplay.showForestNames}"); } else { Debug.LogWarning("Name Display not found!"); } // Feature Manager Info if (featureManager != null) { Debug.Log($"Geographic Features Count: {featureManager.GeographicFeatures.Count}"); if (featureManager.GeographicFeatures.Count > 0) { var feature = featureManager.GeographicFeatures[0]; Debug.Log($"Sample Feature: {feature.name} ({feature.type}) at {feature.centerPosition}"); } } else { Debug.LogWarning("Feature Manager not found!"); } Debug.Log("=========================="); } }