コード例 #1
0
    //接触
    public void OnCollision2D(Collider2D other)
    {
        List <Vector2Int> Olist = new List <Vector2Int>();

        Olist.Add(MapCtl.offset_vec2stg(destList[1]));
        doMove(MapCtl.offset_vec2stg(LastDest), null, Olist);
    }
コード例 #2
0
    // ユニット削除
    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);
            }
        }
    }
コード例 #3
0
 // 親ユニットに帰る
 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);
 }
コード例 #4
0
    // 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) + "]";
    }
コード例 #5
0
    // Start is called before the first frame update
    void Start()
    {
        UnitList   = StageCtl.UnitList[0];
        cpuTileMap = new cpuMapTile[StageCtl.TileLenX, StageCtl.TileLenY];
        map        = GameObject.Find("Grid").GetComponent <MapCtl>();

        //新しいユニットが生成されたかチェック
        foreach (var units in StageCtl.UnitList[0])
        {
            if (cpuUnitList.Any(u => u.tgtUnit == units) == false)
            {
                cpuUnit newUnit = new cpuUnit();
                newUnit.tgtUnit = units;
                cpuUnitList.Add(newUnit);
            }
        }

        //油田リスト
        visOilList.AddRange(map.tileList.Where(t => t.getType() == TileType.OilField).Select(t => new visOil(new Vector2Int(t.getPosX(), t.getPosY()))));
        Debug.Log("[visOilList=" + visOilList.Count() + "]" + visOilList[0].pos);

        foreach (var units in cpuUnitList)
        {
            switch (units.tgtUnit.units)
            {
            case Unit.Capital:                                  /* 首都 */
                var landList = map.landArea(units.tgtUnit.pos); /* 陸地をチェック */
                if (landList?.Count > 0)
                {
                    //Debug.Log("[landList="+ landList.Count +"]");
                    foreach (var land in landList)
                    {
                        //Debug.Log("[land="+ land +"]");
                        cpuTileMap[land.x, land.y].domain += 10;
                    }
                }
                break;
            }
        }
    }
コード例 #6
0
    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;
        //}
    }
コード例 #7
0
    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;
        }
        ;
    }
コード例 #8
0
    //接触中
    void OnCollisionStay2D(Collision2D other)
    {
        if (works == WorkType.Moving)
        {
            lock_timer++;
            if (lock_timer == lock_max)
            {
                if (lock_retry < 3)
                {
                    if (destList?.Count > 1)
                    {
                        destList.RemoveAt(0);
                    }
                    var mList = map.tileRing(pos, 1).Where(c => map.chkMoveObj(c, type)).OrderBy(i => System.Guid.NewGuid()).ToList();                  //
                    if (mList?.Count > 1)
                    {
                        destList.Insert(0, MapCtl.offset_stg2vec(mList[0]));
                    }
                    //destList.Insert(0, new Vector2(transform.position.x + UnityEngine.Random.Range(-1, 2), transform.position.y + UnityEngine.Random.Range(-1, 2)));
                    lock_timer = 0;
                    lock_retry++;
                    //List<Vector2Int> Olist = new List<Vector2Int>();
                    //if (destList?.Count > 1) Olist.Add(MapCtl.offset_vec2stg(destList[1]));
                    //doMove(MapCtl.offset_vec2stg(LastDest), null, Olist);

                    /* 3回リトライしても解決しない場合は行動クリア */
                }
                else
                {
                    destList.Clear();
                    chgWorkType(WorkType.None);
                    destDir    = 999;
                    lock_timer = 0;
                    lock_retry = 0;
                }
            }
        }
    }
コード例 #9
0
    // 初期化
    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);
                }
            }
        }
    }
コード例 #10
0
    //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;
        }
    }
コード例 #11
0
 void Awake()
 {
     instance = this;
     map      = GameObject.Find("Grid").GetComponent <MapCtl>();
 }
コード例 #12
0
 // ユニットに乗る (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);
 }
コード例 #13
0
 // ユニットから降りる (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);
 }
コード例 #14
0
    //タップ結果コールバック
    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));
        }
    }
コード例 #15
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;
    }
