Esempio n. 1
0
        private void SetTileByRef(TileSlot tile, Vector2Int gridPosition, TileMapLayer tilemapLayer, bool countsAsEdit, ref TileSlot[,] tileArr, ref Tilemap tilemap, bool generation = false)
        {
            Vector2Int chunkPosition = GridToChunkPosition(gridPosition);
            bool       tileExists    = tileArr != null && tileArr[chunkPosition.x, chunkPosition.y] != null;

            if (tile != null || tileExists)
            {
                if (tileArr == null)
                {
                    tileArr = new TileSlot[CHUNK_SIZE, CHUNK_SIZE];
                }
                if (tileExists && tile == null)
                {
                    tileArr[chunkPosition.x, chunkPosition.y].CancelEvent(gridPosition, tilemapLayer);
                    tilemap.SetTile((Vector3Int)gridPosition, null);
                    tileArr[chunkPosition.x, chunkPosition.y] = null;

                    tileCount--;
                    wasEdited |= countsAsEdit;
                    if (tileCount == 0)
                    {
                        tileArr = null;
                    }
                }
                else if (!tileExists)
                {
                    tileCount++;
                    wasEdited |= countsAsEdit;
                    tile.Init(gridPosition, tilemapLayer, generation);
                    tilemap.SetTile((Vector3Int)gridPosition, tile.GetMainTileBase);
                    tileArr[chunkPosition.x, chunkPosition.y] = tile;
                }
                else
                {
                    if (tile != tileArr[chunkPosition.x, chunkPosition.y])
                    {
                        tileArr[chunkPosition.x, chunkPosition.y].CancelEvent(gridPosition, tilemapLayer);
                        tileArr[chunkPosition.x, chunkPosition.y] = tile;
                        tile.Init(gridPosition, tilemapLayer, generation);
                    }
                    tilemap.SetTile((Vector3Int)gridPosition, tile.GetMainTileBase);
                    wasEdited |= countsAsEdit;
                }
            }
        }
Esempio n. 2
0
    public override void Init()
    {
        islandsNoise.GenerateSeed();
        buildingsRandom.GenerateSeed();
        CameraController._instance.UpdateView();
        SetTile(new TileSlot(craftingTable1), new Vector2Int(-7, 0), TileMapLayer.Buildings, true);
        SetTile(new TileSlot(craftingTable2), new Vector2Int(-6, 0), TileMapLayer.Buildings, true);
        TileSlot tree = new TileSlot(buildingsGeneration[0].tile);

        tree.Init(new Vector2Int(4, 0), TileMapLayer.Buildings, true);
        SetTile(tree, new Vector2Int(4, 0), TileMapLayer.Buildings, true);
    }