Exemplo n.º 1
0
    //ユニットオブジェクトのテンプレート作成
    static UnitObj addObjTlt(String _image, uType _type, Unit _units, int _cost, int _hpMax, int _fuelMax, int _fuelEfc, float _speedMax, float _yawMax)
    {
        UnitObj newObj = Instantiate(instance);

        newObj.unitImage        = newObj.transform.GetComponent <SpriteRenderer>(); //newObj.transform.Find("Texture").GetComponent<SpriteRenderer>()
        newObj.unitImage.sprite = Resources.Load <Sprite>("UnitImg/" + _image);
        newObj.units            = _units;
        newObj.type             = _type;
        newObj.hpMax            = _hpMax;
        newObj.fuelMax          = _fuelMax;
        newObj.fuelEfc          = _fuelEfc;
        newObj.speedMax         = _speedMax;
        newObj.yawMax           = _yawMax;
        newObj.yawrate          = _yawMax;
        newObj.gameObject.SetActive(false); //非表示
        newObj.gameObject.name = "Tlt_" + _units.ToString();

        //switch (newObj.type){
        //    case uType.Infantry:  /* 歩兵   */
        //		newObj.gameObject.layer = LayerMask.NameToLayer("Infantry");
        //		break;
        //    case uType.Vehicle:   /* 車両   */
        //		newObj.gameObject.layer = LayerMask.NameToLayer("Vehicle");
        //		break;
        //    case uType.Aircraft:  /* 航空機 */
        //		newObj.gameObject.layer = LayerMask.NameToLayer("Aircraft");
        //		break;
        //    case uType.Warship:   /* 戦艦   */
        //		newObj.gameObject.layer = LayerMask.NameToLayer("Warship");
        //		break;
        //    case uType.Submarine: /* 潜水艦 */
        //		newObj.gameObject.layer = LayerMask.NameToLayer("Submarine");
        //		break;
        //    case uType.Building:
        //		newObj.gameObject.layer = LayerMask.NameToLayer("Building");
        //		break;
        //	default:              /* その他 */
        //		break;
        //
        //}
        newObj.gameObject.layer = LayerMask.NameToLayer(newObj.type.ToString());

        //建物の場合は、位置と向きを固定
        if (_type == uType.Building)
        {
            var rb = newObj.GetComponent <Rigidbody2D>();
            rb.constraints = RigidbodyConstraints2D.FreezeAll;
            newObj.GetComponent <CircleCollider2D>().isTrigger = true;    //コライダーを無効化
        }

        return(newObj);
    }
Exemplo n.º 2
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);
    }
Exemplo n.º 3
0
    private void _endBattle()
    {
        Debug.Log("ENDING BATTLE");
        for (int i = TEAM_GOOD_GUYS; i < this.CombatantsByTeam.Length; i++)
        {
            foreach (GameObject UnitObj in this.CombatantsByTeam[i])
            {
                Unit SurvivingUnit = UnitObj.GetComponent <Unit>();
                SurvivingUnit.setBattle(null);
            }
        }

        Destroy(this);
        Destroy(this.gameObject);
    }
Exemplo n.º 4
0
    private void _doRoundForTeam(int teamNumber)
    {
        int targetTeam = TEAM_MONSTERS;

        if (teamNumber == TEAM_MONSTERS)
        {
            targetTeam = TEAM_GOOD_GUYS;
        }

        //Now go through the units in the team
        ArrayList TargetTeam = this.CombatantsByTeam[targetTeam];

        foreach (GameObject UnitObj in this.CombatantsByTeam[teamNumber])
        {
            Unit AttackingUnit = UnitObj.GetComponent <Unit>();

            //Attack a rando on the other team
            //Debug.Log ("Target team size: " + TargetTeam.Count);
            int targetIndex = Random.Range(0, TargetTeam.Count - 1);

            //Debug.Log("ATTACKING");
            GameObject TargetUnitObj = TargetTeam[targetIndex] as GameObject;

            AttackingUnit.attack(TargetUnitObj);

            Unit TargetUnit = TargetUnitObj.GetComponent <Unit>();
            //Debug.Log(TargetUnit.health);
            if (TargetUnit.health <= 0.0f)
            {
                TargetTeam.RemoveAt(targetIndex);
                TargetUnit.die();

                if (TargetTeam.Count <= 0)                   //The other team is dead oh neos!
                {
                    this._endBattle();
                    return;
                }
            }
        }        //end foreach
    }