// Update is called once per frame void Update() { if (Input.GetMouseButtonUp(0)) { Tap(Input.mousePosition); } if (Input.GetMouseButtonDown(1)) { ChangeTile(Input.mousePosition); } /* 座標表示 */ TextObj.transform.position = Input.mousePosition; Vector3 screenToWorldPointPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3Int cellPosition = GridMap.GetComponent <Grid>().LocalToCell(screenToWorldPointPosition); TextObj.GetComponent <Text>().text = "[" + MapCtl.offset_tile2stg_x(cellPosition.x) + "," + MapCtl.offset_tile2stg_y(cellPosition.y) + "]"; }
private void ChangeTile(Vector3 point) { // タップ時の処理を記述 point.z = 10.0f; Vector3 screenToWorldPointPosition = Camera.main.ScreenToWorldPoint(point); //Grid grid = transform.parent.GetComponent<Grid>(); Vector3Int cellPosition = GridMap.GetComponent <Grid>().LocalToCell(screenToWorldPointPosition); switch (GridMap.tileMap[MapCtl.offset_tile2stg_x(cellPosition.x), MapCtl.offset_tile2stg_y(cellPosition.y)].getType()) { case TileType.DeepSea: /* 深い海 */ GridMap.putTile(TileType.ShallowSea, MapCtl.offset_tile2stg_x(cellPosition.x), MapCtl.offset_tile2stg_y(cellPosition.y)); break; case TileType.ShallowSea: /* 浅い海 */ GridMap.putTile(TileType.SandyBeach, MapCtl.offset_tile2stg_x(cellPosition.x), MapCtl.offset_tile2stg_y(cellPosition.y)); break; case TileType.SandyBeach: /* 砂地 */ GridMap.putTile(TileType.Meadow, MapCtl.offset_tile2stg_x(cellPosition.x), MapCtl.offset_tile2stg_y(cellPosition.y)); break; case TileType.Meadow: /* 緑地 */ GridMap.putTile(TileType.Forest, MapCtl.offset_tile2stg_x(cellPosition.x), MapCtl.offset_tile2stg_y(cellPosition.y)); break; case TileType.Forest: /* 森 */ GridMap.putTile(TileType.Mountain, MapCtl.offset_tile2stg_x(cellPosition.x), MapCtl.offset_tile2stg_y(cellPosition.y)); break; case TileType.Mountain: /* 山 */ GridMap.putTile(TileType.OilField, MapCtl.offset_tile2stg_x(cellPosition.x), MapCtl.offset_tile2stg_y(cellPosition.y)); break; default: /* 資源・その他 */ GridMap.putTile(TileType.DeepSea, MapCtl.offset_tile2stg_x(cellPosition.x), MapCtl.offset_tile2stg_y(cellPosition.y)); break; } ; }
private void Tap(Vector3 point) { // 陸地をチェック //Vector3 screenToWorldPointPosition = Camera.main.ScreenToWorldPoint(point); //Vector3Int cellPosition = GridMap.GetComponent<Grid>().LocalToCell(screenToWorldPointPosition); //var ret = GridMap.landArea( new Vector2Int(MapCtl.offset_tile2stg_x(cellPosition.x), MapCtl.offset_tile2stg_y(cellPosition.y))); // LineRenderer lr = Instantiate(renderer); // //// 線の幅 //lr.SetWidth(0.1f, 0.1f); //// 頂点の数 //lr.SetVertexCount(ret.Count); //// 頂点を設定 //for (int i=0;i<ret.Count;i++){ // lr.SetPosition(i, GridMap.GetComponent<Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(ret[i].x), MapCtl.offset_stg2tile_y(ret[i].y), 0)) + new Vector3(0f, 0f, -1f)); //} // タップ時の処理を記述 point.z = 10.0f; Vector3 screenToWorldPointPosition = Camera.main.ScreenToWorldPoint(point); //Grid grid = transform.parent.GetComponent<Grid>(); Vector3Int cellPosition = GridMap.GetComponent <Grid>().LocalToCell(screenToWorldPointPosition); Debug.Log("[" + cellPosition.x + "," + cellPosition.y + "]"); GridMap.ClickMap(cellPosition); var ret = GridMap.chkOpenSea(new Vector2Int(MapCtl.offset_tile2stg_x(cellPosition.x), MapCtl.offset_tile2stg_y(cellPosition.y)), 20, TileGroup.Sea); Debug.Log("[chkOpenSea = " + ret + "]"); //if (count == 0) { // spos = new Vector2Int(MapCtl.offset_tile2stg_x(cellPosition.x), MapCtl.offset_tile2stg_y(cellPosition.y)); // count=1; // //} else { // epos = new Vector2Int(MapCtl.offset_tile2stg_x(cellPosition.x), MapCtl.offset_tile2stg_y(cellPosition.y)); // ast.getRoute(spos, epos, GridMap.tileMap, 2, TapCb); //A-Sterによる経路取得 // count=0; //} }
void Update() { //if(Input.GetMouseButtonDown(0)){ // var mousePos = Input.mousePosition; // mousePos.z = 10.0f; // destList.Add(Camera.main.ScreenToWorldPoint(mousePos)); // Debug.Log(Camera.main.ScreenToWorldPoint(mousePos)); //} if (destList.Count > 0) //移動中 { Vector2 dif = destList[0] - (Vector2)transform.position; // ラジアン float radian = Mathf.Atan2(dif.y, dif.x); // 角度 float degree = radian * Mathf.Rad2Deg + 270.0f; float degree_diff = (rid2.rotation - degree + 360.0f) % 360.0f; if ((degree_diff > 0.0f) && (degree_diff < 180.0f)) { rid2.rotation -= yawrate; if (rid2.rotation < 0f) { rid2.rotation += 360.0f; } } else { rid2.rotation += yawrate; } if ((degree_diff > 45.0f) && (degree_diff < 325.0f) && (type != uType.Aircraft)) { if (speed > 0.0f) { speed -= 0.01f; } else { speed = 0.0f; } } else { if (speed < speedMax) { speed += 0.01f; } else { speed = speedMax; } } //到着時はリスト削除 if (Vector2.Distance(destList[0], (Vector2)transform.position) < 0.1f) { if ((type != uType.Aircraft) || (destList.Count() > 1)) { destList.Remove(destList[0]); } else if (works == WorkType.Returning) // 空港・空母へ帰還 { destList.Clear(); chgWorkType(WorkType.Repairing); } } Vector3Int cellPosition = map.GetComponent <Grid>().LocalToCell(transform.position); pos = new Vector2Int(MapCtl.offset_tile2stg_x(cellPosition.x), MapCtl.offset_tile2stg_y(cellPosition.y)); if ((pos.x != old_pos.y) || (pos.y != old_pos.y)) { player.vMap.moveUnit(old_pos, pos, 4); } old_pos = pos; fuelCnt += Time.deltaTime; if (fuelCnt > fuelEfc) { fuel--; //燃料消費 fuelCnt -= fuelEfc; } } else { if (speed > 0.0f) { speed -= 0.05f; } else { speed = 0.0f; } if ((works == WorkType.Moving) || (works == WorkType.Unloading)) { //if (units == Unit.TransportShip){ // if (map.tileRing(pos, 1).Exists(tll => (((map.tileMap[tll.x,tll.y].getGroup() == TileGroup.Ground)||(map.tileMap[tll.x,tll.y].getGroup() == TileGroup.Mountain))))){ // chgWorkType(WorkType.None); // } else { // chgWorkType(WorkType.None); // } //} else { chgWorkType(WorkType.None); destDir = 999; //} } else if (works == WorkType.Loading) { gameObject.SetActive(false); //非表示 transform.parent.GetComponent <UnitObj>().loadUnits.Add(this); // 修理・補給中 } else if (works == WorkType.Repairing) { if ((fuel < fuelMax) || (hp < hpMax)) { fuelCnt += Time.deltaTime; if (fuelCnt > fixEfc) { if (hp < hpMax) { hp++; //修理(優先) } else if (fuel < fuelMax) { fuel++; //燃料補給 } fuelCnt -= fixEfc; } } else //修理・補給完了 { chgWorkType(WorkType.None); } } } if (works == WorkType.Newing) { imgFill += 0.01f; material.SetFloat("_FillAmount", imgFill); if (imgFill > 1.0f) { if (type == uType.Aircraft) { // 格納庫に格納 chgWorkType(WorkType.None); if (transform.parent != null) { transform.parent.GetComponent <UnitObj>().chgWorkType(WorkType.None); } } else { chgWorkType(WorkType.None); if (transform.parent != null) { transform.parent.GetComponent <UnitObj>().chgWorkType(WorkType.None); transform.parent = null; } } } } rid2.velocity = transform.up * speed; }