private void Start()
    {
        MainCamera = Camera.main;

        m_Field.Init();

        var firstCell = MatchThreeField.GetCell(0, 0);

        MatchThreeCell cell = firstCell;

        while (cell)
        {
            SetupCandiesLine(cell, Direction.Right);
            cell = cell.GetNeighbour(Direction.Up);
        }
    }
示例#2
0
    private void OnMouseUp()
    {
        inDrag = false;
        if (currentCollider)
        {
            MatchThreeCandy targetCandy = currentCollider.GetComponent <MatchThreeCandy>();
            var             targetCell  = MatchThreeField.GetCell(targetCandy);
            var             currentCell = MatchThreeField.GetCell(this);
            //пытаемся поменять ячейки
            currentCell.Candy = targetCandy;
            targetCell.Candy  = this;

            //проверить валидность
            bool isFreePlacement = MatchThreeController.IsFreeCandyPlacement(targetCell, CandyData.Id);
            if (isFreePlacement)
            {
                isFreePlacement = MatchThreeController.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;
            return;
        }

        transform.position = baseCandyPosition;
    }