TitleScreenDiagnostics.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * TITLE SCREEN TROUBLESHOOTING STEPS
  3. * ==================================
  4. *
  5. * Your title screen shows visual effects (hover, click) but doesn't load scenes.
  6. * This suggests the UI is working but scene loading is failing.
  7. *
  8. * STEP-BY-STEP DEBUGGING:
  9. * ======================
  10. *
  11. * 1. VERIFY BUTTON SETUP:
  12. * - Add this component to your TitleScreenManager GameObject
  13. * - Play the game and check Console for button detection messages
  14. *
  15. * 2. TEST SIMPLE SCENE LOADING:
  16. * - Add SimpleTitleScreenTest component instead of TitleScreenManager
  17. * - This will test basic scene loading without complications
  18. *
  19. * 3. CHECK CONSOLE MESSAGES:
  20. * - Look for "NEW GAME BUTTON CLICKED" messages
  21. * - Look for scene loading errors
  22. * - Look for "Scene exists" confirmation
  23. *
  24. * 4. VERIFY BUILD SETTINGS:
  25. * - Use context menu "Check Scene Setup" on this component
  26. *
  27. * LIKELY CAUSES:
  28. * ==============
  29. *
  30. * ❌ Scene loading is called but target scene has errors preventing load
  31. * ❌ MainTeamSelectScene is corrupted or has script errors
  32. * ❌ Missing dependencies in MainTeamSelectScene
  33. * ❌ Build Settings cache needs refresh
  34. *
  35. */
  36. using UnityEngine;
  37. using UnityEngine.UIElements;
  38. using UnityEngine.SceneManagement;
  39. public class TitleScreenDiagnostics : MonoBehaviour
  40. {
  41. [Header("Diagnostic Results")]
  42. public bool uiDocumentFound = false;
  43. public bool buttonsFound = false;
  44. public bool sceneInBuildSettings = false;
  45. public bool eventHandlersAttached = false;
  46. private void Start()
  47. {
  48. RunDiagnostics();
  49. }
  50. [ContextMenu("Run Full Diagnostics")]
  51. public void RunDiagnostics()
  52. {
  53. Debug.Log("=== TITLE SCREEN DIAGNOSTICS ===");
  54. // Check UIDocument
  55. var uiDoc = GetComponent<UIDocument>();
  56. uiDocumentFound = uiDoc != null;
  57. Debug.Log($"✓ UIDocument found: {uiDocumentFound}");
  58. if (!uiDocumentFound)
  59. {
  60. Debug.LogError("❌ No UIDocument component found!");
  61. return;
  62. }
  63. // Check buttons
  64. var root = uiDoc.rootVisualElement;
  65. var newGameBtn = root.Q<Button>("NewGameButton");
  66. var loadGameBtn = root.Q<Button>("LoadGameButton");
  67. var quitBtn = root.Q<Button>("QuitButton");
  68. buttonsFound = (newGameBtn != null && loadGameBtn != null && quitBtn != null);
  69. Debug.Log($"✓ All buttons found: {buttonsFound}");
  70. Debug.Log($" - NewGameButton: {newGameBtn != null}");
  71. Debug.Log($" - LoadGameButton: {loadGameBtn != null}");
  72. Debug.Log($" - QuitButton: {quitBtn != null}");
  73. // Check scene in build settings
  74. sceneInBuildSettings = CheckSceneInBuild("MainTeamSelectScene");
  75. Debug.Log($"✓ MainTeamSelectScene in build: {sceneInBuildSettings}");
  76. // Test event attachment
  77. if (newGameBtn != null)
  78. {
  79. // Add test event handler
  80. newGameBtn.clicked += TestSceneLoad;
  81. eventHandlersAttached = true;
  82. Debug.Log("✓ Test event handler attached to New Game button");
  83. }
  84. Debug.Log("=== DIAGNOSTICS COMPLETE ===");
  85. if (!uiDocumentFound || !buttonsFound || !sceneInBuildSettings)
  86. {
  87. Debug.LogError("❌ Issues found! Check the problems above.");
  88. }
  89. else
  90. {
  91. Debug.Log("✅ All basic checks passed. Try clicking New Game now.");
  92. }
  93. }
  94. private void TestSceneLoad()
  95. {
  96. Debug.Log("🔥 TEST SCENE LOAD TRIGGERED!");
  97. Debug.Log("Attempting to load MainTeamSelectScene...");
  98. try
  99. {
  100. SceneManager.LoadScene("MainTeamSelectScene");
  101. Debug.Log("✅ SceneManager.LoadScene() called successfully!");
  102. }
  103. catch (System.Exception e)
  104. {
  105. Debug.LogError($"❌ Exception during scene load: {e.Message}");
  106. Debug.LogError($"Stack trace: {e.StackTrace}");
  107. }
  108. }
  109. private bool CheckSceneInBuild(string sceneName)
  110. {
  111. for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++)
  112. {
  113. string scenePath = UnityEngine.SceneManagement.SceneUtility.GetScenePathByBuildIndex(i);
  114. string sceneNameFromPath = System.IO.Path.GetFileNameWithoutExtension(scenePath);
  115. if (sceneNameFromPath.Equals(sceneName, System.StringComparison.OrdinalIgnoreCase))
  116. {
  117. Debug.Log($"Scene '{sceneName}' found at build index {i}: {scenePath}");
  118. return true;
  119. }
  120. }
  121. Debug.LogError($"Scene '{sceneName}' not found in build settings!");
  122. LogAllBuildScenes();
  123. return false;
  124. }
  125. private void LogAllBuildScenes()
  126. {
  127. Debug.Log("All scenes in build settings:");
  128. for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++)
  129. {
  130. string scenePath = UnityEngine.SceneManagement.SceneUtility.GetScenePathByBuildIndex(i);
  131. string sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePath);
  132. Debug.Log($" {i}: {sceneName}");
  133. }
  134. }
  135. [ContextMenu("Test Scene Load Manually")]
  136. public void TestSceneLoadManually()
  137. {
  138. TestSceneLoad();
  139. }
  140. }