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); } }
protected override void Init() { battleground = Game.GetBattleground(); canvas_go = this.GetChild("canvas"); this.GetChild("canvas/btn_exit").MakeButton(Exit); base.Init(); }
void Awake() { battleground = Game.GetBattleground(); fsm = new StateMachine <BattleUnitState>(); AddState(new StateSpawning()); AddState(new StateIdle()); AddState(new StateMoving()); AddState(new StateAttacking()); AddState(new StateDying()); fsm.SwitchTo(BattleUnitState.Spawning); }
public Vector2 GetTilePosition() { var battleground = Game.GetBattleground(); if (battleground == null || !battleground.IsLoaded()) { return(Vector2.zero); } var tilemap = battleground.GetMainTilemap(); var cell_pos = tilemap.WorldToCell(transform.position); var tile_pos = new Vector2(cell_pos.x, cell_pos.y); return(tile_pos); }
public BattleManager() { this.battleground = Game.GetBattleground(); Error.Assert(this.battleground != null, "Unable to create BattleManager - battleground is not exist."); }