private void Awake() { instance = this; levelText.text = string.Format(levelText.text, "Puzzle"); cellOri = wordCell.GetComponent <RectTransform> ().anchoredPosition; min = wordCell.GetComponent <RectTransform> ().sizeDelta.x; blockOri = block.GetComponent <RectTransform> ().anchoredPosition; InitColor(); SetColor(); saveBtn.onClick.AddListener(() => { Save(); modifierWord.gameObject.SetActive(false); startSetBlock.gameObject.SetActive(false); }); modifierWord.onClick.AddListener(() => { currentBlock = null; currentItem = null; downItem = null; //blockText = ""; blockGroup.gameObject.SetActive(false); wordGroup.gameObject.SetActive(true); opGroup.SetActive(true); letterGroup.SetActive(true); colorGroup.SetActive(false); modifierWord.gameObject.SetActive(false); startSetBlock.gameObject.SetActive(true); saveBtn.gameObject.SetActive(false); setColor = false; }); startSetBlock.onClick.AddListener(() => { modifierWord.gameObject.SetActive(true); blockGroup.gameObject.SetActive(true); SetHintCell(); SetBlockGrid(); setColor = true; opGroup.SetActive(false); letterGroup.SetActive(false); colorGroup.SetActive(true); currentItem = null; letter = ""; startSetBlock.gameObject.SetActive(false); saveBtn.gameObject.SetActive(true); }); }
private BlockLetter CloneBlock(int i, int j, float offset) { BlockLetter cell = Instantiate(block, blockGroup); cell.name = "block" + i.ToString() + j.ToString(); cell.GetComponent <RectTransform> ().anchoredPosition = new Vector2(blockOri.x + (min + offset) * j, blockOri.y - (min + offset) * i); cell.pos.x = i; cell.pos.y = j; cell.ClearColor(); cell.SetSize(min); if ((i < row && j >= col) || i >= row) { Vector2 pos = cell.GetComponent <RectTransform> ().anchoredPosition; if (pos.x + min < 720 && pos.y - min > -720) { cell.gameObject.SetActive(true); } } return(cell); }
private void CalculateCenter() { //两个字典的数量一定是相等的 List <BlockInfo> blockInfos = new List <BlockInfo> (); foreach (int key in wordPosDic.Keys) { BlockInfo info = new BlockInfo(); info.blockNum = key; List <CellInfo> word = new List <CellInfo> (); List <CellInfo> block = new List <CellInfo> (); word = wordPosDic[key]; block = blockPosDic[key]; info.wordPos = word; info.blockPos = block; info.wordRect = CalculateRectangle(word, wordGroup); info.blockRect = CalculateRectangle(block, blockGroup); blockInfos.Add(info); } data.puzzleInfo = blockInfos; }
//设置方块的放置格子 private void SetBlockGrid() { if (blockGroup.childCount > 1) { // SetBlockSizeAndPos (); blockGroup.gameObject.SetActive(true); } else { float offset = 2; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (j >= col || i >= row) { offset = 3; } if (i == 0 && j == 0) { } else { BlockLetter cell = CloneBlock(i, j, offset); if (loadData.blockInfo.Count != 0) { if (loadData.blockColorIndex[i][j] != -1) { int colorIndex = loadData.blockColorIndex[i][j]; cell.SetColor(colorIndex, colors[colorIndex]); cell.letter.text = loadData.blockInfo[i][j]; } } } } } } }
private void CalculateBlock() { int index = 0; for (int i = 0; i < 10; i++) { List <string> block_word = new List <string> (); List <int> block_color = new List <int> (); for (int j = 0; j < 10; j++) { List <CellInfo> list = new List <CellInfo> (); CellInfo info = new CellInfo(); BlockLetter cell = blockGroup.GetChild(index).GetComponent <BlockLetter> (); block_word.Add(cell.letter.text); block_color.Add(cell.blockIndex); if (cell.blockIndex != -1 && !string.IsNullOrEmpty(cell.letter.text)) { info.pos = cell.pos; info.letter = cell.letter.text; if (blockPosDic.ContainsKey(cell.blockIndex)) { list = blockPosDic[cell.blockIndex]; list.Add(info); blockPosDic[cell.blockIndex] = list; } else { list.Add(info); blockPosDic.Add(cell.blockIndex, list); } } index++; } loadData.blockInfo.Add(block_word); loadData.blockColorIndex.Add(block_color); } }