MapSceneSetup.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. using UnityEngine;
  2. using UnityEngine.UIElements;
  3. /// <summary>
  4. /// Setup script to configure all UI systems in the map scene.
  5. /// Handles both travel system and team overview setup automatically.
  6. /// </summary>
  7. public class MapSceneSetup : MonoBehaviour
  8. {
  9. [Header("Setup Options")]
  10. public bool autoSetupOnStart = true;
  11. public bool showDebugLogs = true;
  12. [Header("UI Settings")]
  13. public bool enableTeamOverview = true;
  14. public bool enableTravelSystem = true;
  15. void Start()
  16. {
  17. if (autoSetupOnStart)
  18. {
  19. SetupMapScene();
  20. }
  21. }
  22. [ContextMenu("Setup Map Scene")]
  23. public void SetupMapScene()
  24. {
  25. // Check if we're in Play Mode
  26. if (!Application.isPlaying)
  27. {
  28. Debug.LogWarning("⚠️ MapSceneSetup: Please run this setup during Play Mode, not Edit Mode!");
  29. Debug.LogWarning("💡 Either enter Play Mode and try again, or let it run automatically via autoSetupOnStart.");
  30. return;
  31. }
  32. if (showDebugLogs)
  33. {
  34. Debug.Log("🏗️ Setting up Map Scene UI systems...");
  35. }
  36. // Setup team overview if enabled
  37. if (enableTeamOverview)
  38. {
  39. SetupTeamOverview();
  40. }
  41. // Setup travel system if enabled
  42. if (enableTravelSystem)
  43. {
  44. SetupTravelSystem();
  45. }
  46. if (showDebugLogs)
  47. {
  48. Debug.Log("✅ Map Scene setup complete!");
  49. }
  50. }
  51. [ContextMenu("Force Setup (Play Mode Only)")]
  52. public void ForceSetupInPlayMode()
  53. {
  54. if (!Application.isPlaying)
  55. {
  56. Debug.LogError("❌ This setup requires Play Mode! Enter Play Mode first.");
  57. return;
  58. }
  59. SetupMapScene();
  60. }
  61. /// <summary>
  62. /// Sets up the team overview controller
  63. /// </summary>
  64. private void SetupTeamOverview()
  65. {
  66. // Look for UI GameObject
  67. GameObject uiGameObject = GameObject.Find("UI");
  68. if (uiGameObject == null)
  69. {
  70. if (showDebugLogs)
  71. {
  72. Debug.LogWarning("⚠️ No UI GameObject found - Team Overview not setup");
  73. }
  74. return;
  75. }
  76. // Check if TeamOverviewController already exists
  77. var existingController = FindFirstObjectByType<TeamOverviewController>();
  78. if (existingController != null)
  79. {
  80. if (showDebugLogs)
  81. {
  82. Debug.Log("📋 TeamOverviewController already exists");
  83. }
  84. return;
  85. }
  86. // Create a new GameObject for the TeamOverviewController
  87. GameObject teamOverviewObject = new GameObject("TeamOverviewController");
  88. teamOverviewObject.transform.SetParent(uiGameObject.transform);
  89. // Add the TeamOverviewController component
  90. var teamOverviewController = teamOverviewObject.AddComponent<TeamOverviewController>();
  91. if (showDebugLogs)
  92. {
  93. Debug.Log("✅ TeamOverviewController created and setup");
  94. }
  95. }
  96. /// <summary>
  97. /// Sets up the travel system (delegates to existing setup if available)
  98. /// </summary>
  99. private void SetupTravelSystem()
  100. {
  101. var travelSystemSetup = FindFirstObjectByType<TravelSystemSetup>();
  102. if (travelSystemSetup != null)
  103. {
  104. if (showDebugLogs)
  105. {
  106. Debug.Log("🚗 Using existing TravelSystemSetup");
  107. }
  108. // Let the existing travel system setup handle this
  109. return;
  110. }
  111. // Look for UI GameObject
  112. GameObject uiGameObject = GameObject.Find("UI");
  113. if (uiGameObject == null)
  114. {
  115. if (showDebugLogs)
  116. {
  117. Debug.LogWarning("⚠️ No UI GameObject found - Travel System not setup");
  118. }
  119. return;
  120. }
  121. // Check if TravelUIController already exists
  122. var existingUIController = uiGameObject.GetComponent<TravelUIController>();
  123. if (existingUIController != null)
  124. {
  125. if (showDebugLogs)
  126. {
  127. Debug.Log("🚗 TravelUIController already exists");
  128. }
  129. return;
  130. }
  131. // Add TravelUIController to UI GameObject
  132. var uiController = uiGameObject.AddComponent<TravelUIController>();
  133. uiController.showDebugLogs = showDebugLogs;
  134. if (showDebugLogs)
  135. {
  136. Debug.Log("✅ TravelUIController created and setup");
  137. }
  138. }
  139. /// <summary>
  140. /// Context menu methods for debugging
  141. /// </summary>
  142. [ContextMenu("Setup Team Overview Only")]
  143. public void SetupTeamOverviewOnly()
  144. {
  145. SetupTeamOverview();
  146. }
  147. [ContextMenu("Setup Travel System Only")]
  148. public void SetupTravelSystemOnly()
  149. {
  150. SetupTravelSystem();
  151. }
  152. [ContextMenu("Verify UI Setup")]
  153. public void VerifyUISetup()
  154. {
  155. var uiGameObject = GameObject.Find("UI");
  156. if (uiGameObject == null)
  157. {
  158. Debug.LogError("❌ UI GameObject not found!");
  159. return;
  160. }
  161. var uiDocument = uiGameObject.GetComponent<UIDocument>();
  162. var teamOverviewController = FindFirstObjectByType<TeamOverviewController>();
  163. var travelUIController = uiGameObject.GetComponent<TravelUIController>();
  164. Debug.Log($"🔍 UI Setup Verification:");
  165. Debug.Log($" UIDocument: {(uiDocument != null ? "✅" : "❌")}");
  166. Debug.Log($" TeamOverviewController: {(teamOverviewController != null ? "✅" : "❌")}");
  167. Debug.Log($" TravelUIController: {(travelUIController != null ? "✅" : "❌")}");
  168. if (uiDocument?.rootVisualElement != null)
  169. {
  170. var root = uiDocument.rootVisualElement;
  171. var teamOverviewPanel = root.Q("TeamOverviewPanel");
  172. var travelContainer = root.Q("TravelContainer");
  173. Debug.Log($" TeamOverviewPanel in UXML: {(teamOverviewPanel != null ? "✅" : "❌")}");
  174. Debug.Log($" TravelContainer in UXML: {(travelContainer != null ? "✅" : "❌")}");
  175. }
  176. }
  177. }