Exemplo n.º 1
0
 // Instancie tous les éléments de l'environnement
 public void AddElement(string typeElement, string nom, Vector3 pos)
 {
     // Chargement des agents
     if (typeElement == "AgentReactif")
     {
         GameObject agentModel = Instantiate(Resources.Load("AgentReactif/AgentReactifv2")) as GameObject;
         AgentReactif.CreateComponent(agentModel, nom, pos);
     }
     if (typeElement == "SupplyZone")
     {
         GameObject supplyZone = GameObject.CreatePrimitive(PrimitiveType.Plane);
         SupplyZone.CreateComponent(supplyZone, nom, pos, new Vector3(pos.x + 1.5f, 0.01f, pos.z + 1.5f));
     }
 }
Exemplo n.º 2
0
        // Instancie tous les éléments de l'environnement
        public void AddElement(string typeElement, string nom, Vector3 firstPos, Vector3 secondPos)
        {
            // Creating agents
            if (typeElement == "AgentReactif")
            {
                GameObject agentModel = Instantiate(Resources.Load("AgentReactif/AgentReactifv2")) as GameObject;
                AgentReactif.CreateComponent(agentModel, nom, firstPos);
            }
            // Creating walls
            if (typeElement == "ElementStatique")
            {
                GameObject elementStatique = GameObject.CreatePrimitive(PrimitiveType.Cube);
                ElementStatique.CreateComponent(elementStatique, nom, firstPos, secondPos);
            }

            if (typeElement == "Supply")
            {
                GameObject supply = GameObject.CreatePrimitive(PrimitiveType.Cube);
                Supply.CreateComponent(supply, nom, firstPos);
            }
        }
Exemplo n.º 3
0
        public void Display(GameObject gameObject)
        {
            GameObject infoDisplayPanel = GameObject.FindGameObjectWithTag("InfoDisplayPanel");

            if (gameObject.GetComponentInParent <AgentReactif>() != null)
            {
                AgentReactif agent = gameObject.GetComponentInParent <AgentReactif>();

                GameObject motorTorqueText = new GameObject("motorTorqueText");
                motorTorqueText.transform.parent = infoDisplayPanel.transform;
                motorTorqueText.AddComponent <Slider>();

                motorTorqueText.AddComponent <Text>();
                motorTorqueText.GetComponent <Text>().text = "MotorTorque : " + agent.motorTorque.ToString();
                motorTorqueText.GetComponent <Text>().font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;

                RectTransform motorTorqueTextRect = motorTorqueText.GetComponent <RectTransform>();
                motorTorqueTextRect.anchorMin        = new Vector2(0, 1);
                motorTorqueTextRect.anchorMax        = new Vector2(0, 1);
                motorTorqueTextRect.sizeDelta        = new Vector2(128, 25);
                motorTorqueTextRect.anchoredPosition = new Vector2(80, -25);
            }
        }
Exemplo n.º 4
0
        // This Coroutine waits for a left mouse click to create the selected item
        IEnumerator WaitForMouseDown(string typeObject)
        {
            while (!Input.GetMouseButtonDown(0))
            {
                yield return(null);
            }

            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                if (typeObject == "AgentReactif")
                {
                    AddElement("AgentReactif", "Toto", new Vector3(hit.point.x, 0.5f, hit.point.z), new Vector3());
                }
                if (typeObject == "ElementStatique") // To create a wall, run a new coroutine waiting for a second input
                {
                    StartCoroutine(WaitForSecondMouseDown(new Vector3(hit.point.x, 0.5f, hit.point.z)));
                }
                if (typeObject == "Supply")
                {
                    AddElement("Supply", "Caisse", new Vector3(hit.point.x, 0.5f, hit.point.z), new Vector3());
                }
                if (typeObject == "Lidar")
                {
                    try
                    {
                        AgentReactif agent = hit.rigidbody.GetComponent <AgentReactif>();
                        AddSensorToAgent("Lidar", "Lidar", agent);
                    }
                    catch (NullReferenceException)
                    {
                    }
                }
                if (typeObject == "RFID")
                {
                    try
                    {
                        if (hit.rigidbody.GetComponent <AgentReactif>())
                        {
                            AgentReactif agent = hit.rigidbody.GetComponent <AgentReactif>();
                            AddSensorToAgent("RFID", "RFID", agent);
                        }
                        else if (hit.rigidbody.GetComponent <Supply>())
                        {
                            Supply supply = hit.rigidbody.GetComponent <Supply>();
                            AddSensorToItem("RFID", "RFID", supply);
                        }
                        else if (hit.rigidbody.GetComponent <ElementStatique>())
                        {
                            ElementStatique staticElement = hit.rigidbody.GetComponent <ElementStatique>();
                            AddSensorToItem("RFID", "RFID", staticElement);
                        }
                    }
                    catch (NullReferenceException)
                    {
                    }
                }
            }
        }