예제 #1
0
    void CheckAdjacents(PuzzlePiece piece)
    {
        PuzzlePiece tempPiece;

        GameObject go;

        tempPiece = GetPuzzlePiece(piece.pos.x + 1, piece.pos.y);
        if (tempPiece != null && tempPiece != freePiece)
        {
            Debug.Log("Piece moved: " + piece + " Piece at Right: " + tempPiece);
            if (piece.id + new Vector2(1, 0) == tempPiece.id)
            {
                Debug.Log("Match at right");
                go                  = GameObject.Instantiate(linePrefab, Vector3.zero, Quaternion.identity) as GameObject;
                go.layer            = Layers.LAYER_2D;
                go.transform.parent = piece.transform;
                piece.rightLine     = go;
                piece.RightAnimation();
            }
        }
        tempPiece = GetPuzzlePiece(piece.pos.x - 1, piece.pos.y);
        if (tempPiece != null && tempPiece != freePiece)
        {
            Debug.Log("Piece moved: " + piece + " Piece at Left: " + tempPiece);
            if (piece.id - new Vector2(1, 0) == tempPiece.id)
            {
                Debug.Log("Match at left");
                go                  = GameObject.Instantiate(linePrefab, Vector3.zero, Quaternion.identity) as GameObject;
                go.layer            = Layers.LAYER_2D;
                go.transform.parent = piece.transform;
                piece.leftLine      = go;
                piece.LeftAnimation();
            }
        }
        tempPiece = GetPuzzlePiece(piece.pos.x, piece.pos.y + 1);
        if (tempPiece != null && tempPiece != freePiece)
        {
            Debug.Log("Piece moved: " + piece + " Piece at Bottom: " + tempPiece);
            if (piece.id + new Vector2(0, 1) == tempPiece.id)
            {
                Debug.Log("Match at Bottom");
                go                  = GameObject.Instantiate(linePrefab, Vector3.zero, Quaternion.identity) as GameObject;
                go.layer            = Layers.LAYER_2D;
                go.transform.parent = piece.transform;
                piece.bottomLine    = go;
                piece.BottomAnimation();
            }
        }
        tempPiece = GetPuzzlePiece(piece.pos.x, piece.pos.y - 1);
        if (tempPiece != null && tempPiece != freePiece)
        {
            Debug.Log("Piece moved: " + piece + " Piece at Top: " + tempPiece);
            if (piece.id - new Vector2(0, 1) == tempPiece.id)
            {
                Debug.Log("Match at top");
                go                  = GameObject.Instantiate(linePrefab, Vector3.zero, Quaternion.identity) as GameObject;
                go.layer            = Layers.LAYER_2D;
                go.transform.parent = piece.transform;
                piece.topLine       = go;
                piece.TopAnimation();
            }
        }
    }