// ユニット削除 public void moveRemove(Vector2Int pos, int fov) { List <Vector2Int> vList = tileArea(pos, fov); foreach (Vector2Int _p in vList) { visible[_p.x, _p.y]--; if ((visible[_p.x, _p.y] == 0) && (vMask != null)) { vMask.SetTile(new Vector3Int(MapCtl.offset_stg2tile_x(_p.x), MapCtl.offset_stg2tile_y(_p.y), 0), mask); } } }
// 親ユニットに帰る public bool doReturn() { if (transform.parent == null) { return(false); } if (type == uType.Aircraft) { destList.Clear(); //destList.Add(transform.parent.GetComponent<UnitObj>().pos); var p = transform.parent.GetComponent <UnitObj>().pos; destList.Add(new Vector2Int(MapCtl.offset_stg2tile_x(p.x), MapCtl.offset_stg2tile_y(p.y))); } chgWorkType(WorkType.Returning); return(true); }
// 初期化 public ViewMap(Tilemap _vMap = null, Tilemap _vMask = null) { vMap = _vMap; vMask = _vMask; //Tilemapのクリア tileList = new List <TileObj>(); visible = new int[StageCtl.TileLenX, StageCtl.TileLenY]; //タイル要素定義 tileMap = new TileObj[StageCtl.TileLenX, StageCtl.TileLenY]; for (int x = 0; x < StageCtl.TileLenX; x++) { for (int y = 0; y < StageCtl.TileLenY; y++) { if (vMask != null) { vMask.SetTile(new Vector3Int(MapCtl.offset_stg2tile_x(x), MapCtl.offset_stg2tile_y(y), 0), mask); } } } }
//タップ結果コールバック public void TapCb(List <Vector2Int> rt, int ret) { Debug.Log(string.Format("Min: (ret={0})", ret)); LineRenderer lr = Instantiate(renderer); // 線の幅 lr.SetWidth(0.1f, 0.1f); // 頂点の数 lr.SetVertexCount(rt.Count); // 頂点を設定 for (int i = 0; i < rt.Count; i++) { lr.SetPosition(i, GridMap.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(rt[i].x), MapCtl.offset_stg2tile_y(rt[i].y), 0)) + new Vector3(0f, 0f, -1f)); } }
//タップ結果コールバック public void TapCbs(List <Vector2Int> rt) { AddUnit("AAA", new Vector2Int(rt[0].x, rt[0].y), players[0], Unit.Surveillance); testUnit.addMoveList(rt.Select(pos => new Vector2(map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(pos.x), MapCtl.offset_stg2tile_y(pos.y), 0)).x, map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(pos.x), MapCtl.offset_stg2tile_y(pos.y), 0)).y)).ToList()); // 線の幅 renderer.SetWidth(0.1f, 0.1f); // 頂点の数 renderer.SetVertexCount(rt.Count); // 頂点を設定 for (int i = 0; i < rt.Count; i++) { renderer.SetPosition(i, map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(rt[i].x), MapCtl.offset_stg2tile_y(rt[i].y), 0)) + new Vector3(0f, 0f, -1f)); } }
void doAstMoveCb(List <Vector2Int> rt, int ret) { if ((works == WorkType.PreMove) || (works == WorkType.Moving)) { chgWorkType(WorkType.Moving); if (rt?.Count > 0) { var startPos = new Vector2(map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(rt[0].x), MapCtl.offset_stg2tile_y(rt[0].y), 0)).x, map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(rt[0].x), MapCtl.offset_stg2tile_y(rt[0].y), 0)).y); rt.RemoveAt(0); if (lock_timer == 0) { if ((destList.Count == 0) || ((destList.Last().x == startPos.x) && (destList.Last().y == startPos.y))) { if (destDir > ret) { this.addMoveList(rt.Select(pos => new Vector2(map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(pos.x), MapCtl.offset_stg2tile_y(pos.y), 0)).x, map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(pos.x), MapCtl.offset_stg2tile_y(pos.y), 0)).y)).ToList()); destDir = ret; if (ret > 0) { if (destList?.Count > 0) { doMove(MapCtl.offset_vec2stg(LastDest), MapCtl.offset_vec2stg(destList.Last())); } } } } lock_retry = 0; } else { if ((destList.Count == 0) || ((destList.Last().x != startPos.x) && (destList.Last().y != startPos.y))) { destList.Clear(); this.addMoveList(rt.Select(pos => new Vector2(map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(pos.x), MapCtl.offset_stg2tile_y(pos.y), 0)).x, map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(pos.x), MapCtl.offset_stg2tile_y(pos.y), 0)).y)).ToList()); //destList.RemoveAt(0); destDir = ret; if (ret > 0) { if (destList?.Count > 0) { doMove(MapCtl.offset_vec2stg(LastDest), MapCtl.offset_vec2stg(destList.Last())); } } lock_timer = 0; lock_retry++; } } } // 線の幅 renderer.SetWidth(0.1f, 0.1f); // 頂点の数 renderer.SetVertexCount(destList.Count); // 頂点を設定 for (int i = 0; i < destList.Count; i++) { renderer.SetPosition(i, new Vector3(destList[i].x, destList[i].y, -1f)); } } }
//A-Starでの移動(OList = 移動不可の位置) public void doMove(Vector2Int epos, Vector2Int?_spos = null, List <Vector2Int> Olist = null) { if (works != WorkType.Moving) { chgWorkType(WorkType.PreMove); } var spos = _spos ?? pos; LastDest = map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(epos.x), MapCtl.offset_stg2tile_y(epos.y), 0)); //Debug.Log (string.Format ("doMove: ({0},{1})", spos, epos)); switch (type) { case uType.Infantry: /* 歩兵 */ map.getRoute(spos, epos, 2, doAstMoveCb, Olist); //A-Sterによる経路取得 break; case uType.Vehicle: /* 車両 */ map.getRoute(spos, epos, 1, doAstMoveCb, Olist); //A-Sterによる経路取得 break; case uType.Aircraft: /* 航空機 */ destList.Clear(); chgWorkType(WorkType.Moving); destList.Add(epos); break; case uType.Warship: /* 戦艦 */ case uType.Submarine: /* 潜水艦 */ map.getRoute(spos, epos, 0, doAstMoveCb, Olist); //A-Sterによる経路取得 break; default: /* その他 */ break; } }
// ユニットから降りる (false: 失敗 dst 降りる先) public bool doUnload(UnitObj tgtObj, Vector2Int?dst = null) { Debug.Log(string.Format("Unload!!")); // if (dst != null) { //降りる候補を選定 } else { Vector2Int?dsts = map.tileRing(pos, 1).FirstOrDefault(tll => (map.tileMap[tll.x, tll.y].getGroup() == TileGroup.Ground)); if (dsts != null) { //候補がある場合 tgtObj.gameObject.SetActive(true); tgtObj.destList.Clear(); tgtObj.destList.Add(new Vector2(map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x((int)dsts?.x), MapCtl.offset_stg2tile_y((int)dsts?.y), 0)).x, map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x((int)dsts?.x), MapCtl.offset_stg2tile_y((int)dsts?.y), 0)).y)); tgtObj.transform.parent = null; loadUnits.Remove(tgtObj); tgtObj.chgWorkType(WorkType.Unloading); //tgtObj.pos = (Vector2Int)dsts; } else { //候補がない場合 return(false); } } //if (map.MapDist(pos, dst.pos) > 1) return false; //destList.Clear(); //destList.Add(new Vector2(map.GetComponent<Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(dst.pos.x),MapCtl.offset_stg2tile_y(dst.pos.y), 0)).x, // map.GetComponent<Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(dst.pos.x), MapCtl.offset_stg2tile_y(dst.pos.y), 0)).y)); //dst.pos); //chgWorkType(WorkType.Loading); // return(true); }
// ユニットに乗る (false: 失敗) public bool doLoad(UnitObj dst) { if (map.MapDist(pos, dst.pos) > 1) { return(false); } Debug.Log(string.Format("Load!!")); destList.Clear(); destList.Add(new Vector2(map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(dst.pos.x), MapCtl.offset_stg2tile_y(dst.pos.y), 0)).x, map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(dst.pos.x), MapCtl.offset_stg2tile_y(dst.pos.y), 0)).y)); //dst.pos); chgWorkType(WorkType.Loading); transform.parent = dst.transform; //dst.chgWorkType(WorkType.Loading); return(true); }
//ユニット作成(リスト追加は外部で実施すること) public static UnitObj Create(String _name, Unit _type, Vector2Int _pos, PlayerCtl _player) { UnitObj newObj = Instantiate(_player.utltList.FirstOrDefault(u => u.units == _type)); //対象のシェーダー情報を取得 Shader sh = _player.utltList.FirstOrDefault(u => u.units == _type).transform.GetComponent <SpriteRenderer>().material.shader; //Find("Texture"). //取得したシェーダーを元に新しいマテリアルを作成 Material mat = new Material(sh); newObj.transform.GetComponent <SpriteRenderer>().material = mat; //Find("Texture"). newObj.name = _name; newObj.pos = _pos; newObj.old_pos = _pos; newObj.hp = newObj.hpMax; newObj.fuel = newObj.fuelMax; newObj.gameObject.SetActive(true); //表示 newObj.lock_max = UnityEngine.Random.Range(10, 100); newObj.player = _player; newObj.gameObject.SetActive(true); newObj.GetComponent <SpriteRenderer>().color = _player.pColor; newObj.chgWorkType(WorkType.Newing); newObj.gameObject.name = "Obj_" + _player.pnum + "_" + _type.ToString(); _player.vMap.moveAdd(_pos, 3); if (newObj.type != uType.Building) { StageCtl.UnitList[newObj.player.pnum].Insert(0, newObj); //先頭 } else { StageCtl.UnitList[newObj.player.pnum].Add(newObj); //末尾 } newObj.transform.position = map.GetComponent <Grid>().GetCellCenterWorld(new Vector3Int(MapCtl.offset_stg2tile_x(_pos.x), MapCtl.offset_stg2tile_y(_pos.y), 0)) - new Vector3(0f, 0f, 1f); return(newObj); }