示例#1
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);
    }
示例#2
0
    private void RefreshNames(string name)
    {
        if (!elementPositions.ContainsKey(name))
        {
            return;
        }
        int i = 1;

        foreach (Vector2Int pos in elementPositions[name])
        {
            BoardObject boardObject = board[pos.x, pos.y].GetPlacedObject();
            boardObject.SetIndex(i++);
            FollowingText text = boardObject.GetComponent <FollowingText>();
            if (text != null)
            {
                text.SetName(boardObject.GetNameWithIndex());
            }
        }
    }