Exemplo n.º 1
0
    private PieceController InitPiece(int colIndex, int rowIndex, Boolean isBlocker = false)
    {
        if (_piecesParent == null)
        {
            Debug.Log("Invalid piece parent");
            return(null);
        }
        var             position = GetPiecePositionOnGrid(colIndex, rowIndex);
        var             prefab   = isBlocker ? GetBlockerPrefab() : GetPiecePrefab();
        PieceController piece    = null;

        if (prefab != null)
        {
            piece = Instantiate <PieceController>(prefab, position, Quaternion.identity, _piecesParent.transform);
            piece.Initialize(colIndex, rowIndex);
            piece.OnPieceClickedEvent += OnPieceClicked;
            if (!isBlocker)
            {
                AddPiece(piece);
            }
            else
            {
                AddBlocker(piece);
            }
        }
        return(piece);
    }
Exemplo n.º 2
0
    public void MakePiece(Grid grid)
    {
        GameObject      p     = Instantiate(nodePiece, gameBoard); // piece Object 생성
        PieceController piece = p.GetComponent <PieceController>();
        RectTransform   rect  = p.GetComponent <RectTransform>();

        rect.anchoredPosition = new Vector2(BoardController.anchor_x + (120 * grid.point.x), BoardController.anchor_y - (70 * grid.point.y)); // global위치 세팅
        piece.Initialize(grid.value, new Point(grid.point.x, grid.point.y));                                                                  // pieceController 값 세팅
        grid.SetPiece(piece);                                                                                                                 // Grid와 piece 연결
    }