Example #1
0
    //===============================================================================================

    public bool TryToMoveFurnitureOffset(Vector2Int characterCoordinate, Vector2Int paraOffset)
    {
        bool res = true;

        // 1.先移除
        for (int i = 0; i < occupyTiles.GetLength(0); i++)
        {
            MainWorldController.DeregisterFurnitureOnSingleTile(this, occupyTiles[i]);
        }

        // 检查主角是否可以移动
        if (!MainWorldController.CheckTilePassable(characterCoordinate + paraOffset))
        {
            res = false;
        }

        // 2.检查当前家具是否能够移动
        for (int i = 0; i < occupyTiles.GetLength(0); i++)
        {
            if (!MainWorldController.CheckTileHaveNoFurniture(occupyTiles[i] + paraOffset))
            {
                res = false;
            }
        }

        if (res)
        {
            for (int i = 0; i < occupyTiles.GetLength(0); i++)
            {
                occupyTiles[i] += paraOffset;
                MainWorldController.RegisterFurnitureOnSingleTile(this, occupyTiles[i]);

                if (itemOnOccupyTile[i] != null)
                {
                    itemOnOccupyTile[i].GetComponent <FurnitureController>().MoveFurnitureOnCFByOffset(paraOffset);
                }
            }

            SetFurnitureMove(this.transform.position + new Vector3(2.5f * paraOffset.x, 0.0f, 2.5f * paraOffset.y));

            //this.transform.position = this.transform.position + new Vector3(2.5f * paraOffset.x, 0.0f, 2.5f * paraOffset.y);
        }
        else
        {
            for (int i = 0; i < occupyTiles.GetLength(0); i++)
            {
                MainWorldController.RegisterFurnitureOnSingleTile(this, occupyTiles[i]);
            }
        }

        return(res);
    }