MapLocationSystemInitializer.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. using UnityEngine;
  2. using System.Collections;
  3. [System.Serializable]
  4. public class MapLocationSystemSettings
  5. {
  6. [Header("System Settings")]
  7. public bool enableDebugMode = true;
  8. public bool autoGenerateFeatures = true;
  9. public bool showLegendOnStart = true;
  10. public bool showSettlementNamesOnStart = true;
  11. [Header("Name Display Settings")]
  12. public bool showForestNames = true;
  13. public bool showLakeNames = true;
  14. public bool showPlainNames = false;
  15. public bool showMountainNames = true;
  16. public bool showRiverNames = true;
  17. }
  18. public class MapLocationSystemInitializer : MonoBehaviour
  19. {
  20. [Header("System Configuration")]
  21. public MapLocationSystemSettings settings = new MapLocationSystemSettings();
  22. [Header("Component References (Auto-found if null)")]
  23. public GeographicFeatureManager featureManager;
  24. public MapLocationNameDisplay nameDisplay;
  25. public MapSceneLegendUI legendUI;
  26. public MapMaker2 mapMaker;
  27. void Start()
  28. {
  29. StartCoroutine(InitializeSystemDelayed());
  30. }
  31. IEnumerator InitializeSystemDelayed()
  32. {
  33. // Wait a frame for all components to awake
  34. yield return null;
  35. Debug.Log("MapLocationSystemInitializer: Starting system initialization...");
  36. // Find components if not assigned
  37. FindComponents();
  38. // Configure debug modes
  39. ConfigureDebugModes();
  40. // Wait for map generation if needed
  41. yield return StartCoroutine(WaitForMapGeneration());
  42. // Initialize geographic features
  43. yield return StartCoroutine(InitializeGeographicFeatures());
  44. // Initialize name display
  45. yield return StartCoroutine(InitializeNameDisplay());
  46. // Initialize legend UI
  47. yield return StartCoroutine(InitializeLegendUI());
  48. // Connect legend to name display
  49. ConnectLegendToNameDisplay();
  50. Debug.Log("MapLocationSystemInitializer: System initialization complete!");
  51. // Print status
  52. PrintSystemStatus();
  53. }
  54. void FindComponents()
  55. {
  56. if (featureManager == null)
  57. featureManager = FindFirstObjectByType<GeographicFeatureManager>();
  58. if (nameDisplay == null)
  59. nameDisplay = FindFirstObjectByType<MapLocationNameDisplay>();
  60. if (legendUI == null)
  61. legendUI = FindFirstObjectByType<MapSceneLegendUI>();
  62. if (mapMaker == null)
  63. mapMaker = FindFirstObjectByType<MapMaker2>();
  64. Debug.Log($"Found components - FeatureManager: {featureManager != null}, NameDisplay: {nameDisplay != null}, LegendUI: {legendUI != null}, MapMaker: {mapMaker != null}");
  65. }
  66. void ConfigureDebugModes()
  67. {
  68. if (nameDisplay != null)
  69. nameDisplay.debugMode = settings.enableDebugMode;
  70. if (legendUI != null)
  71. legendUI.debugMode = settings.enableDebugMode;
  72. if (featureManager != null)
  73. featureManager.debugMode = settings.enableDebugMode;
  74. }
  75. IEnumerator WaitForMapGeneration()
  76. {
  77. if (mapMaker == null)
  78. {
  79. Debug.LogWarning("MapLocationSystemInitializer: MapMaker not found - cannot wait for map generation");
  80. yield break;
  81. }
  82. // Wait for map to be generated
  83. int maxWaitFrames = 300; // 5 seconds at 60fps
  84. int waitedFrames = 0;
  85. while (mapMaker.GetMapData() == null && waitedFrames < maxWaitFrames)
  86. {
  87. yield return null;
  88. waitedFrames++;
  89. }
  90. if (mapMaker.GetMapData() != null)
  91. {
  92. Debug.Log("MapLocationSystemInitializer: Map generation complete");
  93. }
  94. else
  95. {
  96. Debug.LogWarning("MapLocationSystemInitializer: Timeout waiting for map generation");
  97. }
  98. }
  99. IEnumerator InitializeGeographicFeatures()
  100. {
  101. if (featureManager == null)
  102. {
  103. Debug.LogWarning("MapLocationSystemInitializer: FeatureManager not found");
  104. yield break;
  105. }
  106. if (settings.autoGenerateFeatures)
  107. {
  108. Debug.Log("MapLocationSystemInitializer: Generating geographic features...");
  109. featureManager.GenerateFeatures(mapMaker.GetMapData());
  110. // Wait a frame for generation to complete
  111. yield return null;
  112. Debug.Log($"MapLocationSystemInitializer: Generated {featureManager.GeographicFeatures.Count} geographic features");
  113. }
  114. }
  115. IEnumerator InitializeNameDisplay()
  116. {
  117. if (nameDisplay == null)
  118. {
  119. Debug.LogWarning("MapLocationSystemInitializer: NameDisplay not found");
  120. yield break;
  121. }
  122. Debug.Log("MapLocationSystemInitializer: Initializing name display...");
  123. // Configure name visibility settings
  124. nameDisplay.showSettlementNames = settings.showSettlementNamesOnStart;
  125. nameDisplay.showForestNames = settings.showForestNames;
  126. nameDisplay.showLakeNames = settings.showLakeNames;
  127. nameDisplay.showPlainNames = settings.showPlainNames;
  128. nameDisplay.showMountainNames = settings.showMountainNames;
  129. nameDisplay.showRiverNames = settings.showRiverNames;
  130. // Wait a frame for UI layout
  131. yield return null;
  132. // Refresh names
  133. nameDisplay.RefreshLocationNames();
  134. Debug.Log("MapLocationSystemInitializer: Name display initialized");
  135. }
  136. IEnumerator InitializeLegendUI()
  137. {
  138. if (legendUI == null)
  139. {
  140. Debug.LogWarning("MapLocationSystemInitializer: LegendUI not found");
  141. yield break;
  142. }
  143. Debug.Log("MapLocationSystemInitializer: Initializing legend UI...");
  144. // Wait a frame for UI setup
  145. yield return null;
  146. // Set initial visibility
  147. if (settings.showLegendOnStart)
  148. {
  149. legendUI.SetLegendVisible(true);
  150. }
  151. Debug.Log("MapLocationSystemInitializer: Legend UI initialized");
  152. }
  153. void PrintSystemStatus()
  154. {
  155. Debug.Log("=== MAP LOCATION SYSTEM STATUS ===");
  156. Debug.Log($"Geographic Features: {(featureManager != null ? featureManager.GeographicFeatures.Count.ToString() : "N/A")}");
  157. Debug.Log($"Legend UI Active: {(legendUI != null ? "Yes" : "No")}");
  158. Debug.Log($"Name Display Active: {(nameDisplay != null ? "Yes" : "No")}");
  159. Debug.Log($"Settlement Names: {(nameDisplay != null ? nameDisplay.showSettlementNames.ToString() : "N/A")}");
  160. Debug.Log($"Forest Names: {(nameDisplay != null ? nameDisplay.showForestNames.ToString() : "N/A")}");
  161. Debug.Log("=================================");
  162. }
  163. private void ConnectLegendToNameDisplay()
  164. {
  165. if (legendUI != null)
  166. {
  167. legendUI.RefreshNameDisplayConnection();
  168. Debug.Log("MapLocationSystemInitializer: Connected legend to name display");
  169. }
  170. }
  171. [ContextMenu("Reinitialize System")]
  172. public void ReinitializeSystem()
  173. {
  174. StartCoroutine(InitializeSystemDelayed());
  175. }
  176. [ContextMenu("Print System Status")]
  177. public void PrintCurrentStatus()
  178. {
  179. PrintSystemStatus();
  180. }
  181. }