| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- 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<MapSceneLegendUI>();
- nameDisplay = FindFirstObjectByType<MapLocationNameDisplay>();
- featureManager = FindFirstObjectByType<GeographicFeatureManager>();
- 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<MonoBehaviour>(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<UIDocument>();
- 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<UIDocument>();
- 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<UIDocument>();
- 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("==========================");
- }
- }
|