void Update() { if (Input.GetMouseButtonDown(0) && isStart) { if (setColor) { if (currentItem != null) { // blockText = currentItem.letter.text; currentItem.SetColor(currentColor, colors[currentColor]); } if (currentBlock != null && downItem != null) { if (downItem.blockIndex != -1) { currentBlock.SetText(downItem.letter.text); currentBlock.SetColor(downItem.blockIndex, colors[downItem.blockIndex]); downItem = null; } } } else { if (currentItem != null) { currentItem.SetText(letter); } } } if (Input.GetMouseButtonDown(1)) { if (setColor) { if (currentBlock != null) { currentBlock.ClearColor(); } if (currentItem != null) { currentItem.ClearColor(); } } else { if (currentItem != null) { currentItem.SetText(""); } } } }
//克隆方格 private PuzzleCell CloneCell(int i, int j, int index) { PuzzleCell cell = Instantiate(wordCell, wordGroup); cell.name = "word" + i.ToString() + j.ToString(); cell.GetComponent <RectTransform> ().anchoredPosition = new Vector2(cellOri.x + (min + 2) * j, cellOri.y - (min + 2) * i); cell.pos.x = i; cell.pos.y = j; cell.SetText(""); cell.ClearColor(); cell.SetSize(min); cell.transform.SetSiblingIndex(index); cell.gameObject.SetActive(true); return(cell); }
//设置单词格子 private void SetWordGrid() { Calculate(); int index = 0; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { if (i == 0 && j == 0) { wordCell.ClearColor(); wordCell.pos.x = i; wordCell.pos.y = j; wordCell.gameObject.SetActive(true); wordCell.SetSize(min); if (loadData.wordInfo.Count != 0 && loadData.wordColorIndex[i][j] != -1) { wordCell.SetText(loadData.wordInfo[i][j]); wordCell.SetColor(loadData.wordColorIndex[i][j], colors[loadData.wordColorIndex[i][j]]); } } else { PuzzleCell cell = CloneCell(i, j, index); if (loadData.wordInfo.Count != 0 && loadData.wordColorIndex[i][j] != -1) { cell.SetText(loadData.wordInfo[i][j]); cell.SetColor(loadData.wordColorIndex[i][j], colors[loadData.wordColorIndex[i][j]]); } } index++; } } isStart = true; }