Пример #1
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);
            }
        }
Пример #2
0
    public void AddWall(Vector3 firstPos, Vector3 secondPos)
    {
        GameObject elementStatique = GameObject.CreatePrimitive(PrimitiveType.Cube);

        ElementStatique.CreateComponent(elementStatique, "Wall", firstPos, secondPos);
    }
Пример #3
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)
                    {
                    }
                }
            }
        }