async void SpawnUnits(string unit_prefab, FieldBounds bounds, int count, uint team_index) { var battleground = Game.GetBattleground(); var tilemap = battleground.GetMainTilemap(); var points = bounds.GetAllPoints(); points.Shuffle(); if (points.Count < count) { Debug.LogWarning($"Can't spawn {count} units, trim to free points count."); count = points.Count; } for (int i = 0; i < count; i++) { var asset = await Assets.LoadAsync(unit_prefab); var unit = asset.AddComponentOnce <BattleUnit>(); unit.Init(team_index); var cell_x = Mathf.RoundToInt(points[i].x); var cell_y = Mathf.RoundToInt(points[i].y); var point = new Vector3Int(cell_x, cell_y, 0); var world_pos = tilemap.CellToWorld(point); world_pos.x += Battleground.UNIT_WORLD_POS_OFFSET_X; world_pos.y += Battleground.UNIT_WORLD_POS_OFFSET_Y; unit.transform.position = world_pos; battleground.AddUnit(unit); } }
public Pathfinder(Battleground battleground, Tilemap main_tilemap, Tilemap decor_tilemap, FieldBounds field_bounds) { this.battleground = battleground; this.main_tilemap = main_tilemap; this.decor_tilemap = decor_tilemap; this.field_bounds = field_bounds; this.field = new int[field_bounds.GetWidth(), field_bounds.GetHeight()]; }