public void DrawMap(Map map) { TearDownOldMap(); int numberOfLayers = map.nodeLayers.Count; MapNode entrance = map.nodeLayers[0][0]; entrance.AssociateNodeWithController(entranceNodeController); RectTransform entranceRect = entranceNodeController.GetComponent <RectTransform>(); entranceNodeController.GetComponent <Button>().onClick.AddListener(GenerateMapNodeClickListener(entrance)); mapNodeXVariance = (width - (entranceRect.rect.width * 1.5f)) / 2f; MapNode exit = map.nodeLayers[numberOfLayers - 1][0]; exit.AssociateNodeWithController(exitNodeController); RectTransform exitRect = exitNodeController.GetComponent <RectTransform>(); exitNodeController.GetComponent <Button>().onClick.AddListener(GenerateMapNodeClickListener(exit)); float baseLayerYCoord = entranceRect.localPosition.y; float topLayerYCoord = exitRect.localPosition.y; float totalYHeightOfNodes = Mathf.Abs(topLayerYCoord - baseLayerYCoord); float yGapBetweenLayers = Mathf.Abs(totalYHeightOfNodes / (numberOfLayers - 1)); // For the time being, just going to stack nodes in layer rightward from leftmost valid point. // TODO: Prettify for (int i = 1; i < numberOfLayers - 1; i++) { List <MapNode> layer = map.nodeLayers[i]; int nodesInLayer = layer.Count; for (int j = 0; j < nodesInLayer; j++) { MapNode node = layer[j]; GameObject drawnNode = Instantiate(mapNodePrefab, intermediaryNodeParent); node.AssociateNodeWithController(drawnNode.GetComponent <MapNodeController>()); RectTransform newNodeRect = drawnNode.GetComponent <RectTransform>(); newNodeRect.localPosition = new Vector2(mapNodeXVariance * (j - 1), yGapBetweenLayers * i + baseLayerYCoord); drawnNode.GetComponent <Button>().onClick.AddListener(GenerateMapNodeClickListener(node)); foreach (MapNode parent in node.parents) { DrawPath(node.NodeController, parent.NodeController); } } } foreach (MapNode parent in exit.parents) { DrawPath(exit.NodeController, parent.NodeController); } }