using Assets.Domain.Agents; using System.Collections.Generic; using UnityEngine; public class SampleAgentPresenter : MonoBehaviour { [Header("Agent Shape")] public GameObject agentShape; [Header("MQTT Controller Script")] public MqttController Controller; public Dictionary ActiveAgents = new Dictionary(); public void Update() { if (Controller.isConnected) { foreach (KeyValuePair> topicWithAgents in Controller.ActiveAgentsPerTopic) { UpdateAgents(topicWithAgents.Value); } } } private void UpdateAgents(Dictionary agents) { foreach (KeyValuePair agent in agents) { UpdateAgent(agent.Value); } } private void UpdateAgent(SimulationAgent agent) { Vector3 newPos = new Vector3((float)agent.Position.x, (float)agent.Position.z, (float)agent.Position.y); if (!ActiveAgents.ContainsKey(agent.Name)) { GameObject newAgent = Instantiate(agentShape); newAgent.name = agent.Name; ActiveAgents.Add(agent.Name, newAgent); } ActiveAgents[agent.Name].transform.position = newPos; } }