void FixedUpdate()
        {
            if (msgList.Count > 0)
            {
                MqttMsgPublishEventArgs e = msgList[0];
                if (!MqttSetting.getTopicsInList().Contains(e.Topic))
                {
                    Debug.Log("-> The Topic '" + e.Topic + "' doesn't exist in the defined list. Please check! (the message will be deleted!)");
                    msgList.Remove(e);
                    return;
                }

                receivedMsg = System.Text.Encoding.UTF8.GetString(e.Message);
                //Debug.Log ("-> Received Message is : " + receivedMsg);
                allObjects = UnityEngine.Object.FindObjectsOfType <GameObject>();

                switch (e.Topic)
                {
                case MqttSetting.MAIN_TOPIC:

                    Debug.Log("-> Topic to deal with is : " + MqttSetting.MAIN_TOPIC);
                    //Debug.Log("-> The message is : " + e.Message);

                    topicGameObject = gameObject;
                    GamaMessage gamaMessage = (GamaMessage)MsgSerialization.deserialization(receivedMsg, new GamaMessage());
                    targetGameObject = GameObject.Find(gamaMessage.receivers);

                    if (targetGameObject == null)
                    {
                        Debug.LogError(" Sorry, requested gameObject is null (" + gamaMessage.receivers + "). Please check you code! ");
                        break;
                    }

                    obj = new object[] { gamaMessage, targetGameObject };
                    //GamaManager obje = (GamaManager) FindObjectOfType(typeof(GamaManager));
                    GameObject.Find(IGamaManager.MAIN_TOPIC_MANAGER).GetComponent(IGamaManager.MAIN_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);


                    break;

                case MqttSetting.MONO_FREE_TOPIC:

                    Debug.Log("-> Topic to deal with is : " + MqttSetting.MONO_FREE_TOPIC);
                    MonoFreeTopicMessage monoFreeTopicMessage = (MonoFreeTopicMessage)MsgSerialization.deserialization(receivedMsg, new MonoFreeTopicMessage());
                    targetGameObject = GameObject.Find(monoFreeTopicMessage.objectName);
                    obj = new object[] { monoFreeTopicMessage, targetGameObject };

                    if (targetGameObject == null)
                    {
                        Debug.LogError(" Sorry, requested gameObject is null (" + monoFreeTopicMessage.objectName + "). Please check your code! ");
                        break;
                    }
                    Debug.Log("The message is to " + monoFreeTopicMessage.objectName + " about the methode " + monoFreeTopicMessage.methodName + " and attribute " + monoFreeTopicMessage.attribute);
                    GameObject.Find(IGamaManager.MONO_FREE_TOPIC_MANAGER).GetComponent(IGamaManager.MONO_FREE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);

                    break;

                case MqttSetting.MULTIPLE_FREE_TOPIC:

                    Debug.Log("-> Topic to deal with is : " + MqttSetting.MULTIPLE_FREE_TOPIC);

                    MultipleFreeTopicMessage multipleFreetopicMessage = (MultipleFreeTopicMessage)MsgSerialization.deserialization(receivedMsg, new MultipleFreeTopicMessage());
                    targetGameObject = GameObject.Find(multipleFreetopicMessage.objectName);
                    obj = new object[] { multipleFreetopicMessage, targetGameObject };

                    if (targetGameObject == null)
                    {
                        Debug.LogError(" Sorry, requested gameObject is null (" + multipleFreetopicMessage.objectName + "). Please check you code! ");
                        break;
                    }

                    GameObject.Find(IGamaManager.MULTIPLE_FREE_TOPIC_MANAGER).GetComponent(IGamaManager.MULTIPLE_FREE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);

                    break;

                case MqttSetting.POSITION_TOPIC:

                    Debug.Log("-> Topic to deal with is : " + MqttSetting.POSITION_TOPIC);

                    PositionTopicMessage positionTopicMessage = (PositionTopicMessage)MsgSerialization.deserialization(receivedMsg, new PositionTopicMessage());
                    targetGameObject = GameObject.Find(positionTopicMessage.objectName);
                    obj = new object[] { positionTopicMessage, targetGameObject };

                    if (targetGameObject == null)
                    {
                        Debug.LogError(" Sorry, requested gameObject is null (" + positionTopicMessage.objectName + "). Please check your code! ");
                        break;
                    }
                    else
                    {
                        GameObject.Find(IGamaManager.POSITION_TOPIC_MANAGER).GetComponent(IGamaManager.POSITION_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                    }


                    break;

                case MqttSetting.MOVE_TOPIC:

                    Debug.Log("-> Topic to deal with is : " + MqttSetting.MOVE_TOPIC);

                    MoveTopicMessage moveTopicMessage = (MoveTopicMessage)MsgSerialization.deserialization(receivedMsg, new MoveTopicMessage());
                    targetGameObject = GameObject.Find(moveTopicMessage.objectName);
                    obj = new object[] { moveTopicMessage, targetGameObject };

                    if (targetGameObject == null)
                    {
                        Debug.LogError(" Sorry, requested gameObject is null (" + moveTopicMessage.objectName + "). Please check you code! ");
                        break;
                    }

                    GameObject.Find(IGamaManager.MOVE_TOPIC_MANAGER).GetComponent(IGamaManager.MOVE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);

                    break;

                case MqttSetting.COLOR_TOPIC:

                    Debug.Log("-> Topic to deal with is : " + MqttSetting.COLOR_TOPIC);

                    ColorTopicMessage colorTopicMessage = (ColorTopicMessage)MsgSerialization.deserialization(receivedMsg, new ColorTopicMessage());
                    targetGameObject = GameObject.Find(colorTopicMessage.objectName);
                    obj = new object[] { colorTopicMessage, targetGameObject };

                    if (targetGameObject == null)
                    {
                        Debug.LogError(" Sorry, requested gameObject is null (" + colorTopicMessage.objectName + "). Please check you code! ");
                        break;
                    }

                    GameObject.Find(IGamaManager.COLOR_TOPIC_MANAGER).GetComponent(IGamaManager.COLOR_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);


                    break;

                case MqttSetting.GET_TOPIC:

                    Debug.Log("-> Topic to deal with is : " + MqttSetting.GET_TOPIC);
                    string value = null;

                    GetTopicMessage getTopicMessage = (GetTopicMessage)MsgSerialization.deserialization(receivedMsg, new GetTopicMessage());
                    targetGameObject = GameObject.Find(getTopicMessage.objectName);


                    if (targetGameObject == null)
                    {
                        Debug.LogError(" Sorry, requested gameObject is null (" + getTopicMessage.objectName + "). Please check you code! ");
                        break;
                    }

                    obj = new object[] { getTopicMessage, targetGameObject, value };

                    GameObject.Find(IGamaManager.GET_TOPIC_MANAGER).GetComponent(IGamaManager.GET_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                    sendReplay(clientId, "GamaAgent", getTopicMessage.attribute, (string)obj[2]);

                    break;

                case MqttSetting.SET_TOPIC:

                    Debug.Log("-> Topic to deal with is : " + MqttSetting.SET_TOPIC);

                    SetTopicMessage setTopicMessage = (SetTopicMessage)MsgSerialization.deserialization(receivedMsg, new SetTopicMessage());
                    // Debug.Log("-> Target game object name: " + setTopicMessage.objectName);
                    // Debug.Log("-> Message: " + receivedMsg);
                    targetGameObject = GameObject.Find(setTopicMessage.objectName);

                    if (targetGameObject == null)
                    {
                        Debug.LogError(" Sorry, requested gameObject is null (" + setTopicMessage.objectName + "). Please check you code! ");
                        break;
                    }

                    obj = new object[] { setTopicMessage, targetGameObject };

                    GameObject.Find(IGamaManager.SET_TOPIC_MANAGER).GetComponent(IGamaManager.SET_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);

                    break;

                case MqttSetting.PROPERTY_TOPIC:

                    Debug.Log("-> Topic to deal with is : " + MqttSetting.PROPERTY_TOPIC);

                    try
                    {
                    }
                    catch (Exception er)
                    {
                        Debug.Log("Error : " + er.Message);
                    }

                    PropertyTopicMessage propertyTopicMessage = (PropertyTopicMessage)MsgSerialization.deserialization(receivedMsg, new PropertyTopicMessage());
                    Debug.Log("-> Target game object name: " + propertyTopicMessage.objectName);
                    targetGameObject = GameObject.Find(propertyTopicMessage.objectName);

                    if (targetGameObject == null)
                    {
                        Debug.Log(" Sorry, requested gameObject is null (" + propertyTopicMessage.objectName + "). Please check you code! ");
                        // break;
                    }
                    else
                    {
                        obj = new object[] { propertyTopicMessage, targetGameObject };
                        GameObject.Find(IGamaManager.PROPERTY_TOPIC_MANAGER).GetComponent(IGamaManager.PROPERTY_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                    }


                    break;

                case MqttSetting.CREATE_TOPIC:

                    Debug.Log("-> Topic to deal with is : " + MqttSetting.CREATE_TOPIC);
                    // Debug.Log("-> Message: " + receivedMsg);
                    CreateTopicMessage createTopicMessage = (CreateTopicMessage)MsgSerialization.deserialization(receivedMsg, new CreateTopicMessage());
                    obj = new object[] { createTopicMessage };

                    GameObject.Find(IGamaManager.CREATE_TOPIC_MANAGER).GetComponent(IGamaManager.CREATE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);

                    break;

                case MqttSetting.DESTROY_TOPIC:

                    Debug.Log("-> Topic to deal with is : " + MqttSetting.DESTROY_TOPIC);

                    DestroyTopicMessage destroyTopicMessage = (DestroyTopicMessage)MsgSerialization.deserialization(receivedMsg, new DestroyTopicMessage());
                    obj = new object[] { destroyTopicMessage };

                    if (topicGameObject == null)
                    {
                        Debug.LogError(" Sorry, requested gameObject is null (" + destroyTopicMessage.objectName + "). Please check you code! ");
                        break;
                    }

                    GameObject.Find(IGamaManager.DESTROY_TOPIC_MANAGER).GetComponent(IGamaManager.DESTROY_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);

                    break;

                case MqttSetting.NOTIFICATION_TOPIC:

                    Debug.Log("-> Topic to deal with is : " + MqttSetting.NOTIFICATION_TOPIC);

                    NotificationTopicMessage notificationTopicMessage = (NotificationTopicMessage)MsgSerialization.deserialization(receivedMsg, new NotificationTopicMessage());
                    obj = new object[] { notificationTopicMessage };


                    if (topicGameObject == null)
                    {
                        Debug.LogError(" Sorry, requested gameObject is null (" + notificationTopicMessage.objectName + "). Please check you code! ");
                        break;
                    }

                    GameObject.Find(IGamaManager.NOTIFICATION_TOPIC_MANAGER).GetComponent(IGamaManager.NOTIFICATION_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);


                    break;

                default:

                    Debug.Log("-> Topic to deal with is : " + MqttSetting.DEFAULT_TOPIC);

                    break;
                }

                msgList.Remove(e);
            }

            checkForNotifications();
            GameObject mapBuilder = GameObject.Find("MapBuilder");

            //GameObject mapBuilder = GameObject.Find("MapBuilder");
            //regionMap = (RegionMap) FindObjectOfType(typeof(RegionMap));
            //GameObject mapBuilder  = (GameObject) FindObjectOfType(typeof(MapBuilder));

            if (mapBuilder != null)
            {
                mapBuilder.GetComponent <RegionMap>().SendMessage("DrawNewAgents");
            }
            else
            {
                Debug.Log("No such Object. Sorry");
            }
        }
示例#2
0
 public override void setAllProperties(object args)
 {
     object[] obj = (object[])args;
     this.topicMessage     = (PropertyTopicMessage)obj [0];
     this.targetGameObject = (GameObject)obj [1];
 }
示例#3
0
 public PropertyTopic(PropertyTopicMessage topicMessage, GameObject gameObj) : base(gameObj)
 {
     this.topicMessage = topicMessage;
 }
        public void HandleMessage()
        {
            while (connector.HasNextMessage())
            {
                MqttMsgPublishEventArgs e = connector.GetNextMessage();

                /*
                 *              if (!IMQTTConnector.getTopicsInList().Contains(e.Topic))
                 *              {
                 *                  Debug.Log("-> The Topic '" + e.Topic + "' doesn't exist in the defined list. Please check! (the message will be deleted!)");
                 *                  msgList.Remove(e);
                 *                  return;
                 *              }
                 */

                receivedMsg = System.Text.Encoding.UTF8.GetString(e.Message);

                Debug.Log("-> Received Message is : " + receivedMsg + " On topic : " + e.Topic);

                if (agentsTopicDic.Keys.Contains(e.Topic))
                {
                    // DO Not DELETE

                    /*
                     *                  string serialisedObject = new XStream().ToXml(receivedMsg);
                     *                  GamaExposeMessage deserialisedObject = (GamaExposeMessage) new XStream().FromXml(serialisedObject);
                     */
                    //Debug.Log("The topic is : " + e.Topic);
                    GamaExposeMessage exposeMessage = new GamaExposeMessage(receivedMsg);

                    sceneManager.SetAttribute(agentsTopicDic[e.Topic], exposeMessage.attributesList);
                }
                else
                {
                    switch (e.Topic)
                    {
                    //case "listdata":
                    //    break;
                    case IMQTTConnector.MAIN_TOPIC:
                        //------------------------------------------------------------------------------
                        Debug.Log("  -> Topic to deal with is : " + IMQTTConnector.MAIN_TOPIC);

                        UnityAgent unityAgent = (UnityAgent)MsgSerialization.FromXML(receivedMsg, new UnityAgent());
                        Agent      agent      = unityAgent.GetAgent();

                        switch (agent.Species)
                        {
                        case IUILittoSim.LAND_USE:
                            agent.Height = 10;
                            //agentCreator.GetComponent<AgentCreator>().CreateAgent(agent, Land_Use_Transform, matRed, IUILittoSim.LAND_USE_ID, true, ILittoSimConcept.LAND_USE_TAG, -60);
                            agentCreator.GetComponent <AgentCreator>().CreateGenericPolygonAgent(agent, true, ILittoSimConcept.LAND_USE_TAG, 0);       //-60);

                            break;

                        case IUILittoSim.COASTAL_DEFENSE:
                            agent.Height = 10;
                            //agentCreator.GetComponent<AgentCreator>().CreateAgent(agent, Land_Use_Transform, matYellow, IUILittoSim.COASTAL_DEFENSE_ID, true, ILittoSimConcept.COASTAL_DEFENSE_TAG, -80);
                            agentCreator.GetComponent <AgentCreator>().CreateGenericPolygonAgent(agent, true, ILittoSimConcept.COASTAL_DEFENSE_TAG, -80);
                            break;

                        case IUILittoSim.DISTRICT:
                            agent.Height = 10;
                            //agentCreator.GetComponent<AgentCreator>().CreateAgent(agent, Land_Use_Transform, matBlue, IUILittoSim.DISTRICT_ID, true, ILittoSimConcept.DISTRICT_TAG, -40);
                            agentCreator.GetComponent <AgentCreator>().CreateGenericPolygonAgent(agent, true, ILittoSimConcept.DISTRICT_TAG, -40);
                            break;

                        case IUILittoSim.FLOOD_RISK_AREA:
                            agent.Height = 10;
                            //agentCreator.GetComponent<AgentCreator>().CreateAgent(agent, Land_Use_Transform, matRed, IUILittoSim.FLOOD_RISK_AREA_ID, true, ILittoSimConcept.FLOOD_RISK_AREA_TAG, -100);
                            agentCreator.GetComponent <AgentCreator>().CreateGenericPolygonAgent(agent, true, ILittoSimConcept.FLOOD_RISK_AREA_TAG, -100);
                            break;

                        case IUILittoSim.PROTECTED_AREA:
                            agent.Height = 10;
                            //agentCreator.GetComponent<AgentCreator>().CreateAgent(agent, Land_Use_Transform, matGreenLighter, IUILittoSim.PROTECTED_AREA_ID, true, ILittoSimConcept.PROTECTED_AREA_TAG, -100);
                            agentCreator.GetComponent <AgentCreator>().CreateGenericPolygonAgent(agent, true, ILittoSimConcept.PROTECTED_AREA_TAG, -100);
                            break;

                        case IUILittoSim.ROAD:
                            agent.Height = 0;
                            //agentCreator.GetComponent<AgentCreator>().CreateAgent(agent, Land_Use_Transform, mat, IUILittoSim.ROAD_ID, false);
                            //agentCreator.GetComponent<AgentCreator>().CreateLineAgent(agent, Land_Use_Transform, matWhite, IUILittoSim.ROAD_ID, false, 10f, ILittoSimConcept.ROAD_TAG, -151);
                            agentCreator.GetComponent <AgentCreator>().CreateGenericLineAgent(agent, 10f, "Road", -151);
                            break;

                        default:
                            targetGameObject = GameObject.Find(unityAgent.receivers);
                            if (targetGameObject == null)
                            {
                                Debug.LogError(" Sorry, requested gameObject is null (" + unityAgent.receivers + "). Please check you code! ");
                                break;
                            }
                            else
                            {
                                Debug.Log("Generic Object creation : " + unityAgent.contents.agentName);
                                obj = new object[] { unityAgent, targetGameObject };
                                mainTopicManager.GetComponent <MainTopic>().ProcessTopic(obj);
                                //mainTopicManager.GetComponent(IMQTTConnector.MAIN_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                            }
                            break;
                        }

                        //------------------------------------------------------------------------------
                        break;

                    case IMQTTConnector.MONO_FREE_TOPIC:
                        //------------------------------------------------------------------------------
                        Debug.Log("-> Topic to deal with is : " + IMQTTConnector.MONO_FREE_TOPIC);
                        MonoFreeTopicMessage monoFreeTopicMessage = (MonoFreeTopicMessage)MsgSerialization.FromXML(receivedMsg, new MonoFreeTopicMessage());
                        targetGameObject = GameObject.Find(monoFreeTopicMessage.objectName);
                        obj = new object[] { monoFreeTopicMessage, targetGameObject };

                        if (targetGameObject == null)
                        {
                            Debug.LogError(" Sorry, requested gameObject is null (" + monoFreeTopicMessage.objectName + "). Please check your code! ");
                            break;
                        }
                        //    Debug.Log("The message is to " + monoFreeTopicMessage.objectName + " about the methode " + monoFreeTopicMessage.methodName + " and attribute " + monoFreeTopicMessage.attribute);
                        GameObject.Find(IMQTTConnector.MONO_FREE_TOPIC_MANAGER).GetComponent(IMQTTConnector.MONO_FREE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                        //------------------------------------------------------------------------------
                        break;

                    case IMQTTConnector.MULTIPLE_FREE_TOPIC:
                        //------------------------------------------------------------------------------
                        Debug.Log("-> Topic to deal with is : " + IMQTTConnector.MULTIPLE_FREE_TOPIC);

                        MultipleFreeTopicMessage multipleFreetopicMessage = (MultipleFreeTopicMessage)MsgSerialization.FromXML(receivedMsg, new MultipleFreeTopicMessage());



                        targetGameObject = GameObject.Find(multipleFreetopicMessage.objectName);

                        Debug.Log("-> Concerned Game Object is : " + multipleFreetopicMessage.objectName);

                        obj = new object[] { multipleFreetopicMessage, targetGameObject };

                        if (targetGameObject == null)
                        {
                            Debug.LogError(" Sorry, requested gameObject is null (" + multipleFreetopicMessage.objectName + "). Please check you code! ");
                            break;
                        }

                        GameObject.Find(IMQTTConnector.MULTIPLE_FREE_TOPIC_MANAGER).GetComponent(IMQTTConnector.MULTIPLE_FREE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                        //------------------------------------------------------------------------------
                        break;

                    case IMQTTConnector.POSITION_TOPIC:
                        //------------------------------------------------------------------------------
                        Debug.Log("-> Topic to deal with is : " + IMQTTConnector.POSITION_TOPIC);

                        PositionTopicMessage positionTopicMessage = (PositionTopicMessage)MsgSerialization.FromXML(receivedMsg, new PositionTopicMessage());
                        targetGameObject = GameObject.Find(positionTopicMessage.objectName);
                        obj = new object[] { positionTopicMessage, targetGameObject };

                        if (targetGameObject == null)
                        {
                            Debug.LogError(" Sorry, requested gameObject is null (" + positionTopicMessage.objectName + "). Please check you code! ");
                            break;
                        }
                        else
                        {
                            GameObject.Find(IMQTTConnector.POSITION_TOPIC_MANAGER).GetComponent(IMQTTConnector.POSITION_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                        }

                        //------------------------------------------------------------------------------
                        break;

                    case IMQTTConnector.MOVE_TOPIC:
                        //------------------------------------------------------------------------------
                        Debug.Log("-> Topic to deal with is : " + IMQTTConnector.MOVE_TOPIC);
                        Debug.Log("-> the message is : " + receivedMsg);
                        MoveTopicMessage moveTopicMessage = (MoveTopicMessage)MsgSerialization.FromXML(receivedMsg, new MoveTopicMessage());
                        Debug.Log("-> the position to move to is : " + moveTopicMessage.position);
                        Debug.Log("-> the speed is : " + moveTopicMessage.speed);
                        Debug.Log("-> the object to move is : " + moveTopicMessage.objectName);
                        targetGameObject = GameObject.Find(moveTopicMessage.objectName);
                        obj = new object[] { moveTopicMessage, targetGameObject };

                        if (targetGameObject == null)
                        {
                            Debug.LogError(" Sorry, requested gameObject is null (" + moveTopicMessage.objectName + "). Please check you code! ");
                            break;
                        }

                        GameObject.Find(IMQTTConnector.MOVE_TOPIC_MANAGER).GetComponent(IMQTTConnector.MOVE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                        //------------------------------------------------------------------------------
                        break;

                    case IMQTTConnector.COLOR_TOPIC:
                        //------------------------------------------------------------------------------
                        Debug.Log("-> Topic to deal with is : " + IMQTTConnector.COLOR_TOPIC);

                        ColorTopicMessage colorTopicMessage = (ColorTopicMessage)MsgSerialization.FromXML(receivedMsg, new ColorTopicMessage());
                        targetGameObject = GameObject.Find(colorTopicMessage.objectName);
                        obj = new object[] { colorTopicMessage, targetGameObject };

                        if (targetGameObject == null)
                        {
                            Debug.LogError(" Sorry, requested gameObject is null (" + colorTopicMessage.objectName + "). Please check you code! ");
                            break;
                        }

                        GameObject.Find(IMQTTConnector.COLOR_TOPIC_MANAGER).GetComponent(IMQTTConnector.COLOR_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);

                        //------------------------------------------------------------------------------
                        break;

                    case IMQTTConnector.GET_TOPIC:
                        //------------------------------------------------------------------------------
                        Debug.Log("-> Topic to deal with is : " + IMQTTConnector.GET_TOPIC);
                        string value = null;

                        GetTopicMessage getTopicMessage = (GetTopicMessage)MsgSerialization.FromXML(receivedMsg, new GetTopicMessage());
                        targetGameObject = GameObject.Find(getTopicMessage.objectName);


                        if (targetGameObject == null)
                        {
                            Debug.LogError(" Sorry, requested gameObject is null (" + getTopicMessage.objectName + "). Please check you code! ");
                            break;
                        }

                        obj = new object[] { getTopicMessage, targetGameObject, value };

                        GameObject.Find(IMQTTConnector.GET_TOPIC_MANAGER).GetComponent(IMQTTConnector.GET_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                        SendReplay(connector.clientId, "GamaAgent", getTopicMessage.attribute, (string)obj[2]);
                        //------------------------------------------------------------------------------
                        break;

                    case IMQTTConnector.SET_TOPIC:
                        //------------------------------------------------------------------------------
                        Debug.Log("-> Topic to deal with is : " + IMQTTConnector.SET_TOPIC);

                        SetTopicMessage setTopicMessage = (SetTopicMessage)MsgSerialization.FromXML(receivedMsg, new SetTopicMessage());
                        // Debug.Log("-> Target game object name: " + setTopicMessage.objectName);
                        Debug.Log("-> Message: " + receivedMsg);
                        targetGameObject = GameObject.Find(setTopicMessage.objectName);

                        if (targetGameObject == null)
                        {
                            Debug.LogError(" Sorry, requested gameObject is null (" + setTopicMessage.objectName + "). Please check you code! ");
                            break;
                        }

                        obj = new object[] { setTopicMessage, targetGameObject };

                        GameObject.Find(IMQTTConnector.SET_TOPIC_MANAGER).GetComponent(IMQTTConnector.SET_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                        //------------------------------------------------------------------------------
                        break;

                    case IMQTTConnector.PROPERTY_TOPIC:
                        //------------------------------------------------------------------------------
                        Debug.Log("-> Topic to deal with is : " + IMQTTConnector.PROPERTY_TOPIC);

                        try
                        {
                        }
                        catch (Exception er)
                        {
                            Debug.Log("Error : " + er.Message);
                        }

                        PropertyTopicMessage propertyTopicMessage = (PropertyTopicMessage)MsgSerialization.FromXML(receivedMsg, new PropertyTopicMessage());
                        Debug.Log("-> Target game object name: " + propertyTopicMessage.objectName);
                        targetGameObject = GameObject.Find(propertyTopicMessage.objectName);

                        if (targetGameObject == null)
                        {
                            Debug.LogError(" Sorry, requested gameObject is null (" + propertyTopicMessage.objectName + "). Please check you code! ");
                            break;
                        }

                        obj = new object[] { propertyTopicMessage, targetGameObject };

                        GameObject.Find(IMQTTConnector.PROPERTY_TOPIC_MANAGER).GetComponent(IMQTTConnector.PROPERTY_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                        //------------------------------------------------------------------------------
                        break;

                    case IMQTTConnector.CREATE_TOPIC:
                        //------------------------------------------------------------------------------
                        Debug.Log("-> Topic to deal with is : " + IMQTTConnector.CREATE_TOPIC);
                        Debug.Log("-> Message: " + receivedMsg);
                        CreateTopicMessage createTopicMessage = (CreateTopicMessage)MsgSerialization.FromXML(receivedMsg, new CreateTopicMessage());
                        obj = new object[] { createTopicMessage };

                        GameObject.Find(IMQTTConnector.CREATE_TOPIC_MANAGER).GetComponent(IMQTTConnector.CREATE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                        //------------------------------------------------------------------------------
                        break;

                    case IMQTTConnector.DESTROY_TOPIC:
                        //------------------------------------------------------------------------------
                        Debug.Log("-> Topic to deal with is : " + IMQTTConnector.DESTROY_TOPIC);

                        DestroyTopicMessage destroyTopicMessage = (DestroyTopicMessage)MsgSerialization.FromXML(receivedMsg, new DestroyTopicMessage());
                        obj = new object[] { destroyTopicMessage };

                        if (topicGameObject == null)
                        {
                            Debug.LogError(" Sorry, requested gameObject is null (" + destroyTopicMessage.objectName + "). Please check you code! ");
                            break;
                        }

                        GameObject.Find(IMQTTConnector.DESTROY_TOPIC_MANAGER).GetComponent(IMQTTConnector.DESTROY_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                        //------------------------------------------------------------------------------
                        break;

                    case IMQTTConnector.NOTIFICATION_TOPIC:
                        //------------------------------------------------------------------------------
                        Debug.Log("-> Topic to deal with is : " + IMQTTConnector.NOTIFICATION_TOPIC);

                        NotificationTopicMessage notificationTopicMessage = (NotificationTopicMessage)MsgSerialization.FromXML(receivedMsg, new NotificationTopicMessage());
                        obj = new object[] { notificationTopicMessage };


                        if (topicGameObject == null)
                        {
                            Debug.LogError(" Sorry, requested gameObject is null (" + notificationTopicMessage.objectName + "). Please check you code! ");
                            break;
                        }

                        GameObject.Find(IMQTTConnector.NOTIFICATION_TOPIC_MANAGER).GetComponent(IMQTTConnector.NOTIFICATION_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);

                        //------------------------------------------------------------------------------
                        break;

                    default:
                        //------------------------------------------------------------------------------
                        Debug.Log("-> Topic to deal with is : " + IMQTTConnector.DEFAULT_TOPIC);
                        //------------------------------------------------------------------------------
                        break;
                    }
                }
            }
            CheckForNotifications();
        }
示例#5
0
    void FixedUpdate()
    {
        Debug.Log("-> The number of all received agents is : " + gamaAgentList.Count);

        if (msgList.Count > 0)
        {
            MqttMsgPublishEventArgs e = msgList[0];
            if (!MqttSetting.getTopicsInList().Contains(e.Topic))
            {
                Debug.Log("-> The Topic '" + e.Topic + "' doesn't exist in the defined list. Please check!");
                return;
            }

            receivedMsg = System.Text.Encoding.UTF8.GetString(e.Message);
            //Debug.Log ("-> Received Message is : " + receivedMsg);
            allObjects = UnityEngine.Object.FindObjectsOfType <GameObject>();

            switch (e.Topic)
            {
            case MqttSetting.MAIN_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.MAIN_TOPIC);
                Debug.Log("-> The message is : " + e.Message);

                topicGameObject = gameObject;


                GamaMessage gamaMessage = (GamaMessage)msgDes.deserialization(receivedMsg, new GamaMessage());
                targetGameObject = getGameObjectByName(gamaMessage.receivers);

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + gamaMessage.receivers + "). Please check you code! ");
                    break;
                }

                obj = new object[] { gamaMessage, targetGameObject };

                getGameObjectByName(MqttSetting.MAIN_TOPIC_MANAGER).GetComponent(MqttSetting.MAIN_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);



                //------------------------------------------------------------------------------
                break;

            case MqttSetting.MONO_FREE_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.MONO_FREE_TOPIC);
                MonoFreeTopicMessage monoFreeTopicMessage = (MonoFreeTopicMessage)msgDes.deserialization(receivedMsg, new MonoFreeTopicMessage());
                targetGameObject = getGameObjectByName(monoFreeTopicMessage.objectName);
                obj = new object[] { monoFreeTopicMessage, targetGameObject };

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + monoFreeTopicMessage.objectName + "). Please check your code! ");
                    break;
                }

                getGameObjectByName(MqttSetting.MONO_FREE_TOPIC_MANAGER).GetComponent(MqttSetting.MONO_FREE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.MULTIPLE_FREE_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.MULTIPLE_FREE_TOPIC);

                MultipleFreeTopicMessage multipleFreetopicMessage = (MultipleFreeTopicMessage)msgDes.deserialization(receivedMsg, new MultipleFreeTopicMessage());
                targetGameObject = getGameObjectByName(multipleFreetopicMessage.objectName);
                obj = new object[] { multipleFreetopicMessage, targetGameObject };

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + multipleFreetopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                getGameObjectByName(MqttSetting.MULTIPLE_FREE_TOPIC_MANAGER).GetComponent(MqttSetting.MULTIPLE_FREE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.POSITION_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.POSITION_TOPIC);

                PositionTopicMessage positionTopicMessage = (PositionTopicMessage)msgDes.deserialization(receivedMsg, new PositionTopicMessage());
                targetGameObject = getGameObjectByName(positionTopicMessage.objectName);
                obj = new object[] { positionTopicMessage, targetGameObject };

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + positionTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                getGameObjectByName(MqttSetting.POSITION_TOPIC_MANAGER).GetComponent(MqttSetting.POSITION_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.MOVE_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.MOVE_TOPIC);

                MoveTopicMessage moveTopicMessage = (MoveTopicMessage)msgDes.deserialization(receivedMsg, new MoveTopicMessage());
                targetGameObject = getGameObjectByName(moveTopicMessage.objectName);
                obj = new object[] { moveTopicMessage, targetGameObject };

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + moveTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                getGameObjectByName(MqttSetting.MOVE_TOPIC_MANAGER).GetComponent(MqttSetting.MOVE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.COLOR_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.COLOR_TOPIC);

                ColorTopicMessage colorTopicMessage = (ColorTopicMessage)msgDes.deserialization(receivedMsg, new ColorTopicMessage());
                targetGameObject = getGameObjectByName(colorTopicMessage.objectName);
                obj = new object[] { colorTopicMessage, targetGameObject };

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + colorTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                getGameObjectByName(MqttSetting.COLOR_TOPIC_MANAGER).GetComponent(MqttSetting.COLOR_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);

                //------------------------------------------------------------------------------
                break;

            case MqttSetting.GET_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.GET_TOPIC);
                string value = null;

                GetTopicMessage getTopicMessage = (GetTopicMessage)msgDes.deserialization(receivedMsg, new GetTopicMessage());
                targetGameObject = getGameObjectByName(getTopicMessage.objectName);


                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + getTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                obj = new object[] { getTopicMessage, targetGameObject, value };

                getGameObjectByName(MqttSetting.GET_TOPIC_MANAGER).GetComponent(MqttSetting.GET_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                sendReplay(clientId, "GamaAgent", getTopicMessage.attribute, (string)obj[2]);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.SET_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.SET_TOPIC);

                SetTopicMessage setTopicMessage = (SetTopicMessage)msgDes.deserialization(receivedMsg, new SetTopicMessage());
                Debug.Log("-> Target game object name: " + setTopicMessage.objectName);
                Debug.Log("-> Message: " + receivedMsg);
                targetGameObject = getGameObjectByName(setTopicMessage.objectName);

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + setTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                obj = new object[] { setTopicMessage, targetGameObject };

                getGameObjectByName(MqttSetting.SET_TOPIC_MANAGER).GetComponent(MqttSetting.SET_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.PROPERTY_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.PROPERTY_TOPIC);



                PropertyTopicMessage propertyTopicMessage = (PropertyTopicMessage)msgDes.deserialization(receivedMsg, new PropertyTopicMessage());
                Debug.Log("-> Target game object name: " + propertyTopicMessage.objectName);
                targetGameObject = getGameObjectByName(propertyTopicMessage.objectName);

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + propertyTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                obj = new object[] { propertyTopicMessage, targetGameObject };

                getGameObjectByName(MqttSetting.PROPERTY_TOPIC_MANAGER).GetComponent(MqttSetting.PROPERTY_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.CREATE_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.CREATE_TOPIC);
                Debug.Log("-> Message: " + receivedMsg);
                CreateTopicMessage createTopicMessage = (CreateTopicMessage)msgDes.deserialization(receivedMsg, new CreateTopicMessage());
                obj = new object[] { createTopicMessage };

                getGameObjectByName(MqttSetting.CREATE_TOPIC_MANAGER).GetComponent(MqttSetting.CREATE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.DESTROY_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.DESTROY_TOPIC);

                DestroyTopicMessage destroyTopicMessage = (DestroyTopicMessage)msgDes.deserialization(receivedMsg, new DestroyTopicMessage());
                obj = new object[] { destroyTopicMessage };

                if (topicGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + destroyTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                getGameObjectByName(MqttSetting.DESTROY_TOPIC_MANAGER).GetComponent(MqttSetting.DESTROY_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.NOTIFICATION_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.NOTIFICATION_TOPIC);

                NotificationTopicMessage notificationTopicMessage = (NotificationTopicMessage)msgDes.deserialization(receivedMsg, new NotificationTopicMessage());
                obj = new object[] { notificationTopicMessage };


                if (topicGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + notificationTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                getGameObjectByName(MqttSetting.NOTIFICATION_TOPIC_MANAGER).GetComponent(MqttSetting.NOTIFICATION_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);

                //------------------------------------------------------------------------------
                break;

            default:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.DEFAULT_TOPIC);
                //------------------------------------------------------------------------------
                break;
            }

            msgList.Remove(e);
        }

        checkForNotifications();
        Debug.Log("Check if there are objects to create!");
        GameObject builder = getGameObjectByName("MapBuilder");

        if (builder != null)
        {
            builder.GetComponent <RegionMap>().SendMessage("DrawNewAgents");
            Debug.Log("Drawing agent is done! " + (new DateTime()).ToString());
        }
    }
    void FixedUpdate()
    {
        if (msgList.Count > 0)
        {
            MqttMsgPublishEventArgs e = msgList[0];
            if (!MqttSetting.getTopicsInList().Contains(e.Topic))
            {
                Debug.Log("-> The Topic '" + e.Topic + "' doesn't exist in the defined list. Please check! (the message will be deleted!)");
                msgList.Remove(e);
                return;
            }

            receivedMsg = System.Text.Encoding.UTF8.GetString(e.Message);
            //Debug.Log ("-> Received Message is : " + receivedMsg);
            allObjects = UnityEngine.Object.FindObjectsOfType <GameObject>();

            switch (e.Topic)
            {
            case MqttSetting.MAIN_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.MAIN_TOPIC);
                //Debug.Log("-> The message is : " + e.Message);

                topicGameObject = gameObject;
                GamaMessage gamaMessage = (GamaMessage)MsgSerialization.deserialization(receivedMsg, new GamaMessage());
                targetGameObject = GameObject.Find(gamaMessage.receivers);

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + gamaMessage.receivers + "). Please check you code! ");
                    break;
                }

                obj = new object[] { gamaMessage, targetGameObject };
                //GamaManager obje = (GamaManager) FindObjectOfType(typeof(GamaManager));
                GameObject.Find(MqttSetting.MAIN_TOPIC_MANAGER).GetComponent(MqttSetting.MAIN_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);

                //------------------------------------------------------------------------------
                break;

            case MqttSetting.MONO_FREE_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.MONO_FREE_TOPIC);
                MonoFreeTopicMessage monoFreeTopicMessage = (MonoFreeTopicMessage)MsgSerialization.deserialization(receivedMsg, new MonoFreeTopicMessage());
                targetGameObject = GameObject.Find(monoFreeTopicMessage.objectName);
                obj = new object[] { monoFreeTopicMessage, targetGameObject };

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + monoFreeTopicMessage.objectName + "). Please check your code! ");
                    break;
                }
                Debug.Log("The message is to " + monoFreeTopicMessage.objectName + " about the methode " + monoFreeTopicMessage.methodName + " and attribute " + monoFreeTopicMessage.attribute);
                GameObject.Find(MqttSetting.MONO_FREE_TOPIC_MANAGER).GetComponent(MqttSetting.MONO_FREE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.MULTIPLE_FREE_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.MULTIPLE_FREE_TOPIC);

                MultipleFreeTopicMessage multipleFreetopicMessage = (MultipleFreeTopicMessage)MsgSerialization.deserialization(receivedMsg, new MultipleFreeTopicMessage());
                targetGameObject = GameObject.Find(multipleFreetopicMessage.objectName);
                obj = new object[] { multipleFreetopicMessage, targetGameObject };

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + multipleFreetopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                GameObject.Find(MqttSetting.MULTIPLE_FREE_TOPIC_MANAGER).GetComponent(MqttSetting.MULTIPLE_FREE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.POSITION_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.POSITION_TOPIC);



                PositionTopicMessage positionTopicMessage = (PositionTopicMessage)MsgSerialization.deserialization(receivedMsg, new PositionTopicMessage());
                targetGameObject = GameObject.Find(positionTopicMessage.objectName);
                obj = new object[] { positionTopicMessage, targetGameObject };

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + positionTopicMessage.objectName + "). Please check you code! ");
                    break;
                }
                else
                {
                    GameObject.Find(MqttSetting.POSITION_TOPIC_MANAGER).GetComponent(MqttSetting.POSITION_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                }

                //------------------------------------------------------------------------------
                break;

            case MqttSetting.MOVE_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.MOVE_TOPIC);


                MoveTopicMessage moveTopicMessage = (MoveTopicMessage)MsgSerialization.deserialization(receivedMsg, new MoveTopicMessage());

                print("the coordinates are: ");

                print(" x =  " + moveTopicMessage.position.x);
                print(" y = " + moveTopicMessage.position.y);
                print(" z " + moveTopicMessage.position.z);

                targetGameObject = GameObject.Find(moveTopicMessage.objectName);
                obj = new object[] { moveTopicMessage, targetGameObject };

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + moveTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                GameObject.Find(MqttSetting.MOVE_TOPIC_MANAGER).GetComponent(MqttSetting.MOVE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.COLOR_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.COLOR_TOPIC);

                ColorTopicMessage colorTopicMessage = (ColorTopicMessage)MsgSerialization.deserialization(receivedMsg, new ColorTopicMessage());
                targetGameObject = GameObject.Find(colorTopicMessage.objectName);
                obj = new object[] { colorTopicMessage, targetGameObject };

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + colorTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                GameObject.Find(MqttSetting.COLOR_TOPIC_MANAGER).GetComponent(MqttSetting.COLOR_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);

                //------------------------------------------------------------------------------
                break;

            case MqttSetting.GET_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.GET_TOPIC);
                string value = null;

                GetTopicMessage getTopicMessage = (GetTopicMessage)MsgSerialization.deserialization(receivedMsg, new GetTopicMessage());
                targetGameObject = GameObject.Find(getTopicMessage.objectName);


                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + getTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                obj = new object[] { getTopicMessage, targetGameObject, value };

                GameObject.Find(MqttSetting.GET_TOPIC_MANAGER).GetComponent(MqttSetting.GET_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                sendReplay(clientId, "GamaAgent", getTopicMessage.attribute, (string)obj[2]);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.SET_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.SET_TOPIC);

                SetTopicMessage setTopicMessage = (SetTopicMessage)MsgSerialization.deserialization(receivedMsg, new SetTopicMessage());
                // Debug.Log("-> Target game object name: " + setTopicMessage.objectName);
                // Debug.Log("-> Message: " + receivedMsg);
                targetGameObject = GameObject.Find(setTopicMessage.objectName);

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + setTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                obj = new object[] { setTopicMessage, targetGameObject };

                GameObject.Find(MqttSetting.SET_TOPIC_MANAGER).GetComponent(MqttSetting.SET_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.PROPERTY_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.PROPERTY_TOPIC);
                //XStream xstream = new XStream();
                // -------------------------------
                PropertyTopicMessage pm = new PropertyTopicMessage();
                pm.emissionTimeStamp = "8";
                pm.contents          = "Content not set";
                pm.objectName        = "Player";
                pm.receivers         = "Player";
                pm.sender            = "GamaAgent0";
                pm.unread            = "true";
                pm.property          = "localScale";
                pm.valueType         = "GamaPoint";
                pm.value             = new GamaPoint();


                Debug.Log("---- - >  Serialization ");
                string pmMessage = MsgSerialization.serialization(pm);

                Debug.Log("---- - >  pmMessage is \n " + pmMessage);

                PropertyTopicMessage pm2 = (PropertyTopicMessage)MsgSerialization.deserialization(pmMessage, new PropertyTopicMessage());

                Debug.Log("---- - >  Deserialization ");

                print("-- > property: " + pm2.property);
                print("-- > value: " + pm2.value);

                GamaPoint pp = (GamaPoint)pm2.value;

                print("-- > value x: " + pp.x);
                print("-- > value y: " + pp.y);
                print("-- > value z: " + pp.z);
                // ----------------------------

                PropertyTopicMessage propertyTopicMessage;


                Debug.Log("---- - >  Target and message is \n " + receivedMsg);
                // propertyTopicMessage = (PropertyTopicMessage) xstream.FromXml(receivedMsg);
                propertyTopicMessage = (PropertyTopicMessage)MsgSerialization.deserialization(receivedMsg, new PropertyTopicMessage());

                Debug.Log("---77777 - >  Deserealized  \n ");
                // Debug.Log("-> Target game object Value: " + propertyTopicMessage.value);


                GamaPoint gp = (GamaPoint)propertyTopicMessage.value;

                // PropertyTopicMessage propertyTopicMessage = (PropertyTopicMessage)MsgSerialization.deserialization(receivedMsg, new PropertyTopicMessage());
                Debug.Log("-> Target game object name: " + propertyTopicMessage.objectName);
                Debug.Log("-> Target game object Value: " + gp.getVector3());
                targetGameObject = GameObject.Find(propertyTopicMessage.objectName);

                if (targetGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + propertyTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                obj = new object[] { propertyTopicMessage, targetGameObject };

                GameObject.Find(MqttSetting.PROPERTY_TOPIC_MANAGER).GetComponent(MqttSetting.PROPERTY_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.CREATE_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.CREATE_TOPIC);
                // Debug.Log("-> Message: " + receivedMsg);
                CreateTopicMessage createTopicMessage = (CreateTopicMessage)MsgSerialization.deserialization(receivedMsg, new CreateTopicMessage());
                obj = new object[] { createTopicMessage };

                GameObject.Find(MqttSetting.CREATE_TOPIC_MANAGER).GetComponent(MqttSetting.CREATE_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.DESTROY_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.DESTROY_TOPIC);

                DestroyTopicMessage destroyTopicMessage = (DestroyTopicMessage)MsgSerialization.deserialization(receivedMsg, new DestroyTopicMessage());
                obj = new object[] { destroyTopicMessage };

                if (topicGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + destroyTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                GameObject.Find(MqttSetting.DESTROY_TOPIC_MANAGER).GetComponent(MqttSetting.DESTROY_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);
                //------------------------------------------------------------------------------
                break;

            case MqttSetting.NOTIFICATION_TOPIC:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.NOTIFICATION_TOPIC);

                NotificationTopicMessage notificationTopicMessage = (NotificationTopicMessage)MsgSerialization.deserialization(receivedMsg, new NotificationTopicMessage());
                obj = new object[] { notificationTopicMessage };


                if (topicGameObject == null)
                {
                    Debug.LogError(" Sorry, requested gameObject is null (" + notificationTopicMessage.objectName + "). Please check you code! ");
                    break;
                }

                GameObject.Find(MqttSetting.NOTIFICATION_TOPIC_MANAGER).GetComponent(MqttSetting.NOTIFICATION_TOPIC_SCRIPT).SendMessage("ProcessTopic", obj);

                //------------------------------------------------------------------------------
                break;

            default:
                //------------------------------------------------------------------------------
                Debug.Log("-> Topic to deal with is : " + MqttSetting.DEFAULT_TOPIC);
                //------------------------------------------------------------------------------
                break;
            }

            msgList.Remove(e);
        }

        checkForNotifications();
        GameObject mapBuilder = GameObject.Find("MapBuilder");

        //GameObject mapBuilder = GameObject.Find("MapBuilder");
        //regionMap = (RegionMap) FindObjectOfType(typeof(RegionMap));
        //GameObject mapBuilder  = (GameObject) FindObjectOfType(typeof(MapBuilder));

        if (mapBuilder != null)
        {
            mapBuilder.GetComponent <RegionMap>().SendMessage("DrawNewAgents");
        }
        else
        {
            //       Debug.Log("No such Object. Sorry");
        }
    }