private void Start() { MainCamera = Camera.main; m_Field.Init(); var firstCell = MatchThree_Field.GetCell(0, 0); MatchThree_Cell cell = firstCell; while (cell) { SetupCandiesLine(cell, Direction.Right); cell = cell.GetNeighbour(Direction.Up); } }
private void OnMouseUp() { inDrag = false; if (currentCollider) { MatchThree_Candy targetCandy = currentCollider.GetComponent <MatchThree_Candy>(); var targetCell = MatchThree_Field.GetCell(targetCandy); var currentCell = MatchThree_Field.GetCell(this); //пытаемся поменять ячейки currentCell.Candy = targetCandy; targetCell.Candy = this; //проверить валидность bool isFreePlacement = MatchThree_Controller.IsFreeCandyPlacement(targetCell, CandyData.Id); if (isFreePlacement) { isFreePlacement = MatchThree_Controller.IsFreeCandyPlacement(currentCell, targetCandy.CandyData.Id); } //если смена НЕ приведет к совпадению 3-х if (isFreePlacement) { targetCell.Candy = targetCandy; currentCell.Candy = this; transform.position = baseCandyPosition; return; } //Если приведет к совпадению 3-х transform.position = targetCell.transform.position; targetCandy.transform.position = currentCell.transform.position; MatchThree_Controller.DeleteLine(this, targetCell, CandyData.Id); // MatchThree_Controller.DeleteLine(targetCandy, currentCell, CandyData.Id); // как то удалять если совпала переставленная конфетка =/ // MatchThree_Controller.DragCandies("OnMouseUp 1"); return; } transform.position = baseCandyPosition; // MatchThree_Controller.DragCandies("OnMouseUp 2"); }
public static void DragCandies(string from) { Debug.Log(from); for (int x = 0; x < MatchThree_Field.filedWidth; x++) { for (int y = 0; y < MatchThree_Field.filedHeight; y++) { MatchThree_Cell cell = MatchThree_Field.GetCell(x, y); if (!cell.Candy) { Debug.Log(x + ", " + y + ", 0" + " Empty!"); MatchThree_Cell upCell = cell.GetNeighbour(Direction.Up); float emptyCells = MatchThree_Field.filedCellSize; while (upCell) { Debug.Log("emptyCells " + emptyCells); if (upCell.Candy) { Vector3 newPos = new Vector3(upCell.transform.position.x, upCell.transform.position.y - emptyCells, 0f); upCell.Candy.transform.position = newPos; } else { emptyCells += MatchThree_Field.filedCellSize; } upCell = upCell.GetNeighbour(Direction.Up); } } else { Debug.Log(x + ", " + y + ", 0" + " Have! " + cell.Candy.name); } } } }