void GetGraphInfo(Graph grph) { if (grph.coords [0] < minCoord [0]) { minCoord [0] = grph.coords [0]; } if (grph.coords [1] < minCoord [1]) { minCoord [1] = grph.coords [1]; } if (grph.coords [0] > maxCoord [0]) { maxCoord [0] = grph.coords [0]; } if (grph.coords [1] > maxCoord [1]) { maxCoord [1] = grph.coords [1]; } foreach (Graph child in grph.ReturnChildren()) { GetGraphInfo(child); } }
void DisplayGraph(Graph grph, bool notConnection=true) { if(notConnection){ GameObject node = (GameObject)Instantiate (prefabNode, new Vector3((float)grph.coords[0], (float)grph.coords[1], 0), Quaternion.identity); node.transform.localScale = new Vector3 (1,1,1); parts.Add (node); } if (grph.parent != null) { float xDiff = ((float)(grph.parent.coords [0] - grph.coords [0])) /2; float yDiff = ((float)(grph.parent.coords [1] - grph.coords [1]))/2; GameObject obj = (GameObject) Instantiate (prefabConnection, new Vector3((float)grph.coords[0]+xDiff, (float)grph.coords[1]+yDiff, 0), Quaternion.identity); obj.transform.localScale = new Vector3 (0.1f,1,1); parts.Add (obj); if(xDiff != 0) obj.transform.eulerAngles = new Vector3(0,0,90); } foreach (Graph connection in grph.ReturnConnections()) { if(connection.parent != null) { float xDiff = ((float)(connection.parent.coords [0] - connection.coords [0])) /2; float yDiff = ((float)(connection.parent.coords [1] - connection.coords [1]))/2; GameObject obj = (GameObject) Instantiate (prefabConnection, new Vector3((float)connection.coords[0]+xDiff, (float)connection.coords[1]+yDiff, 0), Quaternion.identity); obj.transform.localScale = new Vector3 (0.1f,1,1); parts.Add (obj); if(xDiff != 0) obj.transform.eulerAngles = new Vector3(0,0,90); } } foreach (Graph child in grph.ReturnChildren()) { DisplayGraph (child); } }
int[,] UpdateMapFromNode(Graph grph, int[,] map, int nodeSize, int seperationWidth) { int[] transPoint = TranslateGraphCoord (grph.coords, nodeSize, seperationWidth); Debug.Log (grph.coords[0] + "," + grph.coords[1] + " To " + transPoint[0] + "," + transPoint[1]); map = InitialiseAreaOfMap (map, transPoint, nodeSize, nodeSize); foreach (Graph connection in grph.ReturnConnections()) { int xDiff = ((connection.coords [0]-grph.coords [0])); int yDiff = ((connection.coords [1]-grph.coords [1])); map = InitaliseConnection (map, transPoint, xDiff, yDiff, nodeSize, seperationWidth); } foreach (Graph child in grph.ReturnChildren()) { int xDiff = ((child.coords [0]-grph.coords [0])); int yDiff = ((child.coords [1]-grph.coords [1])); map = InitaliseConnection (map, transPoint, xDiff, yDiff, nodeSize, seperationWidth); map = UpdateMapFromNode (child, map, nodeSize, seperationWidth); } return map; }