public void _DEBUG_VISUAL_plotNodeNeighbors() { List <AStarNode> nodes = theAStarGrid.nodes; for (int i = 0; i < nodes.Count; i++) { AStarNode an1 = nodes [i]; float thisY = Random.value + 8f; Color c = new Color(Random.value, Random.value, Random.value); List <AStarNeighbor> theNeibs = theAStarGrid.nodeNeighbors [an1]; for (int k = 0; k < theNeibs.Count; k++) { AStarNeighbor an2 = theNeibs [k]; float xs = an1.x; float ys = an1.y; float xf = an2.theNode.x; float yf = an2.theNode.y; Vector3 start = new Vector3(xs, thisY, ys); Vector3 fin = new Vector3(xf, thisY, yf); Vector3 dir = fin - start; Debug.DrawRay(start, dir, c, 10f); } } }
private void addNodesToNodeNeighbors(AStarNode an1, AStarNode an2) { // here, we need to add the nodes to each other's dictionary entries // first, calculate the cost between the two float cost = Mathf.Sqrt((an1.x - an2.x) * (an1.x - an2.x) + (an1.y - an2.y) * (an1.y - an2.y)); // create a neighbor struct of each one AStarNeighbor an1Neigh = new AStarNeighbor(an1, cost); AStarNeighbor an2Neigh = new AStarNeighbor(an2, cost); List <AStarNeighbor> neighbors = new List <AStarNeighbor> (); // next, see if an1 has a dictionary entry, and if so, copy it if (nodeNeighbors.ContainsKey(an1)) { neighbors = nodeNeighbors [an1]; neighbors.Add(an2Neigh); nodeNeighbors [an1] = neighbors; } else { neighbors.Add(an2Neigh); nodeNeighbors.Add(an1, neighbors); } // do the same for an2 neighbors = new List <AStarNeighbor> (); if (nodeNeighbors.ContainsKey(an2)) { neighbors = nodeNeighbors [an2]; neighbors.Add(an1Neigh); nodeNeighbors [an2] = neighbors; } else { neighbors.Add(an1Neigh); nodeNeighbors.Add(an2, neighbors); } }