コード例 #16
0
    // Update is called once per frame
    void Update()
    {
        timeleft -= Time.deltaTime;
        //5秒おき
        if (timeleft <= 0.0)
        {
            timeleft = 5.0f;
            //新しいユニットが生成されたかチェック
            foreach (var units in StageCtl.UnitList[0])
            {
                if (cpuUnitList.Any(u => u.tgtUnit == units) == false)
                {
                    cpuUnit newUnit = new cpuUnit();
                    newUnit.tgtUnit = units;
                    cpuUnitList.Add(newUnit);
                }
            }
        }


        //Debug.Log("[cpuUnit="+ cpuUnitList.Count +"]");

        //ユニットごとの処理
        //foreach(var cUnit in cpuUnitList){
        for (int i = cpuUnitList.Count() - 1; i >= 0; i--)
        {
            if (cpuUnitList[i].tgtUnit == null)
            {
                cpuUnitList.RemoveAt(i);
                continue;
            }
            UnitObj units = cpuUnitList[i].tgtUnit;
            switch (units.units)
            {
            case Unit.LargeTransport:                                                   /* 大型輸送車 */
                if ((units.works == WorkType.None) && (units.transform.parent == null)) //★要改善!
                /* ユニットが搭載されている */
                {
                    if (units.loadUnits.Count > 0)
                    {
                        switch (units.loadUnits[0].units)
                        {
                        case Unit.OilWell:                                 /* 油井 */
                            /* 油田上に居る場合 */
                            if (map.tileMap[units.pos.x, units.pos.y].getType() == TileType.OilField)
                            {
                                units.doDeployUnit();
                            }
                            else
                            {
                                var u = units.canLoad(cpuUnitList[i].hopeRideShip);
                                if (u != null)
                                {
                                    units.doLoad(u);
                                    units.LastDest              = MapCtl.offset_stg2vec(cpuUnitList[i].cpuTgtPos);
                                    cpuUnitList[i].cWorkType    = CpuWorkType.None;
                                    cpuUnitList[i].hopeRideShip = null;
                                }
                                else
                                {
                                    //
                                    if (cpuUnitList[i].hopeRideShip == null)
                                    {
                                        /* 移動先油田未設定 */
                                        //Debug.Log("cpuUnit["+ i +"].cpuTgtPos = " + cpuUnitList[i].cpuTgtPos +"]");
                                        if (cpuUnitList[i].cpuTgtPos.x == -1)
                                        {
                                            visOil OilObj = visOilList.Where(uu => uu.tgtUnit == null).ToList().Find(s => map.MapDist(cpuUnitList[i].tgtUnit.pos, s.pos) == visOilList.Where(uu => uu.tgtUnit == null).ToList().Min(p => map.MapDist(cpuUnitList[i].tgtUnit.pos, p.pos)));
                                            //if (OilObj){
                                            cpuUnitList[i].cpuTgtPos = OilObj.pos;
                                            OilObj.tgtUnit           = cpuUnitList[i].tgtUnit.loadUnits[0];
                                            //Debug.Log("cpuUnit["+ i +"].cpuTgtPos = " + cpuUnitList[i].cpuTgtPos +"]");
                                            //}
                                        }
                                        /* 開いている最短の油田へ経路探索 */
                                        if ((cpuUnitList[i].cWorkType == CpuWorkType.None) && (cpuUnitList[i].cpuTgtPos.x > -1))
                                        {
                                            srcOil(cpuUnitList[i]);
                                            cpuUnitList[i].hopeRideShip = null;
                                            Debug.Log("srcOil cpuUnit[" + i + "].cpuTgtPos = " + units.pos + " ->" + cpuUnitList[i].cpuTgtPos + "]");
                                            //units.doMove(map.getSpcTilePos(new Vector2Int(0,0), new Vector2Int (StageCtl.TileLenX, StageCtl.TileLenY), TileType.OilField, TileType.None)[0]);
                                        }
                                    }
                                    else
                                    {
                                        units.doMove(cpuUnitList[i].hopeRideShip.pos);
                                    }
                                }
                            }
                            break;

                        case Unit.NavalPort:                                 /* 軍港 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.ShallowSea);
                                units.doMove(clist[0]);
                            }
                            break;

                        case Unit.Airfield:                                 /* 飛行場 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.Meadow);
                                units.doMove(clist[0]);
                            }
                            break;

                        case Unit.Factory:                                 /* 工場 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.ShallowSea);
                                units.doMove(clist[0]);
                            }
                            break;

                        case Unit.Refinery:                                 /* 製油所 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.ShallowSea);
                                units.doMove(clist[0]);
                            }
                            break;

                        case Unit.Camp:                                 /* 野営地 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.ShallowSea);
                                units.doMove(clist[0]);
                            }
                            break;

                        case Unit.Base:                                 /* 基地 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.ShallowSea);
                                units.doMove(clist[0]);
                            }
                            break;

                        case Unit.Fortress:                                 /* 要塞 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.ShallowSea);
                                units.doMove(clist[0]);
                            }
                            break;

                        default:                                 /* その他 */
                            break;
                        }
                        /* ユニットが未搭載 */
                    }
                    else
                    {
                    }
                }
                break;

            case Unit.TransportShip:             /* 輸送艦 */
                if (units.works == WorkType.None)
                {
                    /* ユニットが搭載されている */
                    if (units.loadUnits.Count > 0)
                    {
                        if (units.loadUnits[0].works == WorkType.Loading)
                        {
                            //搭載ユニットの最終移動先へ
                            units.doMove(MapCtl.offset_vec2stg(units.loadUnits[0].LastDest));
                            units.loadUnits[0].works = WorkType.None;
                        }
                        else
                        {
                            if (map.tileRing(units.pos, 1).Exists(tll => (((map.tileMap[tll.x, tll.y].getGroup() == TileGroup.Ground)))))
                            {
                                units.doUnload(units.loadUnits[0]);
                                cpuUnitList[i].hopeRideShip = null;
                            }
                            else
                            {
                                units.doMove(MapCtl.offset_vec2stg(units.loadUnits[0].LastDest));
                            }
                        }
                        /* ユニットが非搭載 */
                    }
                    else
                    {
                        //陸地に隣接している場合
                        if (map.tileRing(units.pos, 1).Exists(tll => (((map.tileMap[tll.x, tll.y].getGroup() == TileGroup.Ground)))))
                        {
                            /* 待機 */
                        }
                        else
                        {
                            //ランダムな首都を目指す(デバッグ用)
                            //units.doMove(UnitList.Where(u => u.units == Unit.Capital ).OrderBy(j => System.Guid.NewGuid()).ToList()[0].pos);
                            //ランダムな支配下領域を目指す
                            //units.doMove(map.getSpcTilePos(new Vector2Int(0,0), new Vector2Int (StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.None).FirstOrDefault(t=>cpuTileMap[t.x, t.y].domain>0));
                        }
                    }
                }
                break;

            case Unit.Surveillance:             /* 偵察機 */
                if (units.works == WorkType.None)
                {
                    units.doMove(new Vector2Int(3, 3));
                    units.addMove(new Vector2Int(15, 15));
                }

                /* 帰還チェック */
                chkReturn(units);

                break;

            case Unit.LandFighter:             /* 陸上戦闘機 */
                if (units.works == WorkType.None)
                {
                    units.doMove(new Vector2Int(3, 3));
                    units.addMove(new Vector2Int(15, 15));
                }

                /* 帰還チェック */
                chkReturn(units);

                break;

            case Unit.Fighter:             /* 戦闘機 */
                if (units.works == WorkType.None)
                {
                    units.doMove(new Vector2Int(3, 3));
                    units.addMove(new Vector2Int(15, 15));
                }

                /* 帰還チェック */
                chkReturn(units);

                break;

            case Unit.Capital:             /* 首都 */
                if (units.works == WorkType.None)
                {
                    //if (UnitList.Where( u => u.units == Unit.NavalPort ).ToList().Count < 1) {
                    //	//units.bldNavalPort();
                    //	units.doBuildUnit(Unit.NavalPort);
                    //} else if (UnitList.Where( u => u.units == Unit.OilWell ).ToList().Count < 5){
                    //	//units.bldOilWell();
                    //	units.doBuildUnit(Unit.OilWell);
                    //} else
                    if (UnitList.Where(u => u.units == Unit.Airfield).ToList().Count < 1)
                    {
                        units.doBuildUnit(Unit.Airfield);
                    }
                }
                break;

            case Unit.Factory:             /* 工場 */
                break;

            case Unit.NavalPort:             /* 軍港 */

                //Debug.Log("NavalPort!! "+ units.works);
                if (units.works == WorkType.None)
                {
                    if (UnitList.Where(u => u.units == Unit.TransportShip).ToList().Count < 3)
                    {
                        units.doBuildUnit(Unit.TransportShip);
                    }
                    else if (UnitList.Where(u => u.units == Unit.LargeTanker).ToList().Count < 5)
                    {
                        units.doBuildUnit(Unit.LargeTanker);
                    }
                }
                break;

            case Unit.Airfield:             /* 飛行場 */
                if (units.works == WorkType.None)
                {
                    if (UnitList.Where(u => u.units == Unit.Surveillance).ToList().Count < 2)                         /* 偵察機 */
                    {
                        units.doBuildUnit(Unit.Surveillance);
                    }
                    else if (UnitList.Where(u => u.units == Unit.LandFighter).ToList().Count < 5)                          /* 陸上戦闘機 */
                    {
                        units.doBuildUnit(Unit.LandFighter);
                    }
                }
                break;

            case Unit.Camp:             /* 工場 */
                break;

            case Unit.Base:             /* 軍港 */
                break;

            default:             /* 資源・その他 */
                //units.bldOilWell();
                break;
            }

            //
        }
    }
コード例 #17
0
 private void Awake()
 {
     self = this;
 }
コード例 #18
0
    //タップ結果コールバック
    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));
        }
    }
コード例 #19
0
 // Start is called before the first frame update
 void Awake()
 {
     TileObj.initTileTlt();
     ast      = gameObject.GetComponent <astar>();
     instance = this;
 }
コード例 #20
0
    //ユニット作成(リスト追加は外部で実施すること)
    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);
    }
コード例 #21
0
    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));
            }
        }
    }