using System.Collections; using System.Collections.Generic; using UnityEngine; /**单人限时模式 */ public class TimeLimitGameMode : GameMode { public static int[] distanceCanSelected = {10, 20, 30, 50, 70}; public static int distance = 10; public float score = 0; int oneStarScore = 10; float time = 60; TargetBody targetBody; public TimeLimitGameMode(GameMgr gameMgr) : base(gameMgr) { //记录可射击的靶子 targetBody = GameObject.Find("GameArea/TargetObject/TargetBody").GetComponent(); GameObject.FindObjectOfType().validTargets.Add(targetBody); //添加游戏界面 GameObject view = Resources.Load("Prefabs/Views/TimeLimitGameView"); GameObject.Instantiate(view); BanBowReady(); } public override void Start() { UnbanBowReady(); GameObject.Instantiate(Resources.Load("Prefabs/Views/TimeLimitGameDistanceSelectView")); } public void ConfirmSelectedTargetDistance() { targetBody.SetDistance(distance); if (TimeLimitGameView.ins) TimeLimitGameView.ins.RenderHighestScoreByDistance(distance); TargetView.ins.Show(true); } public override void HitTarget(float score) { this.score += score; HitTargetNumber.Create(score); } 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 (gameMgr.gameOver || pauseTimeCounting) return; if (this.time > 0) { if (GlobalData.pkMatchType == PKMatchType.None && UserSettings.ins.trainMode) { //单人且为训练模式,就不要倒计时了 } else { this.time -= Time.deltaTime; } } else { this.time = 0; gameMgr.StopGame(); //添加结算界面 GameObject view = Resources.Load("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; } }