# Agent Stats UI Toolkit Setup A modern UI Toolkit-based display for your Active Agents (Runners) showing total count and agents that reached exits. ## Files Created 1. **Assets/UI/AgentStatsPanel.uxml** - UI structure 2. **Assets/UI/AgentStatsPanel.uss** - Modern styling with dark theme 3. **Assets/Scripts/AgentStatsUIController.cs** - Controller script ## Setup Instructions ### Step 1: Create UIDocument GameObject 1. In your scene, select the Canvas or create a new GameObject 2. Add a **UIDocument** component 3. In the UIDocument inspector, set the **Panel Asset** to `AgentStatsPanel.uxml` ### Step 2: Add the Controller Script 1. On the same GameObject as UIDocument, add the **AgentStatsUIController** script 2. The script will automatically find your MazeController and AIAgentManager ### Step 3: (Optional) Configure Update Interval - In the AgentStatsUIController inspector, adjust **Update Interval** (default: 0.5 seconds) - Lower values = more frequent UI updates, higher CPU usage - Higher values = less frequent updates, smoother performance ## Visual Features ### Design - **Centered at top** of screen - **Dark semi-transparent background** with blue accent border - **Two stat rows**: - Total active agents (cyan text) - Agents that reached an exit (green text) ### Styling - Modern glassmorphism effect with inset shadows - Color-coded stats (blue for total, green for reached exit) - Responsive layout that scales with UI ## How It Works 1. **AgentStatsUIController** runs every frame 2. Every 0.5 seconds (configurable), it: - Gets total agent count from AIAgentManager - Iterates through all active agents checking `HasReachedGoal` property - Updates UI labels with current counts ## Requirements - ✅ UIToolkit enabled in project - ✅ AIAgentManager with public methods added (DONE) - ✅ AIAgent with `HasReachedGoal` property exposed (DONE) ## Customization ### Change Update Speed Edit `AgentStatsUIController`: ```csharp [SerializeField] private float updateInterval = 0.5f; // Change this value ``` ### Change Colors Edit `AgentStatsPanel.uss`: ```css .stat-value { color: #4a9eff; /* Change blue to your preference */ } .stat-value--success { color: #2ecc71; /* Change green to your preference */ } ``` ### Change Title Text Edit `AgentStatsPanel.uxml`: ```xml ``` ### Adjust Position Edit `AgentStatsPanel.uss`: ```css .panel-container { top: 20px; /* Adjust vertical position */ /* Or use 'bottom' instead of 'top' */ } ``` ## Troubleshooting **UI doesn't appear:** - Verify UIDocument is set to use AgentStatsPanel.uxml - Check that AgentStatsUIController script is on the same GameObject - Ensure MazeController exists in scene **Stats not updating:** - Check AgentStatsUIController is enabled - Verify AIAgentManager is accessible from MazeController - Check console for errors **Wrong text showing:** - Verify label names match: "TotalAgentsLabel" and "ExitReachedLabel" - Check UXML file hasn't been modified ## Next Steps - Add animations on stat changes - Add agent type breakdown - Add statistics history/graphs - Add pause/resume controls for simulation