| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- /**单人限时模式 */
- public class TimeLimitGameMode : GameMode {
- public static int insCount; //被实例化的次数
- public static int[] distanceCanSelected = {10, 20, 30, 50, 70};
- public static int distance = 10;
- public static int insCountWillTryAgain; //哪一次的实例化会以再次挑战进行----用于再次挑战按钮
- public float score = 0;
- int oneStarScore = 10;
- float time = 60;
- TargetBody targetBody;
- public Action onHitTargetEvent;
- public TimeLimitGameMode(GameMgr gameMgr) : base(gameMgr) {
- insCount++;
- //记录可射击的靶子
- targetBody = GameObject.Find("GameArea/TargetObject/TargetBody").GetComponent<TargetBody>();
- GameObject.FindObjectOfType<ArmBow>().validTargets.Add(targetBody);
- //添加游戏界面
- GameObject view = Resources.Load<GameObject>("Prefabs/Views/TimeLimitGameView");
- GameObject.Instantiate(view);
- BanBowReady();
- }
- public override void Start()
- {
- UnbanBowReady();
- if (insCount == insCountWillTryAgain) {
- ConfirmSelectedTargetDistance();
- } else {
- if (GameMgr.bShowDistance) {
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/TimeLimitGameDistanceSelectView"));
- }
- }
- }
- public void ConfirmSelectedTargetDistance()
- {
- targetBody.SetDistance(distance);
- TargetView.ins.Show(true);
- gameMgr.StartCoroutine(RenderHighestScoreByDistance());
- }
- private IEnumerator RenderHighestScoreByDistance() {
- yield return null;
- yield return null;
- if (TimeLimitGameView.ins) TimeLimitGameView.ins.RenderHighestScoreByDistance(distance);
- }
- public override void HitTarget(float score) {
- this.score += score;
- HitTargetNumber.Create(score);
- onHitTargetEvent?.Invoke();
- if(score != 0)
- gameMgr.StartCoroutine(NavDeviceView());
- }
- //跳回homeView 后,跳转到deviceview
- IEnumerator NavDeviceView() {
- yield return new WaitForSeconds(1.0f);
- if (GameMgr.bNavBack)
- {
- InfraredGuider _infraredGuider = UnityEngine.Object.FindObjectOfType<InfraredGuider>();
- if (_infraredGuider != null)
- {
- //红外光引导射击,如果是显示这个状态
- if (_infraredGuider.mTipStep == TipStep.Finish)
- {
- GameMgr.bNavBack = false;
- //直接回到主页
- UnityEngine.SceneManagement.SceneManager.LoadScene("Home", UnityEngine.SceneManagement.LoadSceneMode.Single);
- }
- }
- else {
- GameMgr.bNavBack = false;
- //普通引导时候射击
- HomeView.bOpenOtherView = true;
- HomeView.openName = "DeviceView";
- UnityEngine.SceneManagement.SceneManager.LoadScene("Home", UnityEngine.SceneManagement.LoadSceneMode.Single);
- }
-
- }
- }
- public override bool DoNextShoot() {
- return !GameMgr.ins.gameOver;
- }
- public override object[] Settle() {
- int starCount = Mathf.FloorToInt(this.score / this.oneStarScore);
- float highestScore = 0;
- string distanceStr = distance.ToString();
- if (LoginMgr.myUserInfo.timeLimitGameScores.ContainsKey(distanceStr)) {
- highestScore = LoginMgr.myUserInfo.timeLimitGameScores[distanceStr];
- }
- if (this.score > highestScore) {
- LoginMgr.myUserInfo.timeLimitGameScores.Remove(distanceStr);
- LoginMgr.myUserInfo.timeLimitGameScores.Add(distanceStr, this.score);
- LoginMgr.myUserInfo.Save();
- }
- return new object[]{starCount, this.score};
- }
- public override void Update() {
- #if UNITY_EDITOR
- if (Input.GetKey(KeyCode.W) && this.time > 0) { //win
- Debug.LogWarning("debug-win");
- this.score = 100;
- this.time = 0;
- }
- if (Input.GetKey(KeyCode.F) && this.time > 0) { //fail
- Debug.LogWarning("debug-fail");
- this.score = 10;
- this.time = 0;
- }
- #endif
- if (gameMgr.gameOver || pauseTimeCounting) return;
- //不进入计时器
- if (GameMgr.turnOffTimer) return;
- if (this.time > 0) {
- if (GlobalData.pkMatchType == PKMatchType.None && UserSettings.ins.trainMode) {
- //单人且为训练模式,就不要倒计时了
- } else {
- this.time -= Time.deltaTime;
- }
- if (Billboard.ins && Billboard.ins.bulletManager.NumberOfShotsFired()) {
- //超过射击次数,设置运行时间0,等待结束游戏
- this.time = 0;
- }
- } else {
- this.time = 0;
- gameMgr.StopGame();
- //添加结算界面
- GameObject view = Resources.Load<GameObject>("Prefabs/Views/TimeLimitGameSettleView");
- GameObject.Instantiate(view);
- }
- }
- public string GetTimeStr()
- {
- int seconds = (int) Mathf.Ceil(this.time);
- string str = "";
- int m = seconds / 60;
- if (m < 10) {
- str += 0;
- }
- str += m;
- str += " : ";
- int s = seconds % 60;
- if (s < 10)
- {
- str += 0;
- }
- str += s;
- return str;
- }
- }
|