예제 #1
0
 public void ClickDown(HexObject piece)
 {
     if (typeof(Marker) == piece.GetType())
     {
         // Add the rock to the board and place object
         RockObject tmp;
         if (selectedItem != null)
         {
             if (selectedItem.TryGetComponent <RockObject>(out tmp))
             {
                 model.GetBlockedPositions().Add(piece.GetHexPosition());
                 selectedItem.SetHexPosition(piece);
                 selectedItem.gameObject.SetActive(true);
                 selectedItem = null;
                 markersPool.ClearAll();
             }
         }
         else if (selectedUIPiece != null)
         {
             model.GetNotPlacedPieces().Remove(selectedUIPiece.piece);
             model.GetPlacedPieces().Add((piece.x, piece.y, piece.z), selectedUIPiece.piece);
             panels[0].RemovePiece(selectedUIPiece);
             panels[1].RemovePiece(selectedUIPiece);
             markersPool.ClearAll();
             GameObject instance = piecesPool.GetInstance(true);
             instance.GetComponent <PieceObject>().Initialize(selectedUIPiece.piece, ClickDown);
             instance.GetComponent <PieceObject>().SetHexPosition(piece);
             selectedUIPiece = null;
         }
     }
     else if (typeof(RockObject) == piece.GetType())
     {
         markersPool.ClearAll();
         selectedItem = piece;
     }
     else if (typeof(PieceObject) == piece.GetType())
     {
         if (selectedItem != null)
         {
             // Add a chain to the piece
             if (selectedItem.GetComponent <ChainObject>() != null)
             {
                 ((PieceObject)piece).piece.blocked = true;
                 selectedItem.SetHexPosition(piece);
                 selectedItem.gameObject.SetActive(true);
                 selectedItem = null;
                 return;
             }
         }
         // Select piece
         selectedItem = piece;
     }
 }
예제 #2
0
    public void RemovePiece()
    {
        if (selectedItem != null)
        {
            if (selectedItem.GetType() == typeof(RockObject))
            {
                model.GetBlockedPositions().Remove(selectedItem.GetHexPosition());
                selectedItem.gameObject.SetActive(false);
            }

            else if (selectedItem.GetType() == typeof(PieceObject))
            {
                if (((PieceObject)selectedItem).piece.blocked)
                {
                    ((PieceObject)selectedItem).piece.blocked = false;
                    foreach (GameObject obj in chainsPool)
                    {
                        if (obj.GetComponent <ChainObject>().GetHexPosition() == selectedItem.GetHexPosition())
                        {
                            obj.SetActive(false);
                        }
                    }
                    selectedItem = null;
                }
                else
                {
                    model.GetPlacedPieces().Remove((selectedItem.GetHexPosition().x, selectedItem.GetHexPosition().y, selectedItem.GetHexPosition().z));
                    selectedItem.gameObject.SetActive(false);
                }
            }
        }
        else if (selectedUIPiece != null)
        {
            model.GetNotPlacedPieces().Remove(selectedUIPiece.piece);
            panels[0].RemovePiece(selectedUIPiece);
            panels[1].RemovePiece(selectedUIPiece);
        }
    }