BattleSceneDebugHelper.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. /// <summary>
  4. /// Debug helper for testing battle scene transitions and victory scenarios
  5. /// </summary>
  6. public class BattleSceneDebugHelper : MonoBehaviour
  7. {
  8. [Header("Debug Controls")]
  9. [Tooltip("Enable debug mode to show additional logging and controls")]
  10. public bool enableDebugMode = true;
  11. [Header("Scene Testing")]
  12. [Tooltip("Name of the map scene to return to")]
  13. public string mapSceneName = "MapScene2";
  14. private void Update()
  15. {
  16. if (!enableDebugMode) return;
  17. // Debug hotkeys
  18. if (Input.GetKeyDown(KeyCode.F1))
  19. {
  20. TestSceneTransition();
  21. }
  22. if (Input.GetKeyDown(KeyCode.F2))
  23. {
  24. ForcePlayerVictory();
  25. }
  26. if (Input.GetKeyDown(KeyCode.F3))
  27. {
  28. TestReturnToMap();
  29. }
  30. }
  31. [ContextMenu("Test Scene Transition")]
  32. public void TestSceneTransition()
  33. {
  34. Debug.Log("🧪 [DEBUG] Testing scene transition to " + mapSceneName);
  35. try
  36. {
  37. SceneManager.LoadScene(mapSceneName);
  38. Debug.Log("✅ Scene transition initiated successfully");
  39. }
  40. catch (System.Exception e)
  41. {
  42. Debug.LogError($"❌ Scene transition failed: {e.Message}");
  43. }
  44. }
  45. [ContextMenu("Force Player Victory")]
  46. public void ForcePlayerVictory()
  47. {
  48. Debug.Log("🧪 [DEBUG] Forcing player victory...");
  49. if (GameManager.Instance != null)
  50. {
  51. // Use the GameManager's test victory method if available
  52. var method = typeof(GameManager).GetMethod("TestBattleVictory",
  53. System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
  54. if (method != null)
  55. {
  56. method.Invoke(GameManager.Instance, null);
  57. Debug.Log("✅ Used GameManager.TestBattleVictory()");
  58. }
  59. else
  60. {
  61. Debug.LogWarning("⚠️ GameManager.TestBattleVictory() method not found");
  62. // Manually kill all enemies
  63. ForceKillAllEnemies();
  64. }
  65. }
  66. else
  67. {
  68. Debug.LogError("❌ GameManager.Instance is null");
  69. }
  70. }
  71. [ContextMenu("Test Return to Map")]
  72. public void TestReturnToMap()
  73. {
  74. Debug.Log("🧪 [DEBUG] Testing return to map via OnLootingComplete...");
  75. if (GameManager.Instance != null)
  76. {
  77. // Call the OnLootingComplete method directly
  78. var method = typeof(GameManager).GetMethod("OnLootingComplete",
  79. System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  80. if (method != null)
  81. {
  82. method.Invoke(GameManager.Instance, null);
  83. Debug.Log("✅ Called OnLootingComplete() via reflection");
  84. }
  85. else
  86. {
  87. Debug.LogError("❌ OnLootingComplete method not found");
  88. }
  89. }
  90. else
  91. {
  92. Debug.LogError("❌ GameManager.Instance is null");
  93. }
  94. }
  95. private void ForceKillAllEnemies()
  96. {
  97. Debug.Log("🧪 [DEBUG] Manually killing all enemies...");
  98. if (GameManager.Instance != null && GameManager.Instance.enemyCharacters != null)
  99. {
  100. foreach (var enemy in GameManager.Instance.enemyCharacters)
  101. {
  102. if (enemy != null)
  103. {
  104. var character = enemy.GetComponent<Character>();
  105. if (character != null && !character.IsDead)
  106. {
  107. character.TakeDamage(1000); // Force death
  108. Debug.Log($"🔪 Killed enemy: {enemy.name}");
  109. }
  110. }
  111. }
  112. }
  113. }
  114. [ContextMenu("Debug Battle State")]
  115. public void DebugBattleState()
  116. {
  117. Debug.Log("🔍 [DEBUG] Current battle state:");
  118. if (GameManager.Instance != null)
  119. {
  120. Debug.Log($" Players: {GameManager.Instance.playerCharacters?.Count ?? 0}");
  121. Debug.Log($" Enemies: {GameManager.Instance.enemyCharacters?.Count ?? 0}");
  122. var alivePlayers = GameManager.Instance.GetAlivePlayers();
  123. var aliveEnemies = GameManager.Instance.enemyCharacters?.Where(e => e != null && !e.GetComponent<Character>()?.IsDead == true).Count() ?? 0;
  124. Debug.Log($" Alive Players: {alivePlayers?.Count ?? 0}");
  125. Debug.Log($" Alive Enemies: {aliveEnemies}");
  126. bool battleShouldEnd = (alivePlayers?.Count ?? 0) == 0 || aliveEnemies == 0;
  127. Debug.Log($" Battle should end: {battleShouldEnd}");
  128. }
  129. else
  130. {
  131. Debug.LogError(" GameManager.Instance is null!");
  132. }
  133. }
  134. private void OnGUI()
  135. {
  136. if (!enableDebugMode) return;
  137. // Simple debug GUI
  138. GUILayout.BeginArea(new Rect(10, 10, 300, 200));
  139. GUILayout.Label("Battle Debug Controls", GUI.skin.box);
  140. if (GUILayout.Button("F1: Test Scene Transition"))
  141. TestSceneTransition();
  142. if (GUILayout.Button("F2: Force Player Victory"))
  143. ForcePlayerVictory();
  144. if (GUILayout.Button("F3: Test Return to Map"))
  145. TestReturnToMap();
  146. if (GUILayout.Button("Debug Battle State"))
  147. DebugBattleState();
  148. GUILayout.Label("Hotkeys: F1, F2, F3");
  149. GUILayout.EndArea();
  150. }
  151. }