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 async UniTask LoadLocation() { location = await Assets.LoadAsync("Location"); Error.Verify(location != null); Debug.Log("Location loaded succesfully"); }
public static async UniTask<T> OpenAsync<T>() where T : UIWindow { string prefab = GetPrefab(typeof(T)); var ui_window_go = await Assets.LoadAsync(prefab, windows_container.transform); var window = ui_window_go.AddComponentOnce<T>(); if(window != null) windows.Add(window); return window as T; }
static async UniTask<UIWindow> LoadWindowAsync(string name) { var prefab = await Assets.LoadAsync($"Prefabs/ui/windows/{name}", parent: windows_container.transform); var window = prefab.GetComponent<UIWindow>(); Error.Assert(window != null, $"Failed to load UI window ({name}). UIWindow component not found."); window.SetNameHash(Hash.CRC32(name)); return window; }