private void positionToEditor() { for (int i = 0; i < hexagonals.Count; i++) { List <Hexanonal> row = hexagonals[i]; for (int j = 0; j < row.Count; j++) { Vector2 p = row[j].getPosition(); row[j].setPosition(HexagonalAlgorithm.positionToEditor(p)); } } }
List <Vector2> _lineData = new List <Vector2>(); //划线时用到的数据 public void onHexagonalClick(Vector2 position) { switch (_testOptionValue) { case (int)TEST_TYPE.EDGE_TEST: //求相邻点 { //范围 if (string.IsNullOrEmpty(param1Input.text)) { showNeighbours(position, 1); } else { showNeighbours(position, int.Parse(param1Input.text)); } } break; case (int)TEST_TYPE.DRAW_LINE_TEST: { if (_lineData.Count == 0) //第一个点 { hexagonals[(int)position.y][(int)position.x].setSelected(true); _lineData.Add(HexagonalAlgorithm.positionToAlgorithm(position)); } else if (_lineData.Count == 1) //第二个点 { _lineData.Add(HexagonalAlgorithm.positionToAlgorithm(position)); List <Vector2> line = HexagonalAlgorithm.drawLine(_lineData[0], _lineData[1]); for (int i = 0; i < line.Count; i++) { line[i] = HexagonalAlgorithm.positionToEditor(line[i]); } setSelected(line, true); outPut.text = "距离:" + HexagonalAlgorithm.distance(_lineData[0], _lineData[1]); } else { clearSelected(); _lineData.Clear(); hexagonals[(int)position.y][(int)position.x].setSelected(true); _lineData.Add(HexagonalAlgorithm.positionToAlgorithm(position)); } } break; } }
// public void showNeighbours(Vector2 position, int Area) { clearSelected(); Vector2 algorithmPosition = HexagonalAlgorithm.positionToAlgorithm(position); List <Vector2> neigbours = HexagonalAlgorithm.edge(algorithmPosition, Area); List <Vector2> editorPositions = new List <Vector2>(); for (int i = 0; i < neigbours.Count; i++) { Vector2 editorPosition = HexagonalAlgorithm.positionToEditor(neigbours[i]); Debug.Log("x:" + neigbours[i].x + ", y:" + neigbours[i].y + " to editor: x:" + editorPosition.x + ", y:" + editorPosition.y); editorPositions.Add(editorPosition); } setSelected(editorPositions, true); }