using UnityEngine; using System.Collections; [System.Serializable] public class MapLocationSystemSettings { [Header("System Settings")] public bool enableDebugMode = false; public bool autoGenerateFeatures = true; public bool showLegendOnStart = true; public bool showSettlementNamesOnStart = true; [Header("Name Display Settings")] public bool showForestNames = true; public bool showLakeNames = true; public bool showPlainNames = false; public bool showMountainNames = true; public bool showRiverNames = true; } public class MapLocationSystemInitializer : MonoBehaviour { [Header("System Configuration")] public MapLocationSystemSettings settings = new MapLocationSystemSettings(); [Header("Component References (Auto-found if null)")] public GeographicFeatureManager featureManager; public MapLocationNameDisplay nameDisplay; public MapSceneLegendUI legendUI; public MapMaker2 mapMaker; void Start() { StartCoroutine(InitializeSystemDelayed()); } IEnumerator InitializeSystemDelayed() { // Wait a frame for all components to awake yield return null; Debug.Log("MapLocationSystemInitializer: Starting system initialization..."); // Find components if not assigned FindComponents(); // Configure debug modes ConfigureDebugModes(); // Wait for map generation if needed yield return StartCoroutine(WaitForMapGeneration()); // Initialize geographic features yield return StartCoroutine(InitializeGeographicFeatures()); // Initialize name display yield return StartCoroutine(InitializeNameDisplay()); // Initialize legend UI yield return StartCoroutine(InitializeLegendUI()); // Connect legend to name display ConnectLegendToNameDisplay(); Debug.Log("MapLocationSystemInitializer: System initialization complete!"); // Print status PrintSystemStatus(); } void FindComponents() { if (featureManager == null) featureManager = FindFirstObjectByType(); if (nameDisplay == null) nameDisplay = FindFirstObjectByType(); if (legendUI == null) legendUI = FindFirstObjectByType(); if (mapMaker == null) mapMaker = FindFirstObjectByType(); Debug.Log($"Found components - FeatureManager: {featureManager != null}, NameDisplay: {nameDisplay != null}, LegendUI: {legendUI != null}, MapMaker: {mapMaker != null}"); } void ConfigureDebugModes() { if (nameDisplay != null) nameDisplay.debugMode = settings.enableDebugMode; if (legendUI != null) legendUI.debugMode = settings.enableDebugMode; if (featureManager != null) featureManager.debugMode = settings.enableDebugMode; } IEnumerator WaitForMapGeneration() { if (mapMaker == null) { Debug.LogWarning("MapLocationSystemInitializer: MapMaker not found - cannot wait for map generation"); yield break; } // Wait for map to be generated int maxWaitFrames = 300; // 5 seconds at 60fps int waitedFrames = 0; while (mapMaker.GetMapData() == null && waitedFrames < maxWaitFrames) { yield return null; waitedFrames++; } if (mapMaker.GetMapData() != null) { Debug.Log("MapLocationSystemInitializer: Map generation complete"); } else { Debug.LogWarning("MapLocationSystemInitializer: Timeout waiting for map generation"); } } IEnumerator InitializeGeographicFeatures() { if (featureManager == null) { Debug.LogWarning("MapLocationSystemInitializer: FeatureManager not found"); yield break; } if (settings.autoGenerateFeatures) { Debug.Log("MapLocationSystemInitializer: Generating geographic features..."); featureManager.GenerateFeatures(mapMaker.GetMapData()); // Wait a frame for generation to complete yield return null; Debug.Log($"MapLocationSystemInitializer: Generated {featureManager.GeographicFeatures.Count} geographic features"); } } IEnumerator InitializeNameDisplay() { if (nameDisplay == null) { Debug.LogWarning("MapLocationSystemInitializer: NameDisplay not found"); yield break; } Debug.Log("MapLocationSystemInitializer: Initializing name display..."); // Configure name visibility settings nameDisplay.showSettlementNames = settings.showSettlementNamesOnStart; nameDisplay.showForestNames = settings.showForestNames; nameDisplay.showLakeNames = settings.showLakeNames; nameDisplay.showPlainNames = settings.showPlainNames; nameDisplay.showMountainNames = settings.showMountainNames; nameDisplay.showRiverNames = settings.showRiverNames; // Wait a frame for UI layout yield return null; // Refresh names nameDisplay.RefreshLocationNames(); Debug.Log("MapLocationSystemInitializer: Name display initialized"); } IEnumerator InitializeLegendUI() { if (legendUI == null) { Debug.LogWarning("MapLocationSystemInitializer: LegendUI not found"); yield break; } Debug.Log("MapLocationSystemInitializer: Initializing legend UI..."); // Wait a frame for UI setup yield return null; // Set initial visibility if (settings.showLegendOnStart) { legendUI.SetLegendVisible(true); } Debug.Log("MapLocationSystemInitializer: Legend UI initialized"); } void PrintSystemStatus() { Debug.Log("=== MAP LOCATION SYSTEM STATUS ==="); Debug.Log($"Geographic Features: {(featureManager != null ? featureManager.GeographicFeatures.Count.ToString() : "N/A")}"); Debug.Log($"Legend UI Active: {(legendUI != null ? "Yes" : "No")}"); Debug.Log($"Name Display Active: {(nameDisplay != null ? "Yes" : "No")}"); Debug.Log($"Settlement Names: {(nameDisplay != null ? nameDisplay.showSettlementNames.ToString() : "N/A")}"); Debug.Log($"Forest Names: {(nameDisplay != null ? nameDisplay.showForestNames.ToString() : "N/A")}"); Debug.Log("================================="); } private void ConnectLegendToNameDisplay() { if (legendUI != null) { legendUI.RefreshNameDisplayConnection(); Debug.Log("MapLocationSystemInitializer: Connected legend to name display"); } } [ContextMenu("Reinitialize System")] public void ReinitializeSystem() { StartCoroutine(InitializeSystemDelayed()); } [ContextMenu("Print System Status")] public void PrintCurrentStatus() { PrintSystemStatus(); } }