/// <summary>
    /// Raises the board piece button pressed event when pressing a level editor button in the Unity scene view.
    /// </summary>
    /// <param name='refBoardPiece'>
    /// Board piece.
    /// </param>
    /// <param name='rowIdx'>
    /// Row index.
    /// </param>
    /// <param name='colIdx'>
    /// Col index.
    /// </param>
    void OnBoardPieceButtonPressed(ref Match3BoardPiece refBoardPiece, BoardCoord boardPos)
    {
        // Validate the current board tool selection (the currently selected prefab)
//		editor.selectedBoardTool = Selection.activeGameObject;
        object selectedToolObj = null;

        if (editor.selectedBoardTool != null)
        {
            if (editor.selectedBoardTool.GetComponent <Match3BoardPiece>())
            {
                selectedToolObj = editor.selectedBoardTool.GetComponent <Match3BoardPiece>();
            }
            if (editor.selectedBoardTool.GetComponent <Match3Tile>())
            {
                selectedToolObj = editor.selectedBoardTool.GetComponent <Match3Tile>();
            }
        }

        if (selectedToolObj is Match3BoardPiece)
        {
            // Get the currently selected board tool type
            if (!LevelEditorUtils.IsPrefabInArray(editor.boardRenderer.prefabsPieces, editor.selectedBoardTool))
            {
                EditorUtility.DisplayDialog("Level Editor", "The selected board prefab is not added to the Match3BoardRenderer pieces prefab list!", "Ok");
                return;
            }

            // Spawn a new board piece
            editor.SpawnBoardPieceAt(boardPos, editor.selectedBoardTool);
        }
        else if (selectedToolObj is Match3Tile)
        {
            // Get the currently selected board tool type
            if (!LevelEditorUtils.IsPrefabInArray(editor.boardRenderer.tilesPrefabs, editor.selectedBoardTool))
            {
                EditorUtility.DisplayDialog("Level Editor", "The selected board prefab is not added to the Match3BoardRenderer tiles prefab list!", "Ok");
                return;
            }
            else if (refBoardPiece == null)
            {
                // Spawn a default board piece if none found at the current board position.
                editor.SpawnBoardPieceAt(boardPos, editor.defaultBoardPiece.gameObject);
                editor.UpdateBoardPieceGridTransform(refBoardPiece, boardPos);
            }

            // Spawn a new tile on the selected board piece.
            editor.SpawnTileAt(refBoardPiece, boardPos, editor.selectedBoardTool);
        }
        else
        {
            EditorUtility.DisplayDialog("Level Editor", "The selected board prefab type is not supported!", "Ok");
            return;
        }
    }
Exemple #2
0
    public bool Init(bool allocateNewGrid, Match3BoardPiece[,] oldBoardGrid)
    {
        boardRenderer = GameObject.FindObjectOfType(typeof(Match3BoardRenderer)) as Match3BoardRenderer;

        if (boardRenderer != null)
        {
            boardData = boardRenderer.GetComponent <BoardData>();
        }
        else
        {
//			EditorUtility.DisplayDialog("Level Editor", "No Match3BoardRenderer component found in the scene!", "Ok");
            return(false);
        }

        // Init default board piece to use when no board piece is found in a certain grid position
        defaultBoardPiece = LevelEditorUtils.GetPrefabFromArray <Match3BoardPiece>(defaultBoardPieceType, boardRenderer.prefabsPieces);
        if (defaultBoardPiece == null)
        {
            EditorUtility.DisplayDialog("Level Editor", "Default board piece of type: " + defaultBoardPieceType.Name +
                                        " not found in the board pieces prefabs list on the Match3BoardRenderer component!", "Ok");

            return(false);
        }

        if (boardData != null)
        {
            boardNumRows = boardData.NumRows;
            boardNumCols = boardData.NumColumns;

            if (allocateNewGrid)
            {
                boardGrid = new Match3BoardPiece[boardNumRows, boardNumCols];
            }

//			// Copy old grid to new grid (boardGrid)
//			if (oldBoardGrid != null) {
//				int oldBoardNumRows = oldBoardGrid.GetLength(0);
//				int oldBoardNumCols = oldBoardGrid.GetLength(1);
//
//				for(int rowIdx = 0; rowIdx < boardNumRows; rowIdx++) {
//					for(int colIdx = 0; colIdx < boardNumCols; colIdx++) {
//						if (rowIdx < oldBoardNumRows && colIdx < oldBoardNumCols) {
//							boardGrid[rowIdx, colIdx] = oldBoardGrid[rowIdx, colIdx];
//						} else {
//							// If the new grid is bigger than the old grid, add default board pieces
//							Match3BoardPiece newPiece = SpawnBoardPieceAt(new BoardCoord(rowIdx, colIdx), defaultBoardPiece.gameObject);
//							UpdateBoardPieceGridTransform(newPiece, new BoardCoord(rowIdx, colIdx));
//						}
//					}
//				}
//
//				// Destroy extra board pieces if the new grid is smaller than the old grid
//				for(int rowIdx = boardNumRows - 1; rowIdx < oldBoardNumRows; rowIdx++) {
//					for(int colIdx = boardNumCols - 1; colIdx < oldBoardNumCols; colIdx++) {
//						DestroyBoardPiece(oldBoardGrid[rowIdx, colIdx]);
//					}
//				}
//			} else {
//				// Init board with default board piece.
//				for(int rowIdx = 0; rowIdx < boardNumRows; rowIdx++) {
//					for(int colIdx = 0; colIdx < boardNumCols; colIdx++) {
//						// If the new grid is bigger than the old grid, add default board pieces
//						Match3BoardPiece newPiece = SpawnBoardPieceAt(new BoardCoord(rowIdx, colIdx), defaultBoardPiece.gameObject);
//						UpdateBoardPieceGridTransform(newPiece, new BoardCoord(rowIdx, colIdx));
//					}
//				}
//			}
        }
        else
        {
            EditorUtility.DisplayDialog("Level Editor", "No BoardData component found on the Match3BoardRenderer!", "Ok");
            return(false);
        }

        return(true);
    }