Esempio n. 1
0
    public bool MoveBoardObject(Vector2Int from, Vector2Int to)
    {
        if (IsInBoardBounds(from) && IsInBoardBounds(to) && from != to)
        {
            BoardCell cell = board[to.x, to.y];
            if (cell.GetState() != BoardCell.BoardCellState.FREE)
            {
                return(false);
            }


            BoardObject bObject = board[from.x, from.y].GetPlacedObject();
            if (bObject == null)
            {
                return(false);
            }

            board[from.x, from.y].RemoveObject(false);
            board[to.x, to.y].PlaceObject(bObject);
            if (elementPositions != null)
            {
                elementPositions[bObject.GetNameAsLower()].Remove(from);
                elementPositions[bObject.GetNameAsLower()].Add(to);
            }
            return(true);
        }
        return(false);
    }
Esempio n. 2
0
    public bool AddBoardObject(int x, int y, BoardObject boardObject)
    {
        if (IsInBoardBounds(x, y) && boardObject != null)
        {
            bool placed = board[x, y].PlaceObject(boardObject);
            if (!placed)
            {
                return(false);
            }

            if (boardObject.transform.parent != elementsParent)
            {
                boardObject.transform.SetParent(elementsParent);
                boardObject.SetBoard(this);
            }
            if (elementPositions != null)
            {
                string name = boardObject.GetNameAsLower();
                if (!elementPositions.ContainsKey(name))
                {
                    elementPositions[name] = new List <Vector2Int>();
                }

                elementPositions[name].Add(new Vector2Int(x, y));
                boardObject.SetIndex(elementPositions[name].Count);

                FollowingText text = boardObject.GetComponent <FollowingText>();
                if (text != null)
                {
                    text.SetName(boardObject.GetNameWithIndex());
                }
            }

            if (boardModifiable)
            {
                DraggableObject drag = boardObject.gameObject.GetComponent <DraggableObject>();
                if (drag == null)
                {
                    drag = boardObject.gameObject.AddComponent <DraggableObject>();
                    drag.SetBoard(this);
                    drag.SetArgumentLoader(argLoader);
                    drag.SetCameraInput(cameraInput);
                    drag.SetOrbitCamera(orbitCamera);
                    drag.SetLastPos(new Vector2Int(x, y));
                }
                drag.SetModifiable(objectsModifiable);
            }
            return(placed);
        }
        return(false);
    }