SettlementInteractionTest.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using UnityEngine;
  2. /// <summary>
  3. /// Force test the SettlementInteractionManager detection logic
  4. /// </summary>
  5. public class SettlementInteractionTest : MonoBehaviour
  6. {
  7. [ContextMenu("Force Test Settlement Detection")]
  8. public void ForceTestSettlementDetection()
  9. {
  10. Debug.Log("=== FORCING SETTLEMENT INTERACTION MANAGER TEST ===");
  11. var settlementManager = FindFirstObjectByType<SettlementInteractionManager>();
  12. if (settlementManager == null)
  13. {
  14. Debug.LogError("❌ SettlementInteractionManager not found");
  15. return;
  16. }
  17. Debug.Log("✅ SettlementInteractionManager found");
  18. Debug.Log($" GameObject: {settlementManager.gameObject.name}");
  19. Debug.Log($" Enabled: {settlementManager.enabled}");
  20. Debug.Log($" GameObject Active: {settlementManager.gameObject.activeInHierarchy}");
  21. // Get private fields using reflection to see current state
  22. var teamMarkerField = typeof(SettlementInteractionManager).GetField("teamMarker",
  23. System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  24. var mapDataField = typeof(SettlementInteractionManager).GetField("mapData",
  25. System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  26. var currentNearbySettlementField = typeof(SettlementInteractionManager).GetField("currentNearbySettlement",
  27. System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  28. if (teamMarkerField != null)
  29. {
  30. var teamMarker = teamMarkerField.GetValue(settlementManager) as Transform;
  31. Debug.Log($" TeamMarker reference: {(teamMarker != null ? teamMarker.name : "NULL")}");
  32. }
  33. if (mapDataField != null)
  34. {
  35. var mapData = mapDataField.GetValue(settlementManager);
  36. Debug.Log($" MapData reference: {(mapData != null ? "EXISTS" : "NULL")}");
  37. }
  38. if (currentNearbySettlementField != null)
  39. {
  40. var currentSettlement = currentNearbySettlementField.GetValue(settlementManager);
  41. Debug.Log($" Current nearby settlement: {(currentSettlement != null ? "EXISTS" : "NULL")}");
  42. }
  43. // Force call the CheckForSettlementInteraction method using reflection
  44. Debug.Log("\n🔍 FORCING CheckForSettlementInteraction()...");
  45. var checkMethod = typeof(SettlementInteractionManager).GetMethod("CheckForSettlementInteraction",
  46. System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  47. if (checkMethod != null)
  48. {
  49. try
  50. {
  51. checkMethod.Invoke(settlementManager, null);
  52. Debug.Log("✅ CheckForSettlementInteraction() called successfully");
  53. }
  54. catch (System.Exception e)
  55. {
  56. Debug.LogError($"❌ Error calling CheckForSettlementInteraction(): {e.Message}");
  57. }
  58. }
  59. else
  60. {
  61. Debug.LogError("❌ CheckForSettlementInteraction method not found");
  62. }
  63. // Check state after forced call
  64. if (currentNearbySettlementField != null)
  65. {
  66. var currentSettlement = currentNearbySettlementField.GetValue(settlementManager);
  67. Debug.Log($" Current nearby settlement AFTER: {(currentSettlement != null ? "EXISTS" : "NULL")}");
  68. }
  69. }
  70. }