| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- 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<GeographicFeatureManager>();
- if (nameDisplay == null)
- nameDisplay = FindFirstObjectByType<MapLocationNameDisplay>();
- if (legendUI == null)
- legendUI = FindFirstObjectByType<MapSceneLegendUI>();
- if (mapMaker == null)
- mapMaker = FindFirstObjectByType<MapMaker2>();
- 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();
- }
- }
|