コード例 #1
0
    void FireSwipeEvent(GameObject shapeObject, Constants.SwipeDirection swipeDirection)
    {
        Vector2 vec = shapesManager.GetRowColFromGameObject(shapeObject.transform.parent.gameObject);

        if (vec.x == -10f)
        {
            Debug.LogError("Destroy Something is Seriously wrong ");
            //GameObject.Destroy(shapeObject.transform.parent.gameObject);
            return;
        }
        int row = (int)vec.x;
        int col = (int)vec.y;
        // ask shape manager if can attemp to swap
        // this is dependent on if there is an edge or untouchable terrain
        bool validMove = shapesManager.IsValidMove(row, col, swipeDirection);

        if (validMove)
        {
            SoundManager.PlaySound("short_whoosh");
            Shape   shape    = shapesManager.GetShape(row, col);
            Vector3 position = shapesManager.GetPositionOfBackgroundPiece(row, col);

            // get the other shape
            Vector2 nextRowCol   = Constants.GetNextRowCol(swipeDirection, row, col);
            Shape   nextShape    = shapesManager.GetShape((int)nextRowCol.x, (int)nextRowCol.y);
            Vector3 nextPosition = shapesManager.GetPositionOfBackgroundPiece((int)nextRowCol.x, (int)nextRowCol.y);

            StartCoroutine(
                shape.AnimatePosition(nextPosition, Constants.DEFAULT_SWAP_ANIMATION_DURATION, () =>
            {
                //CheckMatch(row, col, (int)nextRowCol.x, (int)nextRowCol.y);
                //CheckWholeBoard();
                int nRow            = (int)nextRowCol.x;
                int nCol            = (int)nextRowCol.y;
                bool successfulSwap = shapesManager.SwapPieces(row, col, nRow, nCol);
                ShapesManager.CheckResult leftResult  = shapesManager.CheckMatch(row, col);
                ShapesManager.CheckResult rightResult = shapesManager.CheckMatch(nRow, nCol);
                bool isMatch = CheckMatch(leftResult, rightResult);
                if (successfulSwap && !isMatch)
                {
                    // also make a function
                    SoundManager.PlaySound("button-29");
                    Constants.SwipeDirection oppositeDirection = Constants.GetOppositeDirection(currentSwipeDirection);
                    Shape currentShape      = shapesManager.GetShape(row, col);
                    Shape nextShape1        = shapesManager.GetShape(nRow, nCol);
                    Vector3 currentPosition = shapesManager.GetPositionOfBackgroundPiece(row, col);
                    Vector3 nextPosition1   = shapesManager.GetPositionOfBackgroundPiece(nRow, nCol);
                    StartCoroutine(
                        currentShape.AnimatePosition(nextPosition, Constants.DEFAULT_SWAP_ANIMATION_DURATION, () => {
                        shapesManager.SwapPieces(row, col, nRow, nCol);
                        blockEvent = false;
                    })
                        );

                    StartCoroutine(
                        nextShape1.AnimatePosition(currentPosition, Constants.DEFAULT_SWAP_ANIMATION_DURATION, () => {
                        Debug.Log("DAH");
                    })
                        );
                }
                else
                {
                    this.currentMoves--;
                    UIManager.UpdateMoveValue(this.currentMoves, this.maxMoves);
                    CheckWholeBoard();
                }
            })
                );
            StartCoroutine(
                nextShape.AnimatePosition(position, Constants.DEFAULT_SWAP_ANIMATION_DURATION, () => {  })
                );
        }
    }