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