void CreateCell(int x, int z, int i) { Vector3 position; position.x = x; position.y = 0f; position.z = z; SquareCellScript cell = cells[i] = Instantiate <SquareCellScript>(cellPrefab); cell.transform.SetParent(transform, false); cell.transform.localPosition = position; cell.coordinates = CellCoords.FromCoordinates(x, z); if (x > 0) { cell.SetNeighbor(CellDirection.W, cells[i - 1]); } if (z > 0) { //if ((z & 1) == 0) cell.SetNeighbor(CellDirection.S, cells[i - width]); } Text label = Instantiate <Text>(cellLabelPrefab); label.rectTransform.SetParent(gridCanvas.transform, false); label.rectTransform.anchoredPosition = new Vector2(position.x, position.z); label.text = x.ToString() + "\n" + z.ToString(); }
public void Neighbors(SquareCellScript cell) { Debug.Log("Hit by ray"); SquareCellScript neighborN = cell.GetNeighbor(CellDirection.N); SquareCellScript neighborE = cell.GetNeighbor(CellDirection.E); SquareCellScript neighborS = cell.GetNeighbor(CellDirection.S); SquareCellScript neighborW = cell.GetNeighbor(CellDirection.W); }
//Converts touch position to cell coordinates via the CellCoords script void TouchCell(Vector3 position) { position = transform.InverseTransformPoint(position); CellCoords coordinates = CellCoords.FromPosition(position); Debug.Log("contact at " + coordinates.ToString()); int index = coordinates.X + coordinates.Y * width; SquareCellScript cell = cells[index]; cell.color = touchedColor; }
void Triangulate(SquareCellScript cell) { Vector3 center = cell.transform.localPosition; for (int i = 0; i < 4; i++) { AddTriangle( center, center + SquareMetrics.corners[0], center + SquareMetrics.corners[1] ); } }
public void SetNeighbor(CellDirection direction, SquareCellScript cell) { neighbors[(int)direction] = cell; cell.neighbors[(int)direction.Opposite()] = this; }