using UnityEngine;
///
/// Force test the SettlementInteractionManager detection logic
///
public class SettlementInteractionTest : MonoBehaviour
{
[ContextMenu("Force Test Settlement Detection")]
public void ForceTestSettlementDetection()
{
Debug.Log("=== FORCING SETTLEMENT INTERACTION MANAGER TEST ===");
var settlementManager = FindFirstObjectByType();
if (settlementManager == null)
{
Debug.LogError("ā SettlementInteractionManager not found");
return;
}
Debug.Log("ā
SettlementInteractionManager found");
Debug.Log($" GameObject: {settlementManager.gameObject.name}");
Debug.Log($" Enabled: {settlementManager.enabled}");
Debug.Log($" GameObject Active: {settlementManager.gameObject.activeInHierarchy}");
// Get private fields using reflection to see current state
var teamMarkerField = typeof(SettlementInteractionManager).GetField("teamMarker",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var mapDataField = typeof(SettlementInteractionManager).GetField("mapData",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var currentNearbySettlementField = typeof(SettlementInteractionManager).GetField("currentNearbySettlement",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (teamMarkerField != null)
{
var teamMarker = teamMarkerField.GetValue(settlementManager) as Transform;
Debug.Log($" TeamMarker reference: {(teamMarker != null ? teamMarker.name : "NULL")}");
}
if (mapDataField != null)
{
var mapData = mapDataField.GetValue(settlementManager);
Debug.Log($" MapData reference: {(mapData != null ? "EXISTS" : "NULL")}");
}
if (currentNearbySettlementField != null)
{
var currentSettlement = currentNearbySettlementField.GetValue(settlementManager);
Debug.Log($" Current nearby settlement: {(currentSettlement != null ? "EXISTS" : "NULL")}");
}
// Force call the CheckForSettlementInteraction method using reflection
Debug.Log("\nš FORCING CheckForSettlementInteraction()...");
var checkMethod = typeof(SettlementInteractionManager).GetMethod("CheckForSettlementInteraction",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (checkMethod != null)
{
try
{
checkMethod.Invoke(settlementManager, null);
Debug.Log("ā
CheckForSettlementInteraction() called successfully");
}
catch (System.Exception e)
{
Debug.LogError($"ā Error calling CheckForSettlementInteraction(): {e.Message}");
}
}
else
{
Debug.LogError("ā CheckForSettlementInteraction method not found");
}
// Check state after forced call
if (currentNearbySettlementField != null)
{
var currentSettlement = currentNearbySettlementField.GetValue(settlementManager);
Debug.Log($" Current nearby settlement AFTER: {(currentSettlement != null ? "EXISTS" : "NULL")}");
}
}
}