Files
RaidersRPG/Assets/Scripts/RTSDebugger.cs
SHOUTING_PIRATE 3d2d2dc3e3 Initial commit
2025-07-01 21:03:21 +01:00

167 lines
5.7 KiB
C#

using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class RTSDebugger : MonoBehaviour
{
[Header("Debug Settings")]
public bool showDebugInfo = true;
public bool drawLayerInfo = true;
public KeyCode debugKey = KeyCode.F1;
void Update()
{
if (Input.GetKeyDown(debugKey))
{
DebugSceneSetup();
}
}
void OnGUI()
{
if (!showDebugInfo) return;
GUILayout.BeginArea(new Rect(Screen.width - 300, 10, 290, 300));
GUILayout.BeginVertical("box");
GUILayout.Label("RTS Debug Info");
// Units info
Unit[] units = FindObjectsByType<Unit>(FindObjectsSortMode.None);
GUILayout.Label($"Units in scene: {units.Length}");
foreach (Unit unit in units)
{
GUILayout.Label($"- {unit.name}: Layer {unit.gameObject.layer}");
}
// Ground info
GameObject ground = GameObject.Find("Ground");
if (ground != null)
{
GUILayout.Label($"Ground: Layer {ground.layer}");
}
else
{
GUILayout.Label("Ground: NOT FOUND");
}
// Camera controller info
CameraController camController = FindFirstObjectByType<CameraController>();
if (camController != null)
{
GUILayout.Label("Camera Controller: Found");
// Use reflection to access private fields for debugging
var selectedUnitsField = typeof(CameraController).GetField("selectedUnits",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (selectedUnitsField != null)
{
var selectedUnits = selectedUnitsField.GetValue(camController) as System.Collections.Generic.List<GameObject>;
GUILayout.Label($"Selected units: {selectedUnits?.Count ?? 0}");
}
}
else
{
GUILayout.Label("Camera Controller: NOT FOUND");
}
// Unit Manager info
UnitManager unitManager = FindFirstObjectByType<UnitManager>();
if (unitManager != null)
{
GUILayout.Label("Unit Manager: Found");
GUILayout.Label($"Total units: {unitManager.GetTotalUnitCount()}");
}
else
{
GUILayout.Label("Unit Manager: NOT FOUND");
}
GUILayout.Space(10);
GUILayout.Label($"Press {debugKey} for detailed debug");
GUILayout.EndVertical();
GUILayout.EndArea();
}
void DebugSceneSetup()
{
Debug.Log("=== RTS Scene Debug Info ===");
// Check units
Unit[] units = FindObjectsByType<Unit>(FindObjectsSortMode.None);
Debug.Log($"Units found: {units.Length}");
foreach (Unit unit in units)
{
Debug.Log($"Unit: {unit.name} - Layer: {unit.gameObject.layer} - Position: {unit.transform.position}");
// Check if unit has required components
if (unit.GetComponent<UnityEngine.AI.NavMeshAgent>() == null)
Debug.LogWarning($"Unit {unit.name} is missing NavMeshAgent!");
if (unit.GetComponent<Collider>() == null)
Debug.LogWarning($"Unit {unit.name} is missing Collider!");
}
// Check ground
GameObject ground = GameObject.Find("Ground");
if (ground != null)
{
Debug.Log($"Ground found: {ground.name} - Layer: {ground.layer}");
}
else
{
Debug.LogError("Ground object not found! Create a plane named 'Ground' on layer 9");
}
// Check NavMesh
UnityEngine.AI.NavMeshTriangulation navMesh = UnityEngine.AI.NavMesh.CalculateTriangulation();
Debug.Log($"NavMesh triangles: {navMesh.indices.Length / 3}");
if (navMesh.indices.Length == 0)
{
Debug.LogError("NavMesh not baked! Go to Window → AI → Navigation and bake the NavMesh");
}
// Check camera controller
CameraController camController = FindFirstObjectByType<CameraController>();
if (camController != null)
{
Debug.Log("Camera Controller found");
// Check layer masks
var unitLayerField = typeof(CameraController).GetField("unitLayer",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var groundLayerField = typeof(CameraController).GetField("groundLayer",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (unitLayerField != null && groundLayerField != null)
{
LayerMask unitLayer = (LayerMask)unitLayerField.GetValue(camController);
LayerMask groundLayer = (LayerMask)groundLayerField.GetValue(camController);
Debug.Log($"Camera unit layer mask: {unitLayer.value} (should be 256 for layer 8)");
Debug.Log($"Camera ground layer mask: {groundLayer.value} (should be 512 for layer 9)");
}
}
else
{
Debug.LogError("Camera Controller not found!");
}
// Check unit manager
UnitManager unitManager = FindFirstObjectByType<UnitManager>();
if (unitManager != null)
{
Debug.Log($"Unit Manager found - Total units: {unitManager.GetTotalUnitCount()}");
}
else
{
Debug.LogError("Unit Manager not found!");
}
Debug.Log("=== End Debug Info ===");
}
}