void CreateGrid() { Cells = new Cell[Width, Height]; Vector2 offset = this.transform.position; // Organize the grid objects GameObject gridLineContainer = new GameObject("GridLines"); GameObject cellContainer = new GameObject("Cells"); gridLineContainer.transform.parent = this.transform; cellContainer.transform.parent = this.transform; // vertical grid lines VerticalLines = new GridLine[Width + 1]; for (int x = 0; x < Width + 1; x++) { GridLine line = (GameObject.Instantiate(Resources.Load("GridLine") as GameObject)).GetComponent <GridLine> (); float xpos = offset.x + (CellSize * x) + (LineWidth * x); line.Set(LineColor, new Vector2(xpos, offset.y), new Vector2(LineWidth, (Height * CellSize) + LineWidth * Height + LineWidth)); line.transform.parent = gridLineContainer.transform; VerticalLines [x] = line; } // horizontal grid lines HorizontalLines = new GridLine[Height + 1]; for (int y = 0; y < Height + 1; y++) { GridLine line = (GameObject.Instantiate(Resources.Load("GridLine") as GameObject)).GetComponent <GridLine> (); float ypos = offset.y - (CellSize * y) - (LineWidth * y); line.Set(LineColor, new Vector2(offset.x, ypos), new Vector2((Width * CellSize) + LineWidth * Width + LineWidth, LineWidth)); line.transform.parent = gridLineContainer.transform; HorizontalLines [y] = line; } // Cells for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { Cell cell = (GameObject.Instantiate(Resources.Load("Cell") as GameObject)).GetComponent <Cell>(); float xpos = offset.x + (x * CellSize) + (LineWidth * x) + LineWidth; float ypos = offset.y - (y * CellSize) - (LineWidth * y) - LineWidth; cell.Set(x, y, new Vector2(xpos, ypos), CellSize, LiquidFlowSprites, ShowFlow, RenderDownFlowingLiquid, RenderFloatingLiquid); // add a border if (x == 0 || y == 0 || x == Width - 1 || y == Height - 1) { cell.SetType(CellType.Solid); } cell.transform.parent = cellContainer.transform; Cells [x, y] = cell; } } UpdateNeighbors(); }