MapLocationDebugger.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using UnityEngine;
  2. using UnityEngine.UIElements;
  3. using System;
  4. using System.Collections;
  5. public class MapLocationDebugger : MonoBehaviour
  6. {
  7. [Header("Debug Controls")]
  8. public KeyCode debugKey = KeyCode.F9;
  9. public KeyCode toggleLegendKey = KeyCode.F10;
  10. public KeyCode toggleNamesKey = KeyCode.F11;
  11. public KeyCode refreshKey = KeyCode.F12;
  12. private MapSceneLegendUI legendUI;
  13. private MapLocationNameDisplay nameDisplay;
  14. private GeographicFeatureManager featureManager;
  15. void Start()
  16. {
  17. RefreshComponentReferences();
  18. PrintDebugKeys();
  19. }
  20. void RefreshComponentReferences()
  21. {
  22. legendUI = FindFirstObjectByType<MapSceneLegendUI>();
  23. nameDisplay = FindFirstObjectByType<MapLocationNameDisplay>();
  24. featureManager = FindFirstObjectByType<GeographicFeatureManager>();
  25. Debug.Log($"MapLocationDebugger: Found Legend UI: {legendUI != null}");
  26. Debug.Log($"MapLocationDebugger: Found Name Display: {nameDisplay != null}");
  27. Debug.Log($"MapLocationDebugger: Found Feature Manager: {featureManager != null}");
  28. // If we can't find them, let's see what GameObjects exist
  29. if (nameDisplay == null || featureManager == null)
  30. {
  31. Debug.Log("=== SEARCHING FOR MISSING COMPONENTS ===");
  32. var allObjects = FindObjectsByType<MonoBehaviour>(FindObjectsSortMode.None);
  33. foreach (var obj in allObjects)
  34. {
  35. if (obj is MapLocationNameDisplay || obj is GeographicFeatureManager)
  36. {
  37. Debug.Log($"Found {obj.GetType().Name} on GameObject: {obj.gameObject.name}");
  38. }
  39. }
  40. Debug.Log("=== END SEARCH ===");
  41. }
  42. }
  43. void Update()
  44. {
  45. if (Input.GetKeyDown(debugKey))
  46. {
  47. PrintDetailedDebugInfo();
  48. }
  49. if (Input.GetKeyDown(toggleLegendKey))
  50. {
  51. if (legendUI != null)
  52. {
  53. legendUI.ToggleLegend();
  54. Debug.Log("MapLocationDebugger: Toggled legend");
  55. }
  56. }
  57. if (Input.GetKeyDown(toggleNamesKey))
  58. {
  59. if (nameDisplay != null)
  60. {
  61. nameDisplay.showSettlementNames = !nameDisplay.showSettlementNames;
  62. nameDisplay.RefreshLocationNames();
  63. Debug.Log($"MapLocationDebugger: Settlement names: {nameDisplay.showSettlementNames}");
  64. }
  65. }
  66. if (Input.GetKeyDown(refreshKey))
  67. {
  68. if (nameDisplay != null)
  69. {
  70. nameDisplay.RefreshLocationNames();
  71. Debug.Log("MapLocationDebugger: Refreshed location names");
  72. // Print immediate debug info
  73. StartCoroutine(PrintLabelsAfterDelay());
  74. }
  75. }
  76. }
  77. System.Collections.IEnumerator PrintLabelsAfterDelay()
  78. {
  79. yield return new WaitForSeconds(0.1f); // Wait for refresh to complete
  80. if (nameDisplay != null)
  81. {
  82. var uiDoc = nameDisplay.GetComponent<UIDocument>();
  83. if (uiDoc?.rootVisualElement != null)
  84. {
  85. var mapContainer = uiDoc.rootVisualElement.Q("map-container");
  86. if (mapContainer != null)
  87. {
  88. Debug.Log($"=== LABEL DEBUG: Container has {mapContainer.childCount} children ===");
  89. for (int i = 0; i < Math.Min(10, mapContainer.childCount); i++)
  90. {
  91. var child = mapContainer.ElementAt(i);
  92. if (child is Label label)
  93. {
  94. var left = label.style.left.value.value;
  95. var top = label.style.top.value.value;
  96. var color = label.style.color.value;
  97. Debug.Log($"Label {i}: '{label.text}' at ({left:F1}, {top:F1}) color={color} visible={label.style.display.value}");
  98. }
  99. }
  100. }
  101. }
  102. }
  103. }
  104. void PrintDebugKeys()
  105. {
  106. Debug.Log("=== MAP LOCATION DEBUGGER ===");
  107. Debug.Log($"Press {debugKey} for detailed debug info");
  108. Debug.Log($"Press {toggleLegendKey} to toggle legend");
  109. Debug.Log($"Press {toggleNamesKey} to toggle settlement names");
  110. Debug.Log($"Press {refreshKey} to refresh names");
  111. Debug.Log("============================");
  112. }
  113. void PrintDetailedDebugInfo()
  114. {
  115. // Refresh component references in case they were created after Start
  116. RefreshComponentReferences();
  117. Debug.Log("=== DETAILED DEBUG INFO ===");
  118. // Legend UI Info
  119. if (legendUI != null)
  120. {
  121. var uiDoc = legendUI.GetComponent<UIDocument>();
  122. Debug.Log($"Legend UI Document: {uiDoc != null}");
  123. if (uiDoc != null)
  124. {
  125. Debug.Log($"Root Element: {uiDoc.rootVisualElement != null}");
  126. if (uiDoc.rootVisualElement != null)
  127. {
  128. var legendContainer = uiDoc.rootVisualElement.Q("map-legend-container");
  129. Debug.Log($"Legend Container Found: {legendContainer != null}");
  130. if (legendContainer != null)
  131. {
  132. Debug.Log($"Legend Visible: {legendContainer.style.display.value}");
  133. Debug.Log($"Legend Position: {legendContainer.style.position.value}");
  134. Debug.Log($"Legend Size: {legendContainer.resolvedStyle.width}x{legendContainer.resolvedStyle.height}");
  135. }
  136. }
  137. }
  138. }
  139. else
  140. {
  141. Debug.LogWarning("Legend UI not found!");
  142. }
  143. // Name Display Info
  144. if (nameDisplay != null)
  145. {
  146. var uiDoc = nameDisplay.GetComponent<UIDocument>();
  147. Debug.Log($"Name Display UI Document: {uiDoc != null}");
  148. if (uiDoc != null)
  149. {
  150. Debug.Log($"Root Element: {uiDoc.rootVisualElement != null}");
  151. if (uiDoc.rootVisualElement != null)
  152. {
  153. var mapContainer = uiDoc.rootVisualElement.Q("map-container");
  154. Debug.Log($"Map Container Found: {mapContainer != null}");
  155. if (mapContainer != null)
  156. {
  157. Debug.Log($"Map Container Children: {mapContainer.childCount}");
  158. Debug.Log($"Map Container Size: {mapContainer.resolvedStyle.width}x{mapContainer.resolvedStyle.height}");
  159. Debug.Log($"Map Container World Bound: {mapContainer.worldBound}");
  160. // List some children for debugging
  161. for (int i = 0; i < Math.Min(5, mapContainer.childCount); i++)
  162. {
  163. var child = mapContainer.ElementAt(i);
  164. if (child is Label label)
  165. {
  166. 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}");
  167. }
  168. }
  169. }
  170. }
  171. }
  172. Debug.Log($"Settlement Names Enabled: {nameDisplay.showSettlementNames}");
  173. Debug.Log($"Forest Names Enabled: {nameDisplay.showForestNames}");
  174. }
  175. else
  176. {
  177. Debug.LogWarning("Name Display not found!");
  178. }
  179. // Feature Manager Info
  180. if (featureManager != null)
  181. {
  182. Debug.Log($"Geographic Features Count: {featureManager.GeographicFeatures.Count}");
  183. if (featureManager.GeographicFeatures.Count > 0)
  184. {
  185. var feature = featureManager.GeographicFeatures[0];
  186. Debug.Log($"Sample Feature: {feature.name} ({feature.type}) at {feature.centerPosition}");
  187. }
  188. }
  189. else
  190. {
  191. Debug.LogWarning("Feature Manager not found!");
  192. }
  193. Debug.Log("==========================");
  194. }
  195. }