コード例 #1
0
    public void PlaceWall(Wall obj)
    {
        CellIndex tile = floor.GetCellIndex(obj.transform.position);

        bool northWall = floor.CellHasWall(new CellIndex(tile.Row + 1, tile.Col));
        bool southWall = floor.CellHasWall(new CellIndex(tile.Row - 1, tile.Col));
        bool eastWall  = floor.CellHasWall(new CellIndex(tile.Row, tile.Col + 1));
        bool westWall  = floor.CellHasWall(new CellIndex(tile.Row, tile.Col - 1));

        int numConnections = 0;

        if (northWall)
        {
            numConnections++;
        }
        if (southWall)
        {
            numConnections++;
        }
        if (eastWall)
        {
            numConnections++;
        }
        if (westWall)
        {
            numConnections++;
        }

        if (numConnections > 0)
        {
            CreateWall(obj, numConnections, northWall, southWall, eastWall, westWall);
            Destroy(obj.gameObject);
        }
        else
        {
            obj.transform.SetParent(wallParent);
            floor.AddObjectToTile(obj, tile);
        }

        if (northWall)
        {
            UpdateWall(new CellIndex(tile.Row + 1, tile.Col));
        }
        if (southWall)
        {
            UpdateWall(new CellIndex(tile.Row - 1, tile.Col));
        }

        if (eastWall)
        {
            UpdateWall(new CellIndex(tile.Row, tile.Col + 1));
        }

        if (westWall)
        {
            UpdateWall(new CellIndex(tile.Row, tile.Col - 1));
        }
    }