Ejemplo n.º 1
0
    void Update()
    {
        if (PersonList.Count < LastPersonCount)
        {
            SpawnPerson();
        }
        GetSelection();

        if (SelectedVertice1 && SelectedVertice2)
        {
            if (SelectedVertice1 == SelectedVertice2)
            {
                print("No Loops Please");
            }
            else
            {
                MakeEdge(SelectedVertice1, SelectedVertice2);
            }
            SelectedVertice1.GetComponent <MeshRenderer>().material = PreviousVertexMat;
            SelectedVertice2.GetComponent <MeshRenderer>().material = PreviousVertexMat;
            SelectedVertice1 = null;
            SelectedVertice2 = null;
        }
        framecount = Time.frameCount;
        if (framecount % SpawnTimer == 0 && LastPersonCount < MaxPeople)
        {
            SpawnPerson();
            LastPersonCount += 1;
        }

        // update times based on currentUsages;
        if (framecount % 10 == 0)
        {
            Dictionary <string, int> currentUsages = getCurrentUsages();
            foreach (GameObject edge in EdgeList)
            {
                Edge   e        = edge.GetComponent <Edge>();
                string EdgeName = e.EdgeName;
                int    usage    = currentUsages[EdgeName];
                if (usage > 0)
                {
                    float length = edge.transform.localScale.x;

                    float newSpeed = e.Speed / usage;

                    Speeds[EdgeName] = newSpeed;
                    Speeds[new string(EdgeName.ToCharArray().Reverse().ToArray())] = newSpeed;
                    float val = length / newSpeed;

                    Times[EdgeName] = val;
                    Times[new string(EdgeName.ToCharArray().Reverse().ToArray())] = val;
                }
            }
        }
    }
Ejemplo n.º 2
0
    void GetSelection()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;

            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 25.0f, LayerMask.GetMask("UI"), QueryTriggerInteraction.Collide))
            {
            }
            else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 25.0f, LayerMask.GetMask("Vertices"), QueryTriggerInteraction.Collide))
            {
                //if (SelectedEdgeMesh)
                //{
                //    SelectedEdgeMesh.GetComponent<MeshRenderer>().material = PreviousEdgeMat;
                //    SelectedEdgeMesh = null;
                //    SelectedEdge = null;
                //}
                Vertice Temp = hit.collider.gameObject.GetComponent <Vertice>();
                SelectionX = Temp.LocX;
                SelectionY = Temp.LocY;

                // SelectionX and Selection Y were initially -1, so checking if I didn't click on anything
                if (SelectionX == -1 || SelectionY == -1)
                {
                    print("invalid");
                    return;
                }
                if (!SelectedVertice1)
                {
                    SelectedVertice1 = Temp;
                    if (SelectedVertice1)
                    {
                        PreviousVertexMat             = SelectedVertice1.GetComponent <MeshRenderer>().material;
                        SelectedVertexMat.mainTexture = PreviousVertexMat.mainTexture;
                        SelectedVertice1.GetComponent <MeshRenderer>().material = SelectedVertexMat;
                    }
                }
                else if (!SelectedVertice2)
                {
                    SelectedVertice2 = Temp;
                    if (SelectedVertice2)
                    {
                        SelectedVertexMat.mainTexture = PreviousVertexMat.mainTexture;
                        SelectedVertice2.GetComponent <MeshRenderer>().material = SelectedVertexMat;
                    }
                }
            }
            else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 25.0f, LayerMask.GetMask("Edges"), QueryTriggerInteraction.Collide))
            {
                if (SelectedEdgeMesh)
                {
                    SelectedEdgeMesh.GetComponent <MeshRenderer>().material = PreviousEdgeMat;
                    SelectedEdgeMesh = null;
                    SelectedEdge     = null;
                }
                SelectedEdgeMesh = hit.collider.gameObject;
                SelectedEdge     = SelectedEdgeMesh.GetComponent <Edge>();
                PreviousEdgeMat  = SelectedEdgeMesh.GetComponent <MeshRenderer>().material;
                SelectedEdgeMesh.GetComponent <MeshRenderer>().material = SelectedEdgeMat;
            }
            else if (SelectedEdgeMesh)
            {
                SelectedEdgeMesh.GetComponent <MeshRenderer>().material = PreviousEdgeMat;
                SelectedEdgeMesh = null;
                SelectedEdge     = null;
            }

            SelectionX = -1;
            SelectionY = -1;
        }
    }