/// <summary> /// If a coll generator exists in the scene, it generates it's grid, and returns it /// Else it returns null /// </summary> /// <returns></returns> public static GridNode[,] GetGrid(out int xOffset, out int yOffset) { CollGenerator generator = FindObjectOfType <CollGenerator>(); if (generator == null) { xOffset = 0; yOffset = 0; return(null); } else { var output = generator.PrivateInit(); xOffset = generator.xOffset; yOffset = generator.yOffset; return(output); } }
private void Init() { parent = new GameObject("Grid"); gridNodes = CollGenerator.GetGrid(out xOffset, out yOffset); if (gridNodes != null) { int width = gridNodes.GetLength(0); int height = gridNodes.GetLength(1); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (gridNodes[x, y] != null) { gridNodes[x, y].transform.parent = parent.transform; } } } } else { gridNodes = new GridNode[width, width]; for (int x = 0; x < width; x++) { for (int y = 0; y < width; y++) { GridNode node = new GameObject("GridNode(" + x + "," + y + ")").AddComponent <GridNode>(); node.transform.parent = parent.transform; node.transform.position = new Vector3(x, y); gridNodes[x, y] = node; } } GridNode.AutoLink(gridNodes); } }