예제 #1
0
    public void AgentsGenerator()
    {
        Vector2[] vertices2D = { new Vector2(340.4437f, 739.1506f), new Vector2(350.0437f, 688.6506f), new Vector2(369.9437f, 695.1506f), new Vector2(366.7437f, 712.6506f), new Vector2(374.9437f, 713.9506f), new Vector2(383.5437f, 714.5506f), new Vector2(387.2437f, 714.7506f), new Vector2(387.7437f, 712.6506f), new Vector2(383.7437f, 712.3506f), new Vector2(371.8438f, 708.3506f), new Vector2(373.8438f, 695.3506f), new Vector2(398.5437f, 702.7506f), new Vector2(398.4437f, 705.2506f), new Vector2(406.8438f, 707.4506f), new Vector2(407.3438f, 715.0506f), new Vector2(403.0437f, 754.9506f), new Vector2(390.0437f, 754.8506f), new Vector2(389.8438f, 756.5506f), new Vector2(365.3438f, 752.5506f), new Vector2(363.7437f, 743.0506f), new Vector2(361.1437f, 742.7506f), new Vector2(361.8438f, 745.0506f), new Vector2(339.1437f, 747.0506f) };

        List <GamaPoint> list = new List <GamaPoint>();

        foreach (Vector2 v in vertices2D)
        {
            GamaPoint p = new GamaPoint
            {
                x = v.x,
                y = v.y,
                z = 0
            };
            list.Add(p);
        }

        for (int i = 0; i < 3000; i++)
        {
            UnityAgent unityAgent = new UnityAgent
            {
                unread            = "unread",
                sender            = "sender",
                receivers         = "receivers",
                emissionTimeStamp = 12
            };

            Content contents = new Content
            {
                agentName    = "agent_" + i,
                species      = "UA",
                geometryType = "POLYGON",
                vertices     = list,
                color        = new GamaColor(),
                height       = 0,
                location     = new GamaPoint(0, 0, 0)
            };

            unityAgent.contents = contents;

            string message = MsgSerialization.ToXML(unityAgent);

            Debug.Log("Message is " + message);

            UnityAgent newAgent = (UnityAgent)MsgSerialization.FromXML(message, new UnityAgent());

            Agent gamaAgent = newAgent.GetAgent();

            Debug.Log("Agent created : agent_" + gamaAgent.name);
        }



        //
    }
예제 #2
0
        public List <GamaPoint> TransformCoordinates(List <GamaPoint> Points)
        {
            List <GamaPoint> transformedPoints = new List <GamaPoint>();

            foreach (GamaPoint p in Points)
            {
                GamaPoint newP = new GamaPoint(IGamaManager.x_axis_transform * p.x, IGamaManager.y_axis_transform * p.y, IGamaManager.z_axis_transform * p.z);
                transformedPoints.Add(newP);
            }
            return(transformedPoints);
        }
/*
 *      public Vector3 GetValueAsVector3()
 *      {
 *          Vector3 vector = (Vector3) value.getVector3();
 *
 *          return vector;
 *      }
 */
        public GamaPoint GetValueAsGamaPoint()
        {
            GamaPoint vector = (GamaPoint)value;

            return(vector);
        }
 public PropertyTopicMessage(string unread, string sender, string receivers, string contents, string emissionTimeStamp, string objectName, string property, string valueType, GamaPoint value) : base(unread, sender, receivers, contents, objectName, emissionTimeStamp)
 {
     this.property  = property;
     this.valueType = valueType;
     this.value     = value;
 }
예제 #5
0
 public PositionTopicMessage(string unread, string sender, string receivers, string contents, string emissionTimeStamp, string objectName, GamaPoint position) : base(unread, sender, receivers, contents, objectName, emissionTimeStamp)
 {
     this.position = position;
 }
예제 #6
0
 public MoveTopicMessage(string unread, string sender, string receivers, string contents, string emissionTimeStamp, string objectName, GamaPoint position, float speed, bool smoothMove) : base(unread, sender, receivers, contents, objectName, emissionTimeStamp)
 {
     this.position   = position;
     this.speed      = speed;
     this.smoothMove = smoothMove;
 }
예제 #7
0
    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");
        }
    }
 public CreateTopicMessage(string unread, string sender, string receivers, string contents, string emissionTimeStamp, string objectName, string type, GamaRGBColor color, GamaPoint position) : base(unread, sender, receivers, contents, objectName, emissionTimeStamp)
 {
     this.type     = type;
     this.color    = color;
     this.position = position;
 }