//UnitPanelクリック時に詳細表示する public void OnClickPanel() { //ユニット確認の場合(システムメニューなど) if (unitcheckflag) { UnitCheck.unitNowSelected = unit; UnitCheck.is_unitchange = true; } else //戦闘パートの場合 { Operation.setSE(seOk); BattleVal.selectedUnit = unit; CharaStatusPrinter.Show_Enemy_Range(1); if (sortiestate == SortieState.SORTIE || sortiestate == SortieState.FORCE) { //カメラの移動 CameraAngle.CameraPoint(BattleVal.selectedUnit.gobj.transform.position); } } }
//ユニット設置可能なマスにタイルを描く void DrawTile() { unitsetposlist.Clear(); for (int i = 0; i < Mapclass.mapxnum; i++) { for (int j = 0; j < Mapclass.mapynum; j++) { if (BattleVal.mapdata[(int)MapdataList.MAPUNITSET][j][i] == 1) { unitsetlist.Add(Instantiate(UnitSetTile)); Mapclass.DrawCharacter(unitsetlist[unitsetlist.Count - 1], i, j); //1つ目の座標に視点移動 if (unitsetposlist.Count == 0) { Vector3 temp = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref temp, i, j); CameraAngle.CameraPoint(temp); } unitsetposlist.Add(new int[] { i, j }); } } } }
//Update private void Update() { //戦闘中 if (BattleVal.status == STATUS.USESKILL) { int damage = 0; switch (bstate) { case BATTLE_STATUS.SETVECT: //キャラの向き調整;攻撃元が発動場所を向く Vector3 r0 = new Vector3(); //攻撃元 Vector3 rSkill = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref r0, BattleVal.selectX, BattleVal.selectY); Mapclass.TranslateMapCoordToPosition(ref rSkill, skillpos[0], skillpos[1]); rSkill.y = r0.y; BattleVal.selectedUnit.gobj.transform.LookAt(rSkill); /* * //攻撃対象 * foreach (int[] attackedpos in attackedposlist) * { * Vector3 r1 = new Vector3(); //攻撃先 * Mapclass.TranslateMapCoordToPosition(ref r1, attackedpos[0], attackedpos[1]); * Unitdata temp = BattleVal.id2index[string.Format("{0},{1}", attackedpos[0], attackedpos[1])]; * damage = Calc_Damage(BattleVal.selectedUnit, temp); * * temp.hp -= damage; //ダメージ処理 * * string damagetext = string.Format("{0}", (int)Mathf.Abs(damage)); * int count = 1; * //ダメージテキストの中心座標 * Vector3 damage_center = Camera.main.WorldToScreenPoint(r1); * * //テキストの登録 * List<Text> damagenumtmp = new List<Text>(); * foreach (char a in damagetext) * { * int num = (int)char.GetNumericValue(a); //数を取得 * * damagenumtmp.Add(Instantiate(damagetextprefab, r1, Quaternion.identity)); * damagenumtmp[count - 1].text = a.ToString(); * //サイズ取得 * damagenumtmp[count - 1].rectTransform.sizeDelta = * new Vector2(damagenumtmp[count - 1].preferredWidth, damagenumtmp[count - 1].preferredHeight); * damagenumtmp[count - 1].rectTransform.sizeDelta = * new Vector2(damagenumtmp[count - 1].preferredWidth, damagenumtmp[count - 1].preferredHeight); * damagenumtmp[count - 1].transform.SetParent(canvas.transform, false); * damagenumtmp[count - 1].transform.localPosition = damage_center - new Vector3(canvas.GetComponent<RectTransform>().sizeDelta.x / 2, canvas.GetComponent<RectTransform>().sizeDelta.y / 2, 0); * * //1桁当たりの文字ブロック * Vector3 numsize = damagenumtmp[count - 1].GetComponent<RectTransform>().sizeDelta * damagenumtmp[count - 1].GetComponent<RectTransform>().localScale; * numsize.y = 0; * numsize.z = 0; * * damagenumtmp[count - 1].transform.localPosition += (count - 1) * numsize; * damagenumtmp[count - 1].transform.localPosition += new Vector3(0, 30, 0); * damagenumtmp[count - 1].color = new Vector4(1, 0, 0, 1); * if (damage < 0) damagenumtmp[count - 1].color = new Vector4(0.7f,1,0.7f,1); * damagenumtmp[count - 1].gameObject.SetActive(false); * count++; * * } * damagenum.Add(damagenumtmp); * * //アニメーション設定 * attackedAnimator.Add(temp.gobj.GetComponent<Animator>()); * if(damage > 0) * attackedanimstate.Add(hitAnimName); //共通モーションだと思うが、一部キャラで回復・ダメージが混ざる将来性も加味する * else * attackedanimstate.Add(healAnimName); //暫定 Healモーションも作る * attackedCharaAnimation.Add(temp.gobj.GetComponent<CharaAnimation>()); * } */ nowtime = -1; //initialize //スキルの消費 selectedskill.Consume(1); //行動スタックのクリア(1手戻し不可能に) BattleVal.actions.Clear(); //カットイン演出の場合 if (selectedskill.is_cutscene) { gobjCutin = Instantiate(selectedskill.prefab_cutin); bstate = BATTLE_STATUS.CUTIN; } else { //通常スキルの場合 //スキル使用モーション再生 BattleVal.selectedUnit.gobj.GetComponent <Animator>().Play(selectedskill.animname); //state update bstate = BATTLE_STATUS.EFFECT; skilltext.text = selectedskill.skillname; skillnamePanel.SetActive(true); } break; case BATTLE_STATUS.CUTIN: if (gobjCutin.GetComponent <CutinChecker>().cutinFinish) { Destroy(gobjCutin); //スキル使用モーション再生 BattleVal.selectedUnit.gobj.GetComponent <Animator>().Play(selectedskill.animname); //state update bstate = BATTLE_STATUS.EFFECT; skilltext.text = selectedskill.skillname; skillnamePanel.SetActive(true); } break; case BATTLE_STATUS.EFFECT: //スキル使用モーションが終了し、音声はなり終わったか? /* * if (BattleVal.selectedUnit.gobj.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime >= 1 * && !BattleVal.selectedUnit.gobj.GetComponent<CharaAnimation>().voiceSource.isPlaying * && !BattleVal.selectedUnit.gobj.GetComponent<CharaAnimation>().seSource.isPlaying) */ if (!BattleVal.selectedUnit.gobj.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).shortNameHash.Equals(Animator.StringToHash(selectedskill.animname)) && !BattleVal.selectedUnit.gobj.GetComponent <CharaAnimation>().voiceSource.isPlaying && !BattleVal.selectedUnit.gobj.GetComponent <CharaAnimation>().seSource.isPlaying) { Vector3 effectcampoint = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref effectcampoint, skillpos[0], skillpos[1]); CameraAngle.CameraPoint(effectcampoint); //エフェクト再生へ Vector3 reffect = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref reffect, skillpos[0], skillpos[1]); hitEffect = Instantiate(selectedskill.skillefect, reffect, selectedskill.skillefect.transform.rotation); bstate = BATTLE_STATUS.BATTLE; } break; case BATTLE_STATUS.BATTLE: //バトルのアニメーション //エフェクトの再生が終了したか? if (hitEffect == null) { //被弾モーション再生 if (nowtime == -1) { //攻撃対象 foreach (int[] attackedpos in attackedposlist) { Vector3 r1 = new Vector3(); //攻撃先 Mapclass.TranslateMapCoordToPosition(ref r1, attackedpos[0], attackedpos[1]); Unitdata temp = BattleVal.id2index[string.Format("{0},{1}", attackedpos[0], attackedpos[1])]; damage = Calc_Damage(BattleVal.selectedUnit, temp); temp.hp -= damage; //ダメージ処理 string damagetext = string.Format("{0}", (int)Mathf.Abs(damage)); int count = 1; //ダメージテキストの中心座標 Vector3 damage_center = Camera.main.WorldToScreenPoint(r1); //テキストの登録 List <Text> damagenumtmp = new List <Text>(); foreach (char a in damagetext) { int num = (int)char.GetNumericValue(a); //数を取得 damagenumtmp.Add(Instantiate(damagetextprefab, r1, Quaternion.identity)); damagenumtmp[count - 1].text = a.ToString(); //サイズ取得 damagenumtmp[count - 1].rectTransform.sizeDelta = new Vector2(damagenumtmp[count - 1].preferredWidth, damagenumtmp[count - 1].preferredHeight); damagenumtmp[count - 1].rectTransform.sizeDelta = new Vector2(damagenumtmp[count - 1].preferredWidth, damagenumtmp[count - 1].preferredHeight); damagenumtmp[count - 1].transform.SetParent(canvas.transform, false); damagenumtmp[count - 1].transform.localPosition = damage_center - new Vector3(canvas.GetComponent <RectTransform>().sizeDelta.x / 2, canvas.GetComponent <RectTransform>().sizeDelta.y / 2, 0); //1桁当たりの文字ブロック Vector3 numsize = damagenumtmp[count - 1].GetComponent <RectTransform>().sizeDelta *damagenumtmp[count - 1].GetComponent <RectTransform>().localScale; numsize.y = 0; numsize.z = 0; damagenumtmp[count - 1].transform.localPosition += (count - 1) * numsize; damagenumtmp[count - 1].transform.localPosition += new Vector3(0, 30, 0); damagenumtmp[count - 1].color = new Vector4(1, 0, 0, 1); if (damage < 0) { damagenumtmp[count - 1].color = new Vector4(0.7f, 1, 0.7f, 1); } damagenumtmp[count - 1].gameObject.SetActive(false); count++; } damagenum.Add(damagenumtmp); //アニメーション設定 attackedAnimator.Add(temp.gobj.GetComponent <Animator>()); if (damage > 0) { attackedanimstate.Add(hitAnimName); //共通モーションだと思うが、一部キャラで回復・ダメージが混ざる将来性も加味する } else { attackedanimstate.Add(healAnimName); //暫定 Healモーションも作る } attackedCharaAnimation.Add(temp.gobj.GetComponent <CharaAnimation>()); } for (int i = 0; i < attackedAnimator.Count; i++) { //Count不一致するかも? attackedAnimator[i].Play(attackedanimstate[i]); if (attackedanimstate[i] == hitAnimName) { attackedCharaAnimation[i].seSource.clip = seDamage; } else { attackedCharaAnimation[i].seSource.clip = seHeal; } attackedCharaAnimation[i].seSource.Play(); } //テキスト表示 foreach (List <Text> damagenumtmp in damagenum) { foreach (Text a in damagenumtmp) { a.gameObject.SetActive(true); } //CameraAngle.CameraPoint(BattleVal.selectedUnit.gobj.transform.position); } nowtime = 0; } else if (nowtime >= battle_time - Time.deltaTime) { //戦闘後処理 bstate = BATTLE_STATUS.AFTERBATTLE; //ダメージ数値のテキストを消す処理 foreach (List <Text> damagenumtmp in damagenum) { foreach (Text a in damagenumtmp) { Destroy(a.gameObject); } } //戦闘用のダメージ表示などの判定が終了した後に、カメラの位置の移動 CameraAngle.CameraPoint(BattleVal.selectedUnit.gobj.transform.position); //アニメーション関連の初期化 attackedAnimator.Clear(); attackedanimstate.Clear(); attackedCharaAnimation.Clear(); damagenum.Clear(); skillnamePanel.SetActive(false); //攻撃可能フラグをオフに BattleVal.selectedUnit.atackable = false; } else { //ダメージ数値のテキストを消す処理 //damagetext.color -= new Color(0,0,0,Time.deltaTime); foreach (List <Text> damagenumtmp in damagenum) { foreach (Text a in damagenumtmp) { a.color -= new Color(0, 0, 0, Time.deltaTime); a.transform.position += new Vector3(0, 1, 0); } } nowtime += Time.deltaTime; } } break; //戦闘後処理 case BATTLE_STATUS.AFTERBATTLE: //獲得経験値 int getexp = 10; //基本値 //撃墜処理 foreach (int[] attackedpos in attackedposlist) { Unitdata temp = BattleVal.id2index[string.Format("{0},{1}", attackedpos[0], attackedpos[1])]; //撃墜処理 if (temp.hp <= 0) { Vector3 defeatpos = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref defeatpos, attackedpos[0], attackedpos[1]); StartCoroutine(UnitDefeat.DefeatHandle(temp, defeatEffect, defeatpos)); //撃墜ボーナス getexp += BattleVal.id2index[string.Format("{0},{1}", attackedpos[0], attackedpos[1])].status.needexp; //ユニットデータを消去 ////BattleVal.unitlistから消去 for (int i = 0; i < BattleVal.unitlist.Count; i++) { if (BattleVal.unitlist[i].x == temp.x && BattleVal.unitlist[i].y == temp.y) { BattleVal.unitlist.RemoveAt(i); break; } } ////BattleVal.id2indexから消去 BattleVal.id2index.Remove(string.Format("{0},{1}", temp.x, temp.y)); ////mapdataからユニット情報の削除 BattleVal.mapdata[(int)MapdataList.MAPUNIT][temp.y][temp.x] = 0; } if (temp.hp > temp.status.maxhp) { temp.hp = temp.status.maxhp; } } //必殺技の場合、獲得経験値が1.5倍ボーナス if (selectedskill.is_cutscene) { getexp = (int)((float)getexp * 1.5f); } //ユニットセレクトに戻る bstate = BATTLE_STATUS.SETVECT; if (BattleVal.selectedUnit.team == 0) { //経験値を獲得するキャラの場合 if (BattleVal.selectedUnit.status.needexp != 0 && BattleVal.selectedUnit.status.level < 99 && BattleVal.selectedUnit.status.level >= 1) { Operation.AddGetExp(BattleVal.selectedUnit, getexp); BattleVal.status = STATUS.GETEXP; } else { BattleVal.status = STATUS.PLAYER_UNIT_SELECT; } } else { BattleVal.status = STATUS.ENEMY_UNIT_SELECT; } break; } } else { } }
//Update private void Update() { //移動中の場合 if (BattleVal.status == STATUS.MOVING) { switch (mstate) { case MOVING_STATUS.SETVECT: //移動終了の判定 if (nowstep == movepath.Count - 1) { //行動スタックを積む(1手戻し用) if (BattleVal.status == STATUS.MOVING) { Action thisact = new Action(BattleVal.selectedUnit, BattleVal.selectedUnit.x, BattleVal.selectedUnit.y, movepath[nowstep][0], movepath[nowstep][1]); BattleVal.actions.Push(thisact); } //map上のキャラクターIDの更新 //座標情報のアップデート BattleVal.mapdata[(int)MapdataList.MAPUNIT][movepath[nowstep][1]][movepath[nowstep][0]] = BattleVal.mapdata[(int)MapdataList.MAPUNIT][movepath[0][1]][movepath[0][0]]; //移動した場合 if (nowstep != 0) { BattleVal.mapdata[(int)MapdataList.MAPUNIT][movepath[0][1]][movepath[0][0]] = 0; } //BattleVal.selectedUnit.gobj.GetComponent<QuerySDMecanimController>().ChangeAnimation(QuerySDMecanimController.QueryChanSDAnimationType.NORMAL_STAND); BattleVal.selectedUnit.gobj.GetComponent <Animator>().SetBool("Walk", false); BattleVal.selectedUnit.gobj.GetComponent <Animator>().SetBool("Jump", false); BattleVal.selectedUnit.gobj.GetComponent <Animator>().Play("Idle"); BattleVal.selectedUnit.gobj.GetComponent <Animator>().Update(0); BattleVal.selectedUnit.x = movepath[nowstep][0]; BattleVal.selectedUnit.y = movepath[nowstep][1]; //ディクショナリのアップデート BattleVal.id2index.Remove(string.Format("{0},{1}", BattleVal.selectX, BattleVal.selectY)); BattleVal.id2index.Add(string.Format("{0},{1}", movepath[nowstep][0], movepath[nowstep][1]), BattleVal.selectedUnit); //Battleval.statusのアップデート Debug.Log(BattleVal.turnplayer); if (BattleVal.turnplayer == 0) { BattleVal.status = STATUS.PLAYER_UNIT_SELECT; BattleVal.selectX = -1; BattleVal.selectY = -1; } else { BattleVal.status = STATUS.ENEMY_UNIT_SELECT; } //移動可能フラグをオフに BattleVal.selectedUnit.movable = false; break; } //速度ベクトル(実空間)の計算 Vector3 r0 = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref r0, movepath[nowstep][0], movepath[nowstep][1]); Vector3 r1 = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref r1, movepath[nowstep + 1][0], movepath[nowstep + 1][1]); velocity = (1.0f / steptime) * (r1 - r0); //1マスの移動に0.5sec nowtime = 0; stoptime = 0; if (Mathf.Abs(BattleVal.mapdata[(int)MapdataList.MAPHEIGHT][movepath[nowstep + 1][1]][movepath[nowstep + 1][0]] - BattleVal.mapdata[(int)MapdataList.MAPHEIGHT][movepath[nowstep][1]][movepath[nowstep][0]]) > 0) { //ジャンプモーション BattleVal.selectedUnit.gobj.GetComponent <Animator>().Play("Jump"); BattleVal.selectedUnit.gobj.GetComponent <Animator>().SetBool("Walk", false); stoptime = 0.3f; } else { BattleVal.selectedUnit.gobj.GetComponent <Animator>().SetBool("Walk", true); } /* * //もしもジャンプする場合 * if (BattleVal.mapdata[(int)MapdataList.MAPHEIGHT][movepath[nowstep + 1][1]][movepath[nowstep + 1][0]] - BattleVal.mapdata[(int)MapdataList.MAPHEIGHT][movepath[nowstep][1]][movepath[nowstep][0]] > 0) * { * //ジャンプモーション * BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Walk", false); * BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Jump",true); * //BattleVal.selectedUnit.gobj.GetComponent<QuerySDMecanimController>().ChangeAnimation(QuerySDMecanimController.QueryChanSDAnimationType.NORMAL_FLY_UP); * stoptime = 0.3f; * } * else if (BattleVal.mapdata[(int)MapdataList.MAPHEIGHT][movepath[nowstep + 1][1]][movepath[nowstep + 1][0]] - BattleVal.mapdata[(int)MapdataList.MAPHEIGHT][movepath[nowstep][1]][movepath[nowstep][0]] < 0) * { * //ジャンプモーション * BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Walk", false); * BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Jump", true); * * //BattleVal.selectedUnit.gobj.GetComponent<QuerySDMecanimController>().ChangeAnimation(QuerySDMecanimController.QueryChanSDAnimationType.NORMAL_FLY_DOWN); * stoptime = 0.3f; * } * else * { * //歩行モーション * //BattleVal.selectedUnit.gobj.GetComponent<QuerySDMecanimController>().ChangeAnimation(QuerySDMecanimController.QueryChanSDAnimationType.NORMAL_WALK); * BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Jump", false); * BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Walk", true); * * } */ //キャラの向きの調整 Mapclass.TranslateMapCoordToPosition(ref r1, movepath[nowstep + 1][0], movepath[nowstep + 1][1]); BattleVal.selectedUnit.gobj.transform.LookAt(r1); //mstateのアップデート mstate = MOVING_STATUS.MOVING; break; case MOVING_STATUS.MOVING: //ステップ終了の判定 if (nowtime >= steptime - Time.deltaTime) { if (now_stop_time == 0) { //BattleVal.selectedUnit.gobj.GetComponent<Animator>().SetBool("Jump", false); } //終点に表示 if (now_stop_time > stoptime) { r1 = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref r1, movepath[nowstep + 1][0], movepath[nowstep + 1][1]); BattleVal.selectedUnit.gobj.transform.position = r1; BattleVal.selectedUnit.gobj.transform.LookAt(new Vector3(r1.x, BattleVal.selectedUnit.gobj.transform.position.y, r1.z)); CameraAngle.CameraPoint(BattleVal.selectedUnit.gobj.transform.position); nowstep++; now_stop_time = 0; mstate = MOVING_STATUS.SETVECT; break; } now_stop_time += Time.deltaTime; nowtime += Time.deltaTime; /* * //終点に表示 * * r1 = new Vector3(); * Mapclass.TranslateMapCoordToPosition(ref r1, movepath[nowstep + 1][0], movepath[nowstep + 1][1]); * BattleVal.selectedUnit.gobj.transform.position = r1; * BattleVal.selectedUnit.gobj.transform.LookAt(new Vector3(r1.x, BattleVal.selectedUnit.gobj.transform.position.y, r1.z)); * CameraAngle.CameraPoint(BattleVal.selectedUnit.gobj.transform.position); * nowstep++; * now_stop_time = 0; * mstate = MOVING_STATUS.SETVECT; * break; */ } else { r1 = new Vector3(); Mapclass.TranslateMapCoordToPosition(ref r1, movepath[nowstep + 1][0], movepath[nowstep + 1][1]); BattleVal.selectedUnit.gobj.transform.LookAt(new Vector3(r1.x, BattleVal.selectedUnit.gobj.transform.position.y, r1.z)); //nowtime 加算処理 nowtime += Time.deltaTime; //移動 BattleVal.selectedUnit.gobj.transform.position += new Vector3(velocity.x, 0, velocity.z) * Time.deltaTime; //カメラの移動 CameraAngle.CameraPoint(BattleVal.selectedUnit.gobj.transform.position); if (nowtime < steptime / 2 && velocity.y > 0) { BattleVal.selectedUnit.gobj.transform.position += new Vector3(0, (float)velocity.y * steptime * 60 * nowtime, 0) * Time.deltaTime; } else if (nowtime >= steptime / 2 && velocity.y > 0) { float tempvelocity = (r1.y - BattleVal.selectedUnit.gobj.transform.position.y) / (steptime - nowtime); BattleVal.selectedUnit.gobj.transform.position += new Vector3(0, tempvelocity, 0) * Time.deltaTime; } else if (velocity.y < 0) { BattleVal.selectedUnit.gobj.transform.position += new Vector3(0, velocity.y, 0) * Time.deltaTime; } /* * //モーションチェンジ * * if (nowtime < steptime / 2 && velocity.y > 0) * { * BattleVal.selectedUnit.gobj.transform.position += new Vector3(0, (float)velocity.y * steptime * 60 * nowtime, 0) * Time.deltaTime; * } * else if (nowtime >= steptime / 2 && velocity.y > 0) * { * BattleVal.selectedUnit.gobj.transform.position -= new Vector3(0, (float)(velocity.y * steptime * 16 + Physics.gravity.y) * (nowtime - steptime / 2)) * Time.deltaTime; * } * else if (velocity.y < 0) * { * BattleVal.selectedUnit.gobj.transform.position -= new Vector3(0, (float)(velocity.y * steptime * 8 - Physics.gravity.y) * nowtime - steptime) * Time.deltaTime; * } */ } break; } } }