using UnityEngine; using UnityEngine.UIElements; using System.Collections.Generic; /// /// Manages the UI Toolkit-based Agent Stats display /// Shows total active agents and count that have reached an exit /// public class AgentStatsUIController : MonoBehaviour { [Header("UI Settings")] [SerializeField] private UIDocument uiDocument; [SerializeField] private float updateInterval = 0.25f; private Label totalAgentsLabel; private Label exitReachedLabel; private Label killedLabel; private Label monstersKilledLabel; private AIAgentManager agentManager; private MazeController mazeController; private float lastUpdateTime = 0f; private int lastTotalCount = -1; private int lastExitCount = -1; private int lastKilledCount = -1; private int lastMonstersKilledCount = -1; void Start() { // Find references in Start instead of Awake for better timing if (uiDocument == null) { uiDocument = GetComponent(); // If not on this GameObject, try to find it in the scene if (uiDocument == null) { uiDocument = FindAnyObjectByType(); Debug.Log("AgentStatsUIController: Found UIDocument in scene"); } if (uiDocument == null) { Debug.LogError("AgentStatsUIController: UIDocument not found anywhere in scene!"); enabled = false; return; } } // Get the root and find labels var root = uiDocument.rootVisualElement; if (root == null) { Debug.LogError("AgentStatsUIController: Root visual element is null!"); return; } totalAgentsLabel = root.Q