using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Collections.Generic;
///
/// UI display for AI agent statistics and controls
/// Shows agent count, exploration progress, and allows runtime agent spawning
///
public class AIAgentUIDisplay : MonoBehaviour
{
[Header("UI Elements")]
[SerializeField] private TextMeshProUGUI statsDisplay;
[SerializeField] private TextMeshProUGUI controlsDisplay;
[SerializeField] private Canvas uiCanvas;
[Header("Settings")]
[SerializeField] private float updateInterval = 1f;
[SerializeField] private bool autoCreateUI = true;
private MazeController mazeController;
private AIAgentManager agentManager;
private float lastUpdateTime = 0f;
void Start()
{
mazeController = FindAnyObjectByType();
if (mazeController != null)
{
agentManager = mazeController.GetAgentManager();
}
if (autoCreateUI && statsDisplay == null)
{
CreateUI();
}
}
void Update()
{
if (agentManager == null) return;
if (Time.time - lastUpdateTime > updateInterval)
{
UpdateDisplay();
lastUpdateTime = Time.time;
}
// Handle keyboard input for spawning agents
HandleInput();
}
///
/// Updates the stats display
///
private void UpdateDisplay()
{
if (statsDisplay == null) return;
string stats = agentManager.GetAgentStats();
statsDisplay.text = stats;
}
///
/// Handles keyboard input for agent management
///
private void HandleInput()
{
if (Input.GetKeyDown(KeyCode.A))
{
Debug.Log("Spawning 1 agent");
agentManager.SpawnAgent();
}
if (Input.GetKeyDown(KeyCode.S))
{
Debug.Log("Spawning 5 agents");
agentManager.SpawnAgents(5);
}
if (Input.GetKeyDown(KeyCode.C))
{
Debug.Log("Clearing all agents");
agentManager.ClearAllAgents();
}
}
///
/// Creates a simple UI if none exists
///
private void CreateUI()
{
// Create canvas if needed
if (uiCanvas == null)
{
GameObject canvasGO = new GameObject("AgentUICanvas");
uiCanvas = canvasGO.AddComponent