| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- using UnityEngine;
- /// <summary>
- /// Debug tool for testing the respawn system without dying naturally.
- /// Attach to any GameObject in your scene.
- /// </summary>
- public class RespawnSystemTester : MonoBehaviour
- {
- [Header("Debug Controls")]
- [Tooltip("Press this key to instantly kill all party members")]
- public KeyCode killPartyKey = KeyCode.K;
-
- [Tooltip("Press this key to save a checkpoint at current position")]
- public KeyCode saveCheckpointKey = KeyCode.P;
-
- [Tooltip("Press this key to respawn at last checkpoint")]
- public KeyCode respawnKey = KeyCode.R;
-
- [Tooltip("Press this key to damage all characters by 20 HP")]
- public KeyCode damagePartyKey = KeyCode.H;
-
- [Header("References (Auto-found if not assigned)")]
- public TeamCohesionManager cohesionManager;
- public CheckpointSystem checkpointSystem;
- public GameManager gameManager;
-
- private bool showDebugUI = true;
- private void Start()
- {
- // Auto-find references if not assigned
- if (cohesionManager == null)
- cohesionManager = FindFirstObjectByType<TeamCohesionManager>();
-
- if (checkpointSystem == null)
- checkpointSystem = FindFirstObjectByType<CheckpointSystem>();
-
- if (gameManager == null)
- gameManager = FindFirstObjectByType<GameManager>();
-
- Debug.Log("[RespawnTester] Press '" + killPartyKey + "' to test death system");
- Debug.Log("[RespawnTester] Press '" + saveCheckpointKey + "' to save checkpoint");
- Debug.Log("[RespawnTester] Press '" + damagePartyKey + "' to damage party");
- }
- private void Update()
- {
- // Kill all party members instantly
- if (Input.GetKeyDown(killPartyKey))
- {
- KillAllPartyMembers();
- }
-
- // Save checkpoint
- if (Input.GetKeyDown(saveCheckpointKey))
- {
- SaveCheckpoint();
- }
-
- // Force respawn
- if (Input.GetKeyDown(respawnKey))
- {
- ForceRespawn();
- }
-
- // Damage party
- if (Input.GetKeyDown(damagePartyKey))
- {
- DamageAllPartyMembers(20);
- }
-
- // Toggle debug UI
- if (Input.GetKeyDown(KeyCode.F1))
- {
- showDebugUI = !showDebugUI;
- }
- }
- /// <summary>
- /// Instantly kill all party members to test death system
- /// </summary>
- public void KillAllPartyMembers()
- {
- if (cohesionManager == null || cohesionManager.groupMembers == null)
- {
- Debug.LogError("[RespawnTester] Cannot kill party: CohesionManager not found");
- return;
- }
- Debug.Log("[RespawnTester] 💀 Killing all party members...");
- // Set all characters to 0 HP
- foreach (var character in cohesionManager.groupMembers)
- {
- character.currentHP = 0;
-
- // Update UI to show 0 HP
- UIUpdater.Instance?.UpdateCharacterHP(character);
-
- // Trigger death on UI controller
- var uiController = UIUpdater.Instance?.GetUIForCharacter(character);
- if (uiController != null)
- {
- uiController.HandleCharacterDeath();
- }
- }
-
- Debug.Log("[RespawnTester] All party members killed. Death system should trigger...");
- }
- /// <summary>
- /// Damage all party members by a certain amount
- /// </summary>
- public void DamageAllPartyMembers(int damage)
- {
- if (cohesionManager == null || cohesionManager.groupMembers == null)
- {
- Debug.LogError("[RespawnTester] Cannot damage party: CohesionManager not found");
- return;
- }
- Debug.Log($"[RespawnTester] ⚔️ Damaging all party members by {damage} HP");
- foreach (var character in cohesionManager.groupMembers)
- {
- character.currentHP = Mathf.Max(0, character.currentHP - damage);
- UIUpdater.Instance?.UpdateCharacterHP(character);
-
- var uiController = UIUpdater.Instance?.GetUIForCharacter(character);
- if (uiController != null)
- {
- uiController.ShowDamageOnCard(damage);
-
- // Check if character died
- if (character.currentHP <= 0)
- {
- uiController.HandleCharacterDeath();
- }
- }
- }
- }
- /// <summary>
- /// Save checkpoint at current position
- /// </summary>
- public void SaveCheckpoint()
- {
- if (checkpointSystem == null)
- {
- Debug.LogError("[RespawnTester] Cannot save checkpoint: CheckpointSystem not found");
- return;
- }
- checkpointSystem.SaveCheckpoint();
- Debug.Log("[RespawnTester] 💾 Checkpoint saved at current position");
- }
- /// <summary>
- /// Force respawn without dying
- /// </summary>
- public void ForceRespawn()
- {
- if (gameManager == null)
- {
- Debug.LogError("[RespawnTester] Cannot respawn: GameManager not found");
- return;
- }
- Debug.Log("[RespawnTester] 🔄 Forcing respawn...");
- gameManager.RespawnParty();
- }
- /// <summary>
- /// Heal all party members to full
- /// </summary>
- public void HealAllPartyMembers()
- {
- if (cohesionManager == null || cohesionManager.groupMembers == null)
- {
- Debug.LogError("[RespawnTester] Cannot heal party: CohesionManager not found");
- return;
- }
- Debug.Log("[RespawnTester] ❤️ Healing all party members to full");
- foreach (var character in cohesionManager.groupMembers)
- {
- character.currentHP = character.maxHP;
- character.currentFatigue = character.maxFatigue;
- character.currentMana = character.maxMana;
-
- UIUpdater.Instance?.UpdateCharacterHP(character);
- UIUpdater.Instance?.UpdateCharacterFatigue(character);
- }
- }
- private void OnGUI()
- {
- if (!showDebugUI) return;
- // Create debug UI panel
- GUILayout.BeginArea(new Rect(10, 10, 300, 300));
- GUILayout.BeginVertical("box");
-
- GUILayout.Label("=== RESPAWN SYSTEM TESTER ===");
- GUILayout.Space(10);
-
- GUILayout.Label($"[{killPartyKey}] Kill Party");
- GUILayout.Label($"[{damagePartyKey}] Damage Party (-20 HP)");
- GUILayout.Label($"[{saveCheckpointKey}] Save Checkpoint");
- GUILayout.Label($"[{respawnKey}] Force Respawn");
- GUILayout.Label($"[F1] Toggle This UI");
-
- GUILayout.Space(10);
-
- // Show party status
- if (cohesionManager != null && cohesionManager.groupMembers != null)
- {
- GUILayout.Label("--- Party Status ---");
- foreach (var character in cohesionManager.groupMembers)
- {
- GUILayout.Label($"{character.characterName}: {character.currentHP}/{character.maxHP} HP");
- }
- }
-
- GUILayout.Space(10);
-
- // Checkpoint status
- if (checkpointSystem != null)
- {
- bool hasCheckpoint = checkpointSystem.HasCheckpoint();
- GUILayout.Label($"Checkpoint: {(hasCheckpoint ? "✓ Saved" : "✗ None")}");
-
- if (hasCheckpoint)
- {
- Vector3 pos = checkpointSystem.GetCheckpointPosition();
- GUILayout.Label($"Location: ({pos.x:F1}, {pos.y:F1}, {pos.z:F1})");
- }
- }
-
- GUILayout.Space(10);
-
- // Manual buttons
- if (GUILayout.Button("Kill Party"))
- KillAllPartyMembers();
-
- if (GUILayout.Button("Damage Party"))
- DamageAllPartyMembers(20);
-
- if (GUILayout.Button("Save Checkpoint"))
- SaveCheckpoint();
-
- if (GUILayout.Button("Heal Party"))
- HealAllPartyMembers();
-
- GUILayout.EndVertical();
- GUILayout.EndArea();
- }
- }
|