| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- /* 动物挑战关卡游戏模式-通用父类 */
- public abstract class ChallengeGameMode : GameMode
- {
- //动物类型ID {0:野兔,1:野鸡,2:野狼}
- public int animalTypeID = 0;
- //该关卡的动物预制体
- protected GameObject animalPrefab;
- //猎人的变换组件
- protected Transform hunterT;
- //动物地基的变换组件
- protected Transform animalsBaseT;
- //场景中活着的动物
- protected HashSet<TargetAnimal> animalSet = new HashSet<TargetAnimal>();
- //场景中最多同时存在多少只活着的动物
- protected int maxAnimalCountAtTheSameTime = 2;
- //剩余的动物数量(包含场中活着的和后续未出场的)
- public int animalCount = 0;
- public int animalCountMax = 0;
- //剩余的可用箭矢数量
- public int arrowCount = 0;
- public int arrowCountMax = 0;
- //倒计时
- public float time = 60;
- //当前关卡等级
- public int currentlevel;
- //上一关点击进入下一关,会把信息记录到这
- public static string enterNextLevel;
- public string nextLevel;
- public ChallengeGameMode(GameMgr gameMgr) : base(gameMgr) {
- //变量初始化
- animalsBaseT = GameObject.Find("Animals").transform;
- hunterT = this.gameMgr.GetComponentInChildren<ArmBow>().transform;
-
- //监听箭的射出,统计剩余的箭数
- GameEventCenter.ins.onBowArrowShootOut += delegate(ArmBow armBow, Arrow arrow) {
- if (banOnBowArrowShootOut) return;
- if (arrowCount > 0) {
- arrowCount--;
- }
- };
- if (enterNextLevel != null) {
- nextLevel = enterNextLevel;
- enterNextLevel = null;
- }
- }
- public override bool DoNextShoot() {
- if (GameMgr.ins.gameOver) return false;
- if (animalCount == 0 || arrowCount == 0) {
- AnnounceGameOver();
- return false;
- }
- return true;
- }
- public override object[] Settle() {
- return new object[]{animalCount == 0 ? "胜利" : "失败"};
- }
- public override void Update() {
- #if UNITY_EDITOR
- if (Input.GetKey(KeyCode.W) && !gameMgr.gameOver) { //win
- Debug.LogWarning("debug-win");
- gameMgr.gameOver = true;
- animalCount = 0;
- foreach (var item in animalSet)
- {
- GameObject.Destroy(item.gameObject);
- }
- AnnounceGameOver();
- }
- if (Input.GetKey(KeyCode.F) && !gameMgr.gameOver) { //fail
- gameMgr.gameOver = true;
- Debug.LogWarning("debug-fail");
- AnnounceGameOver();
- }
- #endif
- 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;
- AnnounceGameOver();
- }
- }
- //添加关卡选择界面
- protected void AddSelectLevelView() {
- this.gameMgr.transform.Find("HuntGameSelectLevelView").gameObject.SetActive(true);
- }
- //添加通用游戏界面
- public void AddHuntGameView() {
- this.gameMgr.transform.Find("HunterGameView").gameObject.SetActive(true);
- }
- //宣布游戏结束
- protected void AnnounceGameOver() {
- gameMgr.StopGame();
- //添加结算界面
- this.gameMgr.transform.Find("HunterGameSettleView").gameObject.SetActive(true);
- }
- public abstract void SetLevel(int level);
- //当前挑战的关卡是否为狼关卡
- public static bool IsChallengeWolf() {
- return GameMgr.gameType == 5 || GameMgr.gameType == 8 || GameMgr.gameType == 12;
- }
- #region //网络联机新增参数
- public bool banOnBowArrowShootOut = false;
- #endregion
- }
|