| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- using UnityEngine;
- /// <summary>
- /// Example scene setup for AI agents
- /// Shows how to configure and use the AI agent system
- /// </summary>
- public class AIAgentExampleSetup : MonoBehaviour
- {
- [Header("Configuration")]
- [SerializeField] private int initialAgentCount = 10;
- [SerializeField] private string agentCharacterType = "Default";
- [Header("Debug")]
- [SerializeField] private bool logStats = true;
- [SerializeField] private float statsLogInterval = 5f;
- private MazeController mazeController;
- private AIAgentManager agentManager;
- private float lastStatsLog = 0f;
- void Start()
- {
- mazeController = FindAnyObjectByType<MazeController>();
- if (mazeController == null)
- {
- Debug.LogError("AIAgentExampleSetup: MazeController not found in scene!");
- return;
- }
- // Get the agent manager
- agentManager = mazeController.GetAgentManager();
- if (agentManager == null)
- {
- Debug.LogError("AIAgentExampleSetup: Agent manager not found! Make sure spawnAIAgents is enabled on MazeController.");
- return;
- }
- // Configure agent count if not already set
- if (initialAgentCount > 0)
- {
- agentManager.SetInitialAgentCount(initialAgentCount);
- }
- Debug.Log($"AI Agent Example Setup initialized. Agents will spawn when maze is generated.");
- Debug.Log($"Configuration: {initialAgentCount} agents of type '{agentCharacterType}'");
- Debug.Log("Controls:");
- Debug.Log(" A - Spawn 1 agent");
- Debug.Log(" S - Spawn 5 agents");
- Debug.Log(" C - Clear all agents");
- }
- void Update()
- {
- if (agentManager == null) return;
- // Log statistics periodically
- if (logStats && Time.time - lastStatsLog > statsLogInterval)
- {
- LogAgentStats();
- lastStatsLog = Time.time;
- }
- // Handle example keyboard input
- HandleExampleInput();
- }
- /// <summary>
- /// Logs agent statistics to console
- /// </summary>
- private void LogAgentStats()
- {
- string stats = agentManager.GetAgentStats();
- Debug.Log("=== Agent Statistics ===\n" + stats);
- }
- /// <summary>
- /// Handles example keyboard input for agent management
- /// </summary>
- private void HandleExampleInput()
- {
- // Spawn 1 agent
- if (Input.GetKeyDown(KeyCode.A))
- {
- var newAgent = agentManager.SpawnAgent();
- if (newAgent != null)
- {
- Debug.Log($"Spawned agent {newAgent.AgentId}");
- }
- }
- // Spawn 5 agents
- if (Input.GetKeyDown(KeyCode.S))
- {
- agentManager.SpawnAgents(5);
- Debug.Log("Spawning 5 agents...");
- }
- // Clear all agents
- if (Input.GetKeyDown(KeyCode.C))
- {
- agentManager.ClearAllAgents();
- Debug.Log("Cleared all agents");
- }
- // Log stats
- if (Input.GetKeyDown(KeyCode.L))
- {
- LogAgentStats();
- }
- // Regenerate maze
- if (Input.GetKeyDown(KeyCode.R))
- {
- Debug.Log("Regenerating maze...");
- mazeController.GenerateMaze();
- }
- }
- }
|