Beispiel #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);
    }
Beispiel #2
0
    public bool AddBoardObject(int id, int x, int y, int orientation = 0, string[] additionalArgs = null)
    {
        if (id >= boardObjectPrefabs.Length || !IsInBoardBounds(x, y))
        {
            return(false);
        }

        BoardObject bObject = Instantiate(boardObjectPrefabs[id], elementsParent);

        bObject.LoadArgs(additionalArgs);
        bObject.SetBoard(this);
        bObject.SetDirection((BoardObject.Direction)orientation);

        return(AddBoardObject(x, y, bObject));
    }