예제 #1
0
 //checks road already exists
 bool roadCheck(List <nodeConnection> createdRoads, nodeConnection checkingNode)
 {
     for (int i1 = 0; i1 < createdRoads.Count; i1++)
     {
         if ((createdRoads[i1].nodes[0] == checkingNode.nodes[0] && createdRoads[i1].nodes[1] == checkingNode.nodes[1]) || (createdRoads[i1].nodes[0] == checkingNode.nodes[1] && createdRoads[i1].nodes[1] == checkingNode.nodes[0]))
         {
             return(false);
         }
     }
     return(true);
 }
예제 #2
0
    //finds all common nodes
    public void commonNode()
    {
        List <GameObject> uncommonNode = new List <GameObject> {
        };

        // for loop checks if a both nodes can connect
        for (int i1 = 0; i1 < possibleConnections.Count; i1++)
        {
            for (int i2 = 0; i2 < possibleConnections[i1].Count; i2++)
            {
                int temp = commonNodeChecker(possibleConnections[i1][i2], i1);
                //checks if a node is a common node or an uncommon node
                if (temp != -1)
                {
                    nodeConnection connection = new nodeConnection();
                    connection.connectionQuality = temp;
                    connection.nodes[0]          = this.gameObject;
                    connection.nodes[1]          = possibleConnections[i1][i2];

                    possibleConnections[i1][i2].GetComponent <nodeScript>().finalistNode.Add(connection);
                }
                else
                {
                    uncommonNode.Add(possibleConnections[i1][i2]);
                }
            }
        }
        //removes all uncommon node
        for (int i1 = 0; i1 < uncommonNode.Count; i1++)
        {
            for (int i2 = 0; i2 < possibleConnections.Count; i2++)
            {
                if (possibleConnections[i2].Any(node => node == uncommonNode[i1]))
                {
                    possibleConnections[i2].Remove(uncommonNode[i1]);
                }
            }
        }
    }
예제 #3
0
    //creates a node at where two nodes collide
    private void intersectionNodeCreator(Vector3 point, List <GameObject> nodes)
    {
        GameObject temp = Instantiate(Resources.Load("streetNode"), point, Quaternion.identity) as GameObject;

        //assings variables
        temp.GetComponent <nodeScript>().gridProximityStrength = 0;
        temp.GetComponent <nodeScript>().gridID              = -1;
        temp.GetComponent <nodeScript>().nodeID              = 0;
        temp.GetComponent <nodeScript>().XLocation           = 0;
        temp.GetComponent <nodeScript>().YLocation           = 0;
        temp.GetComponent <nodeScript>().minNodeDistance     = 0;
        temp.GetComponent <nodeScript>().avaliableConnection = 0;

        for (int i1 = 0; i1 < nodes.Count; i1++)
        {
            nodeConnection connection = new nodeConnection();

            connection.nodes[0] = this.gameObject;
            connection.nodes[1] = nodes[i1].gameObject;

            temp.GetComponent <nodeScript>().finalistNode.Add(connection);
            nodes[i1].GetComponent <nodeScript>().finalistNode.Add(connection);
        }
    }