| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- using UnityEngine;
- using UnityEngine.UIElements;
- /// <summary>
- /// Setup script to configure all UI systems in the map scene.
- /// Handles both travel system and team overview setup automatically.
- /// </summary>
- public class MapSceneSetup : MonoBehaviour
- {
- [Header("Setup Options")]
- public bool autoSetupOnStart = true;
- public bool showDebugLogs = true;
- [Header("UI Settings")]
- public bool enableTeamOverview = true;
- public bool enableTravelSystem = true;
- void Start()
- {
- if (autoSetupOnStart)
- {
- SetupMapScene();
- }
- }
- [ContextMenu("Setup Map Scene")]
- public void SetupMapScene()
- {
- // Check if we're in Play Mode
- if (!Application.isPlaying)
- {
- Debug.LogWarning("⚠️ MapSceneSetup: Please run this setup during Play Mode, not Edit Mode!");
- Debug.LogWarning("💡 Either enter Play Mode and try again, or let it run automatically via autoSetupOnStart.");
- return;
- }
- if (showDebugLogs)
- {
- Debug.Log("🏗️ Setting up Map Scene UI systems...");
- }
- // Setup team overview if enabled
- if (enableTeamOverview)
- {
- SetupTeamOverview();
- }
- // Setup travel system if enabled
- if (enableTravelSystem)
- {
- SetupTravelSystem();
- }
- // Setup quest system
- SetupQuestSystem();
- if (showDebugLogs)
- {
- Debug.Log("✅ Map Scene setup complete!");
- }
- }
- [ContextMenu("Force Setup (Play Mode Only)")]
- public void ForceSetupInPlayMode()
- {
- if (!Application.isPlaying)
- {
- Debug.LogError("❌ This setup requires Play Mode! Enter Play Mode first.");
- return;
- }
- SetupMapScene();
- }
- /// <summary>
- /// Sets up the team overview controller
- /// </summary>
- private void SetupTeamOverview()
- {
- // Look for UI GameObject
- GameObject uiGameObject = GameObject.Find("UI");
- if (uiGameObject == null)
- {
- if (showDebugLogs)
- {
- Debug.LogWarning("⚠️ No UI GameObject found - Team Overview not setup");
- }
- return;
- }
- // Check if TeamOverviewController already exists
- var existingController = FindFirstObjectByType<TeamOverviewController>();
- if (existingController != null)
- {
- if (showDebugLogs)
- {
- Debug.Log("📋 TeamOverviewController already exists");
- }
- return;
- }
- // Create a new GameObject for the TeamOverviewController
- GameObject teamOverviewObject = new GameObject("TeamOverviewController");
- teamOverviewObject.transform.SetParent(uiGameObject.transform);
- // Add the TeamOverviewController component
- var teamOverviewController = teamOverviewObject.AddComponent<TeamOverviewController>();
- if (showDebugLogs)
- {
- Debug.Log("✅ TeamOverviewController created and setup");
- }
- }
- /// <summary>
- /// Sets up the travel system (delegates to existing setup if available)
- /// </summary>
- private void SetupTravelSystem()
- {
- var travelSystemSetup = FindFirstObjectByType<TravelSystemSetup>();
- if (travelSystemSetup != null)
- {
- if (showDebugLogs)
- {
- Debug.Log("🚗 Using existing TravelSystemSetup");
- }
- // Let the existing travel system setup handle this
- return;
- }
- // Look for UI GameObject
- GameObject uiGameObject = GameObject.Find("UI");
- if (uiGameObject == null)
- {
- if (showDebugLogs)
- {
- Debug.LogWarning("⚠️ No UI GameObject found - Travel System not setup");
- }
- return;
- }
- // Check if TravelUIController already exists
- var existingUIController = uiGameObject.GetComponent<TravelUIController>();
- if (existingUIController != null)
- {
- if (showDebugLogs)
- {
- Debug.Log("🚗 TravelUIController already exists");
- }
- return;
- }
- // Add TravelUIController to UI GameObject
- var uiController = uiGameObject.AddComponent<TravelUIController>();
- uiController.showDebugLogs = showDebugLogs;
- if (showDebugLogs)
- {
- Debug.Log("✅ TravelUIController created and setup");
- }
- }
- /// <summary>
- /// Sets up the quest system and ensures quest data is loaded
- /// </summary>
- private void SetupQuestSystem()
- {
- if (showDebugLogs)
- {
- Debug.Log("🗺️ Setting up Quest System for Map Scene...");
- }
- // Ensure QuestManager exists and loads quest data
- if (QuestManager.Instance != null)
- {
- QuestManager.Instance.LoadQuestData();
- if (showDebugLogs)
- {
- var activeQuests = QuestManager.Instance.GetActiveQuests();
- Debug.Log($"✅ Quest system ready - {activeQuests.Count} active quest(s)");
- }
- }
- else
- {
- if (showDebugLogs)
- {
- Debug.LogWarning("⚠️ QuestManager not found in scene");
- }
- }
- // Ensure quest markers are refreshed
- var questMapMarkerManager = FindFirstObjectByType<QuestMapMarkerManager>();
- if (questMapMarkerManager != null)
- {
- questMapMarkerManager.RefreshAllMarkers();
- if (showDebugLogs)
- {
- Debug.Log("✅ Quest markers refreshed");
- }
- }
- else
- {
- if (showDebugLogs)
- {
- Debug.LogWarning("⚠️ QuestMapMarkerManager not found in scene");
- }
- }
- // Ensure ActiveQuestUI is refreshed
- var activeQuestUI = FindFirstObjectByType<ActiveQuestUI>();
- if (activeQuestUI != null)
- {
- // The ActiveQuestUI should automatically refresh via events
- if (showDebugLogs)
- {
- Debug.Log("✅ ActiveQuestUI found and will auto-refresh");
- }
- }
- else
- {
- // Create ActiveQuestUI if it doesn't exist
- SetupActiveQuestUI();
- }
- }
- /// <summary>
- /// Sets up the ActiveQuestUI component
- /// </summary>
- private void SetupActiveQuestUI()
- {
- if (showDebugLogs)
- {
- Debug.Log("🎯 Setting up ActiveQuestUI...");
- }
- // Look for or create a QuestUI GameObject
- GameObject questUIGameObject = GameObject.Find("QuestUI");
- if (questUIGameObject == null)
- {
- questUIGameObject = new GameObject("QuestUI");
- }
- // Check if ActiveQuestUI already exists
- var existingActiveQuestUI = questUIGameObject.GetComponent<ActiveQuestUI>();
- if (existingActiveQuestUI != null)
- {
- if (showDebugLogs)
- {
- Debug.Log("✅ ActiveQuestUI component already exists");
- }
- return;
- }
- // Add UIDocument if it doesn't exist
- var uiDocument = questUIGameObject.GetComponent<UIDocument>();
- if (uiDocument == null)
- {
- uiDocument = questUIGameObject.AddComponent<UIDocument>();
- }
- // Load the UXML asset
- var activeQuestUIAsset = Resources.Load<VisualTreeAsset>("UI/MapScene/ActiveQuestUI");
- if (activeQuestUIAsset != null)
- {
- uiDocument.visualTreeAsset = activeQuestUIAsset;
- if (showDebugLogs)
- {
- Debug.Log("✅ Loaded ActiveQuestUI.uxml");
- }
- }
- else
- {
- Debug.LogError("❌ Could not load ActiveQuestUI.uxml from Resources/UI/MapScene/");
- return;
- }
- // Load the USS asset
- var activeQuestUIStyleSheet = Resources.Load<StyleSheet>("UI/MapScene/ActiveQuestUI");
- if (activeQuestUIStyleSheet != null)
- {
- uiDocument.rootVisualElement.styleSheets.Add(activeQuestUIStyleSheet);
- if (showDebugLogs)
- {
- Debug.Log("✅ Loaded ActiveQuestUI.uss");
- }
- }
- else
- {
- Debug.LogWarning("⚠️ Could not load ActiveQuestUI.uss from Resources/UI/MapScene/");
- }
- // Add the ActiveQuestUI component
- var activeQuestUI = questUIGameObject.AddComponent<ActiveQuestUI>();
- activeQuestUI.uiDocument = uiDocument;
- if (showDebugLogs)
- {
- Debug.Log("✅ ActiveQuestUI component created and configured");
- }
- }
- /// <summary>
- /// Context menu methods for debugging
- /// </summary>
- [ContextMenu("Setup Team Overview Only")]
- public void SetupTeamOverviewOnly()
- {
- SetupTeamOverview();
- }
- [ContextMenu("Setup Travel System Only")]
- public void SetupTravelSystemOnly()
- {
- SetupTravelSystem();
- }
- [ContextMenu("Setup Quest System Only")]
- public void SetupQuestSystemOnly()
- {
- SetupQuestSystem();
- }
- [ContextMenu("Setup ActiveQuestUI Only")]
- public void SetupActiveQuestUIOnly()
- {
- SetupActiveQuestUI();
- }
- [ContextMenu("Verify UI Setup")]
- public void VerifyUISetup()
- {
- var uiGameObject = GameObject.Find("UI");
- var questUIGameObject = GameObject.Find("QuestUI");
- if (uiGameObject == null)
- {
- Debug.LogError("❌ UI GameObject not found!");
- return;
- }
- var uiDocument = uiGameObject.GetComponent<UIDocument>();
- var teamOverviewController = FindFirstObjectByType<TeamOverviewController>();
- var travelUIController = uiGameObject.GetComponent<TravelUIController>();
- var activeQuestUI = FindFirstObjectByType<ActiveQuestUI>();
- Debug.Log($"🔍 UI Setup Verification:");
- Debug.Log($" UIDocument: {(uiDocument != null ? "✅" : "❌")}");
- Debug.Log($" TeamOverviewController: {(teamOverviewController != null ? "✅" : "❌")}");
- Debug.Log($" TravelUIController: {(travelUIController != null ? "✅" : "❌")}");
- Debug.Log($" ActiveQuestUI: {(activeQuestUI != null ? "✅" : "❌")}");
- Debug.Log($" QuestUI GameObject: {(questUIGameObject != null ? "✅" : "❌")}");
- if (uiDocument?.rootVisualElement != null)
- {
- var root = uiDocument.rootVisualElement;
- var teamOverviewPanel = root.Q("TeamOverviewPanel");
- var travelContainer = root.Q("TravelContainer");
- Debug.Log($" TeamOverviewPanel in UXML: {(teamOverviewPanel != null ? "✅" : "❌")}");
- Debug.Log($" TravelContainer in UXML: {(travelContainer != null ? "✅" : "❌")}");
- }
- if (activeQuestUI?.uiDocument?.rootVisualElement != null)
- {
- var questRoot = activeQuestUI.uiDocument.rootVisualElement;
- var questTracker = questRoot.Q("quest-tracker");
- Debug.Log($" Quest Tracker in UXML: {(questTracker != null ? "✅" : "❌")}");
- }
- }
- }
|