ChallengeGameMode.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /* 动物挑战关卡游戏模式-通用父类 */
  5. public abstract class ChallengeGameMode : GameMode
  6. {
  7. //动物类型ID {0:野兔,1:野鸡,2:野狼}
  8. public int animalTypeID = 0;
  9. //该关卡的动物预制体
  10. protected GameObject animalPrefab;
  11. //猎人的变换组件
  12. protected Transform hunterT;
  13. //动物地基的变换组件
  14. protected Transform animalsBaseT;
  15. //场景中活着的动物
  16. protected HashSet<TargetAnimal> animalSet = new HashSet<TargetAnimal>();
  17. //场景中最多同时存在多少只活着的动物
  18. protected int maxAnimalCountAtTheSameTime = 2;
  19. //剩余的动物数量(包含场中活着的和后续未出场的)
  20. public int animalCount = 0;
  21. public int animalCountMax = 0;
  22. //剩余的可用箭矢数量
  23. public int arrowCount = 0;
  24. public int arrowCountMax = 0;
  25. //倒计时
  26. public float time = 60;
  27. //当前关卡等级
  28. public int currentlevel;
  29. //上一关点击进入下一关,会把信息记录到这
  30. public static string enterNextLevel;
  31. public string nextLevel;
  32. public ChallengeGameMode(GameMgr gameMgr) : base(gameMgr) {
  33. //变量初始化
  34. animalsBaseT = GameObject.Find("Animals").transform;
  35. hunterT = this.gameMgr.GetComponentInChildren<ArmBow>().transform;
  36. //监听箭的射出,统计剩余的箭数
  37. GameEventCenter.ins.onBowArrowShootOut += delegate(ArmBow armBow, Arrow arrow) {
  38. if (banOnBowArrowShootOut) return;
  39. if (arrowCount > 0) {
  40. arrowCount--;
  41. }
  42. };
  43. if (enterNextLevel != null) {
  44. nextLevel = enterNextLevel;
  45. enterNextLevel = null;
  46. }
  47. }
  48. public override bool DoNextShoot() {
  49. if (GameMgr.ins.gameOver) return false;
  50. if (animalCount == 0 || arrowCount == 0) {
  51. AnnounceGameOver();
  52. return false;
  53. }
  54. return true;
  55. }
  56. public override object[] Settle() {
  57. return new object[]{animalCount == 0 ? "胜利" : "失败"};
  58. }
  59. public override void Update() {
  60. if (gameMgr.gameOver || pauseTimeCounting) return;
  61. if (this.time > 0) {
  62. if (GlobalData.pkMatchType == PKMatchType.None && UserSettings.ins.trainMode) {
  63. //单人且为训练模式,就不要倒计时了
  64. } else {
  65. this.time -= Time.deltaTime;
  66. }
  67. } else {
  68. this.time = 0;
  69. AnnounceGameOver();
  70. }
  71. }
  72. //添加关卡选择界面
  73. protected void AddSelectLevelView() {
  74. this.gameMgr.transform.Find("HuntGameSelectLevelView").gameObject.SetActive(true);
  75. }
  76. //添加通用游戏界面
  77. public void AddHuntGameView() {
  78. this.gameMgr.transform.Find("HunterGameView").gameObject.SetActive(true);
  79. }
  80. //宣布游戏结束
  81. protected void AnnounceGameOver() {
  82. gameMgr.StopGame();
  83. //添加结算界面
  84. this.gameMgr.transform.Find("HunterGameSettleView").gameObject.SetActive(true);
  85. }
  86. public abstract void SetLevel(int level);
  87. //当前挑战的关卡是否为狼关卡
  88. public static bool IsChallengeWolf() {
  89. return GameMgr.gameType == 5 || GameMgr.gameType == 8 || GameMgr.gameType == 12;
  90. }
  91. #region //网络联机新增参数
  92. public bool banOnBowArrowShootOut = false;
  93. #endregion
  94. }