using UnityEngine; using UnityEngine.UI; /// /// Automatic setup script for the Combat Scene Integration system /// Run this in the Unity Editor to quickly set up the system in your scenes /// public class CombatIntegrationSetup : MonoBehaviour { [Header("Setup Configuration")] [Tooltip("The name of your battle scene")] public string battleSceneName = "BattleScene"; [Tooltip("Enable debug logging for all components")] public bool enableDebugLogs = false; [Header("Setup Actions")] [Tooltip("Set up the map scene with CombatSceneManager")] public bool setupMapScene = true; [Tooltip("Set up the battle scene with EnhancedBattleSetup")] public bool setupBattleScene = true; [Header("UI Setup")] [Tooltip("Create a battle context UI text element")] public bool createBattleContextUI = true; [Tooltip("Font size for the battle context text")] public int contextTextFontSize = 18; /// /// Set up the entire combat integration system /// [ContextMenu("Setup Combat Integration System")] public void SetupSystem() { Debug.Log("πŸ”§ Setting up Combat Integration System..."); string currentScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; if (setupMapScene && IsMapScene(currentScene)) { SetupMapSceneComponents(); } if (setupBattleScene && IsBattleScene(currentScene)) { SetupBattleSceneComponents(); } Debug.Log("βœ… Combat Integration System setup complete!"); Debug.Log("πŸ“– See COMBAT_SCENE_INTEGRATION_GUIDE.md for usage instructions"); } /// /// Set up components needed in the map scene /// [ContextMenu("Setup Map Scene")] public void SetupMapSceneComponents() { Debug.Log("πŸ—ΊοΈ Setting up map scene components..."); // 1. Find or create CombatSceneManager var existingManager = FindFirstObjectByType(); if (existingManager == null) { GameObject managerObj = new GameObject("CombatSceneManager"); var manager = managerObj.AddComponent(); // Configure the manager SetManagerProperties(manager); Debug.Log("βœ… Created CombatSceneManager"); } else { SetManagerProperties(existingManager); Debug.Log("βœ… Found and configured existing CombatSceneManager"); } // 2. Verify CombatEventIntegration exists var combatIntegration = FindFirstObjectByType(); if (combatIntegration == null) { Debug.LogWarning("⚠️ No CombatEventIntegration found in scene - please ensure it's set up for combat events to work"); } else { Debug.Log("βœ… Found CombatEventIntegration"); } // 3. Check for terrain generator var terrainGen = FindFirstObjectByType(); if (terrainGen == null) { Debug.LogWarning("⚠️ No BFMTerrainGenerator found - terrain effects will be limited"); } else { Debug.Log("βœ… Found BFMTerrainGenerator"); } } /// /// Set up components needed in the battle scene /// [ContextMenu("Setup Battle Scene")] public void SetupBattleSceneComponents() { Debug.Log("βš”οΈ Setting up battle scene components..."); // 1. Find existing BattleSetup var battleSetup = FindFirstObjectByType(); if (battleSetup == null) { Debug.LogError("❌ No BattleSetup component found in scene! Please ensure you're in the correct battle scene."); return; } // 2. Add EnhancedBattleSetup if not present var enhancedSetup = battleSetup.GetComponent(); if (enhancedSetup == null) { enhancedSetup = battleSetup.gameObject.AddComponent(); Debug.Log("βœ… Added EnhancedBattleSetup component"); } else { Debug.Log("βœ… Found existing EnhancedBattleSetup component"); } // Configure enhanced setup SetEnhancedSetupProperties(enhancedSetup); // 3. Set up terrain generator var terrainGen = FindFirstObjectByType(); if (terrainGen == null) { Debug.LogWarning("⚠️ No BFMTerrainGenerator found in battle scene - terrain setup will be skipped"); } else { enhancedSetup.terrainGenerator = terrainGen; Debug.Log("βœ… Connected BFMTerrainGenerator to EnhancedBattleSetup"); } // 4. Set up battle context UI if requested if (createBattleContextUI) { SetupBattleContextUI(enhancedSetup); } } /// /// Configure CombatSceneManager properties /// private void SetManagerProperties(CombatSceneManager manager) { if (manager == null) return; // Use reflection to set properties since we might have compilation issues var type = manager.GetType(); // Set battle scene name var battleSceneField = type.GetField("battleSceneName"); if (battleSceneField != null) { battleSceneField.SetValue(manager, battleSceneName); } // Set debug logs var debugField = type.GetField("showDebugLogs"); if (debugField != null) { debugField.SetValue(manager, enableDebugLogs); } Debug.Log($"πŸ“ Configured CombatSceneManager: scene='{battleSceneName}', debug={enableDebugLogs}"); } /// /// Configure EnhancedBattleSetup properties /// private void SetEnhancedSetupProperties(EnhancedBattleSetup enhancedSetup) { if (enhancedSetup == null) return; var type = enhancedSetup.GetType(); // Enable enhanced setup var useEnhancedField = type.GetField("useEnhancedSetup"); if (useEnhancedField != null) { useEnhancedField.SetValue(enhancedSetup, true); } // Set debug logs var debugField = type.GetField("showDebugLogs"); if (debugField != null) { debugField.SetValue(enhancedSetup, enableDebugLogs); } Debug.Log($"πŸ“ Configured EnhancedBattleSetup: enhanced=true, debug={enableDebugLogs}"); } /// /// Set up battle context UI /// private void SetupBattleContextUI(EnhancedBattleSetup enhancedSetup) { // Look for existing Canvas Canvas canvas = FindFirstObjectByType(); if (canvas == null) { Debug.LogWarning("⚠️ No Canvas found - cannot create battle context UI"); return; } // Check if battle context text already exists Transform existingText = canvas.transform.Find("BattleContextText"); if (existingText != null) { var existingTextComp = existingText.GetComponent(); if (existingTextComp != null) { AssignBattleContextText(enhancedSetup, existingTextComp); Debug.Log("βœ… Found and assigned existing BattleContextText"); return; } } // Create new battle context UI GameObject textObj = new GameObject("BattleContextText"); textObj.transform.SetParent(canvas.transform, false); // Add Text component Text textComponent = textObj.AddComponent(); textComponent.text = "Battle Context Will Appear Here"; textComponent.fontSize = contextTextFontSize; textComponent.color = Color.white; textComponent.alignment = TextAnchor.UpperCenter; // Try to assign a font textComponent.font = Resources.GetBuiltinResource("LegacyRuntime.ttf"); // Position at top of screen RectTransform rectTransform = textComponent.GetComponent(); rectTransform.anchorMin = new Vector2(0, 1); rectTransform.anchorMax = new Vector2(1, 1); rectTransform.pivot = new Vector2(0.5f, 1); rectTransform.offsetMin = new Vector2(10, -100); rectTransform.offsetMax = new Vector2(-10, -10); // Assign to enhanced setup AssignBattleContextText(enhancedSetup, textComponent); Debug.Log("βœ… Created BattleContextText UI element"); } /// /// Assign battle context text to enhanced setup using reflection /// private void AssignBattleContextText(EnhancedBattleSetup enhancedSetup, Text textComponent) { var type = enhancedSetup.GetType(); var textField = type.GetField("battleContextText"); if (textField != null) { textField.SetValue(enhancedSetup, textComponent); Debug.Log("πŸ“ Assigned battle context text to EnhancedBattleSetup"); } } /// /// Check if current scene is a map scene /// private bool IsMapScene(string sceneName) { return sceneName.ToLower().Contains("map") || sceneName.ToLower().Contains("travel") || sceneName.ToLower().Contains("world"); } /// /// Check if current scene is a battle scene /// private bool IsBattleScene(string sceneName) { return sceneName.ToLower().Contains("battle") || sceneName.ToLower().Contains("combat") || sceneName.ToLower().Contains("fight"); } /// /// Validate the current setup /// [ContextMenu("Validate Setup")] public void ValidateSetup() { Debug.Log("πŸ” Validating Combat Integration Setup..."); string currentScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; bool isValid = true; if (IsMapScene(currentScene)) { isValid &= ValidateMapScene(); } else if (IsBattleScene(currentScene)) { isValid &= ValidateBattleScene(); } else { Debug.LogWarning($"⚠️ Unknown scene type: {currentScene}"); } if (isValid) { Debug.Log("βœ… Setup validation passed!"); } else { Debug.LogWarning("⚠️ Setup validation found issues - see messages above"); } } /// /// Validate map scene setup /// private bool ValidateMapScene() { bool valid = true; // Check CombatSceneManager var manager = FindFirstObjectByType(); if (manager == null) { Debug.LogError("❌ CombatSceneManager not found in map scene"); valid = false; } else { Debug.Log("βœ… CombatSceneManager found"); } // Check CombatEventIntegration var integration = FindFirstObjectByType(); if (integration == null) { Debug.LogWarning("⚠️ CombatEventIntegration not found - combat events may not work"); } else { Debug.Log("βœ… CombatEventIntegration found"); } return valid; } /// /// Validate battle scene setup /// private bool ValidateBattleScene() { bool valid = true; // Check BattleSetup var battleSetup = FindFirstObjectByType(); if (battleSetup == null) { Debug.LogError("❌ BattleSetup not found in battle scene"); valid = false; } else { Debug.Log("βœ… BattleSetup found"); // Check EnhancedBattleSetup var enhancedSetup = battleSetup.GetComponent(); if (enhancedSetup == null) { Debug.LogWarning("⚠️ EnhancedBattleSetup not found - enhanced features will not work"); } else { Debug.Log("βœ… EnhancedBattleSetup found"); } } return valid; } /// /// Clean up this setup script (remove it after setup is complete) /// [ContextMenu("Remove Setup Script")] public void RemoveSetupScript() { Debug.Log("🧹 Removing CombatIntegrationSetup script..."); DestroyImmediate(this); } }