Ejemplo n.º 1
0
    public static AtmosSimulation FromTilemap(Tilemap tilemapVisual, int chunkSize = 3)
    {
        var tilemapSize   = tilemapVisual.size;
        var tilemapOrigin = tilemapVisual.origin;

        var worstCaseSize = tilemapSize.x * tilemapSize.y;
        var grid          = new ChunkedGrid <AtmosCell>(chunkSize, worstCaseSize);

        for (int x = tilemapOrigin.x; x < tilemapSize.x + tilemapOrigin.x; x++)
        {
            for (int y = tilemapOrigin.y; y < tilemapSize.y + tilemapOrigin.y; y++)
            {
                var pos = new Vector3Int(x, y, 0);

                // Is there any tile?
                var tile = tilemapVisual.GetTile <GridTile>(pos);
                if (tile != null)
                {
                    var atmosCell = new AtmosCell()
                    {
                        pressure = tile.pressure,
                        isWall   = tile.isWall
                    };

                    grid.AddCell(x, y, atmosCell);
                }
            }
        }

        return(new AtmosSimulation(grid));
    }
Ejemplo n.º 2
0
    public void Execute(AtmosSimulation simulation)
    {
        var grid = simulation.currentState;

        if (!grid.HasCell(pos.x, pos.y))
        {
            var newCell = new AtmosCell()
            {
                isWall = true
            };
            grid.AddCell(pos.x, pos.y, newCell);
            simulation.currentState = grid;
        }
        else
        {
            var cell = simulation.currentState[pos.x, pos.y];
            cell.isWall = true;
            simulation.currentState[pos.x, pos.y] = cell;
        }
    }
Ejemplo n.º 3
0
    public void Execute(AtmosSimulation simulation)
    {
        var grid = simulation.currentState;

        if (!grid.HasCell(pos.x, pos.y))
        {
            var newCell = new AtmosCell()
            {
                isWall = false, pressure = ammount
            };
            grid.AddCell(pos.x, pos.y, newCell);
            simulation.currentState = grid;
        }
        else
        {
            var cell = simulation.currentState[pos.x, pos.y];
            cell.pressure += ammount;
            simulation.currentState[pos.x, pos.y] = cell;
        }
    }